IDEA-161002 Migration to Stream API: convert return true/return false to anyMatch/noneMatch

This commit is contained in:
Tagir Valeev
2016-09-09 17:41:19 +07:00
parent b44b47201b
commit 884043aacc
5 changed files with 114 additions and 0 deletions
@@ -0,0 +1,9 @@
// "Replace with anyMatch()" "true"
import java.util.List;
public class Main {
boolean find(List<String> data) {
return data.stream().map(String::trim).anyMatch(trimmed -> trimmed.startsWith("xyz"));
}
}
@@ -0,0 +1,9 @@
// "Replace with noneMatch()" "true"
import java.util.Arrays;
public class Main {
boolean find(String[][] data) {
return Arrays.stream(data).flatMap(Arrays::stream).noneMatch(str -> str.startsWith("xyz"));
}
}
@@ -0,0 +1,15 @@
// "Replace with anyMatch()" "true"
import java.util.List;
public class Main {
boolean find(List<String> data) {
for(String e : da<caret>ta) {
String trimmed = e.trim();
if(trimmed.startsWith("xyz")) {
return true;
}
}
return false;
}
}
@@ -0,0 +1,14 @@
// "Replace with noneMatch()" "true"
public class Main {
boolean find(String[][] data) {
for(String[] arr : da<caret>ta) {
for(String str : arr) {
if(str.startsWith("xyz")) {
return false;
}
}
}
return true;
}
}