mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-28 04:37:32 +07:00
StreamApiMigration: support Java10 toUnmodifiableList/Set (part of IDEA-187213)
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
// "Fix all 'Subsequent steps can be fused into Stream API chain' problems in file" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.*;
|
||||
|
||||
public class Test {
|
||||
List<String> testFuse(String[] list) {
|
||||
return Arrays.stream(list).filter(s -> !s.isEmpty()).collect(Collectors.toUnmodifiableList());
|
||||
}
|
||||
|
||||
Set<String> testFuse2(String[] list) {
|
||||
return Arrays.stream(list).filter(s -> !s.isEmpty()).collect(Collectors.toUnmodifiableSet());
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Fix all 'Subsequent steps can be fused into Stream API chain' problems in file" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.*;
|
||||
|
||||
public class Test {
|
||||
List<String> testFuse(String[] list) {
|
||||
List<String> result = Arrays.stream(list).filter(s -> !s.isEmpty()).co<caret>llect(Collectors.toCollection(LinkedList::new));
|
||||
return Collections.unmodifiableList(result);
|
||||
}
|
||||
|
||||
Set<String> testFuse2(String[] list) {
|
||||
return Collections.unmodifiableSet(Arrays.stream(list).filter(s -> !s.isEmpty()).collect(Collectors.toSet()));
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// "Fix all 'Loop can be collapsed with Stream API' problems in file" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
// Java 8 language level used: no toUnmodifiable suggestions
|
||||
class Test {
|
||||
List<String> test(String[] list) {
|
||||
List<String> result = Arrays.stream(list).filter(s -> !s.isEmpty()).collect(Collectors.toCollection(LinkedList::new));
|
||||
return Collections.unmodifiableList(result);
|
||||
}
|
||||
|
||||
Collection<String> test2(String[] list) {
|
||||
Set<String> result = Arrays.stream(list).filter(s -> !s.isEmpty()).collect(Collectors.toSet());
|
||||
return Collections.unmodifiableCollection(result);
|
||||
}
|
||||
|
||||
List<String> test3(String[] array) {
|
||||
List<String> list = Arrays.stream(array).filter(s -> !s.isEmpty()).distinct().collect(Collectors.toList());
|
||||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
|
||||
Set<String> test4(String[] array) {
|
||||
Set<String> result = Arrays.stream(array).filter(s -> !s.isEmpty()).collect(Collectors.toCollection(TreeSet::new));
|
||||
return Collections.unmodifiableSet(result);
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// "Fix all 'Loop can be collapsed with Stream API' problems in file" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class Test {
|
||||
List<String> test(String[] list) {
|
||||
return Arrays.stream(list).filter(s -> !s.isEmpty()).collect(Collectors.toUnmodifiableList());
|
||||
}
|
||||
|
||||
Collection<String> test2(String[] list) {
|
||||
return Arrays.stream(list).filter(s -> !s.isEmpty()).collect(Collectors.toUnmodifiableSet());
|
||||
}
|
||||
|
||||
List<String> test3(String[] array) {
|
||||
return Arrays.stream(array).filter(s -> !s.isEmpty()).distinct().collect(Collectors.toUnmodifiableList());
|
||||
}
|
||||
|
||||
Set<String> test4(String[] array) {
|
||||
Set<String> result = Arrays.stream(array).filter(s -> !s.isEmpty()).collect(Collectors.toCollection(TreeSet::new));
|
||||
// toUnmodifiableSet will not preserve order; not suggested here
|
||||
return Collections.unmodifiableSet(result);
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
// "Fix all 'Loop can be collapsed with Stream API' problems in file" "true"
|
||||
import java.util.*;
|
||||
|
||||
// Java 8 language level used: no toUnmodifiable suggestions
|
||||
class Test {
|
||||
List<String> test(String[] list) {
|
||||
List<String> result = new LinkedList<>();
|
||||
f<caret>or (int i = 0; i < list.length; i++) {
|
||||
String s = list[i];
|
||||
if (!s.isEmpty()) {
|
||||
result.add(s);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableList(result);
|
||||
}
|
||||
|
||||
Collection<String> test2(String[] list) {
|
||||
Set<String> result = new HashSet<>();
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
String s = list[i];
|
||||
if (!s.isEmpty()) {
|
||||
result.add(s);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableCollection(result);
|
||||
}
|
||||
|
||||
List<String> test3(String[] array) {
|
||||
Set<String> result = new HashSet<>();
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
String s = array[i];
|
||||
if (!s.isEmpty()) {
|
||||
result.add(s);
|
||||
}
|
||||
}
|
||||
List<String> list = new ArrayList<>(result);
|
||||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
|
||||
Set<String> test4(String[] array) {
|
||||
Set<String> result = new TreeSet<>();
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
String s = array[i];
|
||||
if (!s.isEmpty()) {
|
||||
result.add(s);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableSet(result);
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
// "Fix all 'Loop can be collapsed with Stream API' problems in file" "true"
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
List<String> test(String[] list) {
|
||||
List<String> result = new LinkedList<>();
|
||||
f<caret>or (int i = 0; i < list.length; i++) {
|
||||
String s = list[i];
|
||||
if (!s.isEmpty()) {
|
||||
result.add(s);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableList(result);
|
||||
}
|
||||
|
||||
Collection<String> test2(String[] list) {
|
||||
Set<String> result = new HashSet<>();
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
String s = list[i];
|
||||
if (!s.isEmpty()) {
|
||||
result.add(s);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableCollection(result);
|
||||
}
|
||||
|
||||
List<String> test3(String[] array) {
|
||||
Set<String> result = new HashSet<>();
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
String s = array[i];
|
||||
if (!s.isEmpty()) {
|
||||
result.add(s);
|
||||
}
|
||||
}
|
||||
List<String> list = new ArrayList<>(result);
|
||||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
|
||||
Set<String> test4(String[] array) {
|
||||
Set<String> result = new TreeSet<>();
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
String s = array[i];
|
||||
if (!s.isEmpty()) {
|
||||
result.add(s);
|
||||
}
|
||||
}
|
||||
// toUnmodifiableSet will not preserve order; not suggested here
|
||||
return Collections.unmodifiableSet(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user