mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 03:13:40 +07:00
StreamApiMigrationInspection: use Stream.of, etc. to iterate explicitly created array
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
// "Fix all 'Loop can be collapsed with Stream API' problems in file" "true"
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
public String test(String other) {
|
||||
return Stream.of("aaa", "bbb", "ccc", "ddd").filter(other::startsWith).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public CharSequence test2(String other) {
|
||||
return Stream.<CharSequence>of("aaa", "bbb", "ccc", "ddd").filter(s -> other.startsWith(s.toString())).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public int test(int other) {
|
||||
return IntStream.of(2, 4, 8, 16, 32, 64, 128, 256, 512, 1024).filter(i -> i > other).findFirst().orElse(-1);
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// "Fix all 'Loop can be collapsed with Stream API' problems in file" "true"
|
||||
|
||||
public class Test {
|
||||
public String test(String other) {
|
||||
for(String s : new <caret>String[] {"aaa", "bbb", "ccc", "ddd"}) {
|
||||
if(other.startsWith(s)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public CharSequence test2(String other) {
|
||||
for(CharSequence s : new CharSequence[] {"aaa", "bbb", "ccc", "ddd"}) {
|
||||
if(other.startsWith(s.toString())) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int test(int other) {
|
||||
for(int i : new int[] {2, 4, 8, 16, 32, 64, 128, 256, 512, 1024}) {
|
||||
if(i > other) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user