IDEA-161002 More anyMatch cases supported with if statement

This commit is contained in:
Tagir Valeev
2016-09-19 12:19:21 +07:00
parent 8a7738690a
commit 6919b5ddd6
8 changed files with 178 additions and 52 deletions
@@ -0,0 +1,16 @@
// "Replace with anyMatch()" "true"
import java.util.Arrays;
import java.util.Objects;
public class Main {
String contains(String[][] haystack, String needle) {
if(haystack != null) {
if (Arrays.stream(haystack).filter(Objects::nonNull).flatMap(Arrays::stream).anyMatch(needle::equals)) {
return "yes" + needle.length();
}
System.out.println("oops");
}
return "no";
}
}
@@ -0,0 +1,16 @@
// "Replace with anyMatch()" "true"
import java.util.Arrays;
import java.util.Objects;
public class Main {
boolean contains(String[][] haystack, String needle) {
if(haystack != null) {
if (Arrays.stream(haystack).filter(Objects::nonNull).flatMap(Arrays::stream).anyMatch(needle::equals)) {
return true;
}
System.out.println("Oops");
}
return false;
}
}
@@ -0,0 +1,15 @@
// "Replace with anyMatch()" "true"
import java.util.Arrays;
import java.util.Objects;
public class Main {
void contains(String[][] haystack, String needle) {
if(haystack != null) {
if (Arrays.stream(haystack).filter(Objects::nonNull).flatMap(Arrays::stream).anyMatch(needle::equals)) {
return;
}
}
throw new IllegalStateException();
}
}
@@ -0,0 +1,17 @@
// "Replace with anyMatch()" "true"
public class Main {
String contains(String[][] haystack, String needle) {
if(haystack != null) {
for (String[] row : haysta<caret>ck) {
if (row == null) continue;
for (String str : row) {
if (needle.equals(str))
return "yes"+needle.length();
}
}
System.out.println("oops");
}
return "no";
}
}
@@ -1,4 +1,4 @@
// "Replace with anyMatch()" "false"
// "Replace with anyMatch()" "true"
public class Main {
boolean contains(String[][] haystack, String needle) {
@@ -0,0 +1,17 @@
// "Replace with anyMatch()" "false"
public class Main {
String contains(String[][] haystack, String needle) {
if(haystack != null) {
for (String[] row : haysta<caret>ck) {
if (row == null) continue;
for (String str : row) {
if (needle.equals(str))
return "yes"+str;
}
}
System.out.println("oops");
}
return "no";
}
}
@@ -0,0 +1,16 @@
// "Replace with anyMatch()" "true"
public class Main {
void contains(String[][] haystack, String needle) {
if(haystack != null) {
for (String[] row : haysta<caret>ck) {
if (row == null) continue;
for (String str : row) {
if (needle.equals(str))
return;
}
}
}
throw new IllegalStateException();
}
}