Files
openide/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/replaceComputeWithComputeIfPresent/beforeCompute.java
Tagir Valeev 7e1064ea3c [java-intentions] More preview tests; minor fixes
GitOrigin-RevId: 22a46c15d8900d8a31514846755a013f6a67ad42
2022-07-29 17:55:13 +00:00

31 lines
778 B
Java

// "Replace 'compute' with 'computeIfPresent'" "true-preview"
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;
});
}
}
}
}