mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 00:11:26 +07:00
IDEA-161260 Stream API Migration: support findFirst() patterns
This commit is contained in:
+10
@@ -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("");
|
||||
}
|
||||
}
|
||||
+13
@@ -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;
|
||||
}
|
||||
}
|
||||
+16
@@ -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 "";
|
||||
}
|
||||
}
|
||||
+18
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user