mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-25 14:25:04 +07:00
StreamToLoop: unwrap negation and ternary; minor refactoring
This commit is contained in:
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Main {
|
||||
boolean test(String[] strings) {
|
||||
for (String s : strings) {
|
||||
if (Objects.nonNull(s)) {
|
||||
if (!s.startsWith("xyz")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Main {
|
||||
String test(String[] strings) {
|
||||
for (String s : strings) {
|
||||
if (Objects.nonNull(s)) {
|
||||
if (!s.startsWith("xyz")) {
|
||||
return "s";
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Main {
|
||||
String test(List<List<String>> strings) {
|
||||
for (List<String> string : strings) {
|
||||
if (Objects.nonNull(string)) {
|
||||
for (String s : string) {
|
||||
return "abc";
|
||||
}
|
||||
}
|
||||
}
|
||||
return "xyz";
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Main {
|
||||
boolean test(String[] strings) {
|
||||
return !Arrays.stream(strings).filter(Objects::nonNull).allM<caret>atch(s -> s.startsWith("xyz"));
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Main {
|
||||
String test(String[] strings) {
|
||||
return Arrays.stream(strings).filter(Objects::nonNull).an<caret>yMatch(s -> !s.startsWith("xyz")) ? "s" : null;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Main {
|
||||
String test(List<List<String>> strings) {
|
||||
return !strings.stream().filter(Objects::nonNull).flatMap(List::stream).fin<caret>dFirst().isPresent() ? "xyz" : "abc";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user