StreamApiMigrationInspection: support limit count with separate variable

This commit is contained in:
Tagir Valeev
2016-12-22 12:33:15 +07:00
parent 7a4f20aacb
commit e2b7d60680
9 changed files with 205 additions and 119 deletions
@@ -0,0 +1,10 @@
// "Replace with findFirst()" "true"
import java.util.Arrays;
import java.util.Objects;
public class Main {
public String test(String[] array) {
return Arrays.stream(array).limit(11).filter(Objects::nonNull).findFirst().orElse("");
}
}
@@ -0,0 +1,11 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Main {
public Set<String> test(String[] array) {
Set<String> set = Arrays.stream(array).filter(Objects::nonNull).limit(10).collect(Collectors.toSet());
return set;
}
}
@@ -0,0 +1,14 @@
// "Replace with findFirst()" "true"
public class Main {
public String test(String[] array) {
int count = 0;
for(String str : a<caret>rray) {
if (str != null) {
return str;
}
if(++count > 10) return "";
}
return "";
}
}
@@ -0,0 +1,17 @@
// "Replace with collect" "true"
import java.util.*;
public class Main {
public Set<String> test(String[] array) {
int count = 0;
Set<String> set = new HashSet<>();
for(String str : a<caret>rray) {
if (str != null) {
set.add(str);
if(++count == 10) break;
}
}
return set;
}
}