mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 03:13:40 +07:00
StreamToLoopInspection: added ExplicitCollectTerminalOperation; StreamVariable simplified; guard checks added (IDEA-CR-15249)
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Main {
|
||||
private static void test(List<String> list) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String str : list) {
|
||||
if (Objects.nonNull(str)) {
|
||||
sb.append(str);
|
||||
}
|
||||
}
|
||||
String result = sb.toString();
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
test(Arrays.asList("aa", "bbb", "c", null, "dd"));
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
private static long test(List<? extends String> list) {
|
||||
long count = 0;
|
||||
for (Object o : Arrays.<Object>asList(0, null, "1", list)) {
|
||||
for (Object o1 : Arrays.<Object>asList(o)) {
|
||||
for (Object o2 : Arrays.<Object>asList(o1)) {
|
||||
for (Object o3 : Arrays.<Object>asList(o2)) {
|
||||
for (Object o4 : Arrays.<Object>asList(o3)) {
|
||||
for (Object o5 : Arrays.<Object>asList(o4)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
test(Arrays.asList("aa", "bbb", "c", null, "dd"));
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static void test(List<String> list) {
|
||||
long count1 = 0;
|
||||
for (String s : list) {
|
||||
if (!s.isEmpty()) {
|
||||
count1++;
|
||||
}
|
||||
}
|
||||
long count = count1;
|
||||
if(count > 10) {
|
||||
long result = count*2;
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Main {
|
||||
private static void test(List<String> list) {
|
||||
String result = list.stream().filter(Objects::nonNull).coll<caret>ect(StringBuilder::new, (sb, str) -> sb.append(str), StringBuilder::append).toString();
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
test(Arrays.asList("aa", "bbb", "c", null, "dd"));
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
private static long test(List<? extends String> list) {
|
||||
return Stream.of(0, null, "1", list).flatMap(Stream::of).flatMap(Stream::of).flatMap(Stream::of).flatMap(Stream::of).flatMap(Stream::of).coun<caret>t();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
test(Arrays.asList("aa", "bbb", "c", null, "dd"));
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static void test(List<String> list) {
|
||||
long count = list.stream().filter(s -> !s.isEmpty()).co<caret>unt();
|
||||
if(count > 10) {
|
||||
long result = count*2;
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user