StreamAPI migration: propose to use any/all/noneMatch if next return is not true/false (using || or &&)

This commit is contained in:
Tagir Valeev
2016-10-04 15:32:19 +07:00
parent 94bd721ae1
commit 10c8616d19
5 changed files with 54 additions and 13 deletions
@@ -0,0 +1,9 @@
// "Replace with allMatch()" "true"
import java.util.List;
public class Main {
boolean find(List<String> data, boolean other, boolean third) {
return data.stream().map(String::trim).allMatch(trimmed -> trimmed.startsWith("xyz")) && (other || third);
}
}
@@ -0,0 +1,9 @@
// "Replace with anyMatch()" "true"
import java.util.List;
public class Main {
boolean find(List<String> data, boolean other, boolean third) {
return data.stream().map(String::trim).anyMatch(trimmed -> trimmed.startsWith("xyz")) || (other || third);
}
}
@@ -0,0 +1,15 @@
// "Replace with allMatch()" "true"
import java.util.List;
public class Main {
boolean find(List<String> data, boolean other, boolean third) {
for(String e : da<caret>ta) {
String trimmed = e.trim();
if(!trimmed.startsWith("xyz")) {
return false;
}
}
return other || third;
}
}