IDEA-161260 Stream API Migration: support findFirst() patterns

This commit is contained in:
Tagir Valeev
2016-09-15 12:13:11 +07:00
parent 8722eec61f
commit 5a5929c43f
5 changed files with 102 additions and 4 deletions
@@ -0,0 +1,10 @@
// "Replace with findFirst()" "true"
import java.util.Collection;
import java.util.List;
public class Main {
public static String find(List<List<String>> list) {
return list.stream().flatMap(Collection::stream).filter(string -> string.startsWith("ABC")).findFirst().map(string -> string.substring(3)).orElse("");
}
}
@@ -0,0 +1,13 @@
// "Replace with findFirst()" "true"
import java.util.Collection;
import java.util.List;
public class Main {
public static String find(List<List<String>> list) {
if(list != null) {
return list.stream().flatMap(Collection::stream).filter(string -> string.startsWith("ABC")).findFirst().orElse(null);
}
return null;
}
}
@@ -0,0 +1,16 @@
// "Replace with findFirst()" "true"
import java.util.List;
public class Main {
public static String find(List<List<String>> list) {
for(List<String> innerList : li<caret>st) {
for(String string : innerList) {
if(string.startsWith("ABC")) {
return string.substring(3);
}
}
}
return "";
}
}
@@ -0,0 +1,18 @@
// "Replace with findFirst()" "true"
import java.util.List;
public class Main {
public static String find(List<List<String>> list) {
if(list != null) {
for (List<String> innerList : lis<caret>t) {
for (String string : innerList) {
if (string.startsWith("ABC")) {
return string;
}
}
}
}
return null;
}
}