mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 03:13:40 +07:00
Stream API migration: replace with findFirst().ifPresent() chain
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace with findFirst()" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public Integer[] testFindFirstIfPresent(List<List<String>> data) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
for (List<String> list : data) {
|
||||
list.stream().filter(str -> !str.isEmpty()).findFirst().ifPresent(str -> result.add(str.length()));
|
||||
}
|
||||
return result.toArray(new Integer[result.size()]);
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace with findFirst()" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public Integer[] testFindFirstIfPresent(List<List<String>> data) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
for (List<String> list : data) {
|
||||
for (String str : lis<caret>t) {
|
||||
if (!str.isEmpty()) {
|
||||
result.add(str.length());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toArray(new Integer[result.size()]);
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Replace with findFirst()" "false"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
// The result will have block-lambda so we don't suggest the replacement here
|
||||
public class Main {
|
||||
public Integer[] testFindFirstIfPresent(List<List<String>> data) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
for (List<String> list : data) {
|
||||
for (String str : lis<caret>t) {
|
||||
if (!str.isEmpty()) {
|
||||
result.add(str.length());
|
||||
System.out.println(str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toArray(new Integer[result.size()]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user