mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-04 20:30:42 +07:00
Add "Replace 'compute' with 'computeIfPresent'" fix
Helps for IDEA-194058 False-positive warning of producing NullPointerException for Map.compute
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// "Replace 'compute' with 'computeIfPresent'" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
class Main {
|
||||
interface Item {
|
||||
Integer getInfo(int i);
|
||||
}
|
||||
|
||||
native List<String> getNamesList();
|
||||
|
||||
void test(List<Item> infoList) {
|
||||
Map<String, List<Integer>> data = new HashMap<>();
|
||||
List<String> names = getNamesList();
|
||||
for (String key : names) {
|
||||
data.put(key, new ArrayList<>());
|
||||
}
|
||||
for (Item info : infoList) {
|
||||
for (int i = 0; i < names.size(); i++) {
|
||||
final String k = names.get(i);
|
||||
final Integer newValue = info.getInfo(i);
|
||||
data.computeIfPresent(k, (key, array) -> {
|
||||
array.add(newValue);
|
||||
return array;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// "Replace 'compute' with 'computeIfPresent'" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
class Main {
|
||||
interface Item {
|
||||
Integer getInfo(int i);
|
||||
}
|
||||
|
||||
native List<String> getNamesList();
|
||||
|
||||
void test(List<Item> infoList) {
|
||||
Map<String, List<Integer>> data = new HashMap<>();
|
||||
List<String> names = getNamesList();
|
||||
for (String key : names) {
|
||||
data.put(key, new ArrayList<>());
|
||||
}
|
||||
for (Item info : infoList) {
|
||||
for (int i = 0; i < names.size(); i++) {
|
||||
final String k = names.get(i);
|
||||
final Integer newValue = info.getInfo(i);
|
||||
data.compute(k, (key, array) -> {
|
||||
array.a<caret>dd(newValue);
|
||||
return array;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user