mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-25 14:25:04 +07:00
IDEA-161257 Follow-up: support scenarios like map.put(key, value = new ArrayList<>()); refactor
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
+15
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user