mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 00:11:26 +07:00
StreamToLoopInspection: sorted() operation (currently for non-primitive streams only)
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public String testSorted(List<List<String>> list) {
|
||||
for (List<String> lst : list) {
|
||||
List<String> toSort = new ArrayList<>();
|
||||
for (String x : lst) {
|
||||
if (x != null) {
|
||||
toSort.add(x);
|
||||
}
|
||||
}
|
||||
toSort.sort(null);
|
||||
for (String x : toSort) {
|
||||
if (x.length() < 5) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.*;
|
||||
|
||||
public class Main {
|
||||
public List<String> testSorted(List<String> list) {
|
||||
List<String> toSort = new ArrayList<>();
|
||||
for (String s : list) {
|
||||
if (s != null) {
|
||||
toSort.add(s);
|
||||
}
|
||||
}
|
||||
toSort.sort(null);
|
||||
List<String> result = new ArrayList<>();
|
||||
Set<String> uniqueValues = new HashSet<>();
|
||||
for (String s : toSort) {
|
||||
String trim = s.trim();
|
||||
if (uniqueValues.add(trim)) {
|
||||
result.add(trim);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.*;
|
||||
|
||||
public class Main {
|
||||
public List<String> testSorted(List<String> list) {
|
||||
List<String> toSort = new ArrayList<>();
|
||||
for (String s : list) {
|
||||
toSort.add(s);
|
||||
}
|
||||
toSort.sort(String.CASE_INSENSITIVE_ORDER);
|
||||
List<String> result = new ArrayList<>();
|
||||
for (String s : toSort) {
|
||||
result.add(s);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public String testSorted(List<List<String>> list) {
|
||||
return list.stream().flatMap(lst -> lst.stream().filter(Objects::nonNull).sorted()).filter(x -> x.length() < 5).<caret>findFirst().orElse("");
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.*;
|
||||
|
||||
public class Main {
|
||||
public List<String> testSorted(List<String> list) {
|
||||
return list.stream().filter(Objects::nonNull).sorted().map(String::trim).distinct().<caret>collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.*;
|
||||
|
||||
public class Main {
|
||||
public List<String> testSorted(List<String> list) {
|
||||
return list.stream().sorted(String.CASE_INSENSITIVE_ORDER).<caret>collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user