StreamToLoop: unwrap negation and ternary; minor refactoring

This commit is contained in:
Tagir Valeev
2016-12-12 17:27:53 +07:00
parent 38ded66633
commit 810445f21d
9 changed files with 129 additions and 12 deletions
@@ -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;
}
}
@@ -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;
}
}
@@ -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";
}
}
@@ -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"));
}
}
@@ -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;
}
}
@@ -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";
}
}