mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-07-14 01:26:26 +07:00
CollectMigration: support toUnmodifiableMap
Fixes IDEA-187213 Stream API migration: support Java 10 toUnmodifiableList/Set/Map collections
This commit is contained in:
+13
@@ -20,4 +20,17 @@ class Test {
|
||||
// toUnmodifiableSet will not preserve order; not suggested here
|
||||
return Collections.unmodifiableSet(result);
|
||||
}
|
||||
|
||||
Map<String, Integer> map(List<String> input) {
|
||||
return input.stream().filter(s -> !s.isEmpty()).collect(Collectors.toUnmodifiableMap(s -> s, s -> s.length(), (a, b) -> b));
|
||||
}
|
||||
|
||||
Map<String, Integer> map1(List<String> input) {
|
||||
Map<String, Integer> result = input.stream().filter(s -> !s.isEmpty()).collect(Collectors.toMap(s -> s, String::length, (a, b) -> b, TreeMap::new));
|
||||
return Collections.unmodifiableMap(result);
|
||||
}
|
||||
|
||||
Map<String, Integer> map2(int[] input) {
|
||||
return Arrays.stream(input).filter(s -> s > 0).boxed().collect(Collectors.toUnmodifiableMap(s -> String.valueOf(s), s -> s, (a, b) -> b));
|
||||
}
|
||||
}
|
||||
+30
@@ -47,4 +47,34 @@ class Test {
|
||||
// toUnmodifiableSet will not preserve order; not suggested here
|
||||
return Collections.unmodifiableSet(result);
|
||||
}
|
||||
|
||||
Map<String, Integer> map(List<String> input) {
|
||||
Map<String, Integer> result = new HashMap<>(100);
|
||||
for (String s : input) {
|
||||
if (!s.isEmpty()) {
|
||||
result.put(s, s.length());
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableMap(result);
|
||||
}
|
||||
|
||||
Map<String, Integer> map1(List<String> input) {
|
||||
Map<String, Integer> result = new TreeMap<>();
|
||||
for (String s : input) {
|
||||
if (!s.isEmpty()) {
|
||||
result.put(s, s.length());
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableMap(result);
|
||||
}
|
||||
|
||||
Map<String, Integer> map2(int[] input) {
|
||||
Map<String, Integer> result = new HashMap<>();
|
||||
for (int s : input) {
|
||||
if (s > 0) {
|
||||
result.put(String.valueOf(s), s);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableMap(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user