IDEA-161257 Follow-up: support scenarios like map.put(key, value = new ArrayList<>()); refactor

This commit is contained in:
Tagir Valeev
2016-10-12 14:25:24 +03:00
parent bab9245f27
commit 73eef6c8ac
4 changed files with 103 additions and 48 deletions
@@ -0,0 +1,11 @@
// "Replace with 'computeIfAbsent' method call" "true"
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Main {
public void testMap(Map<String, List<String>> map, String key, String value) {
List<String> list = map.computeIfAbsent(key, k -> new ArrayList<>());
list.add(value);
}
}
@@ -0,0 +1,14 @@
// "Replace with 'computeIfAbsent' method call" "true"
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Main {
public void testMap(Map<String, List<String>> map, String key, String value) {
List<String> list = map.get(key);
if(list == nul<caret>l) {
map.put(key, list = new ArrayList<>());
}
list.add(value);
}
}
@@ -0,0 +1,15 @@
// "Replace with 'computeIfAbsent' method call" "false"
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Main {
public void testMap(Map<String, List<String>> map, String key, String value) {
List<String> list2 = null;
List<String> list = map.get(key);
if(list == nul<caret>l) {
map.put(key, list2 = new ArrayList<>());
}
list.add(value);
}
}