StreamApiMigrationInspection: refactoring of collect scenarios: CollectTerminal interface extracted and used; all forEach scenarios moved to ForEachMigration; cosmetics

This commit is contained in:
Tagir Valeev
2017-01-11 14:37:50 +07:00
parent 1d89b014b0
commit b3a181a091
9 changed files with 789 additions and 571 deletions
@@ -8,8 +8,8 @@ public class Collect {
}
}
Set<String> names = new HashSet<>();
final Set<String> names = new HashSet<>();
void collectNames(List<Person> persons){
persons.stream().map(Person::getName).forEach(s -> names.add(s));
persons.stream().map(Person::getName).forEach(names::add);
}
}
@@ -0,0 +1,8 @@
// "Replace with toArray" "true"
import java.util.*;
public class Test {
String[] test(List<String> list) {
return list.stream().filter(Objects::nonNull).sorted(String.CASE_INSENSITIVE_ORDER).toArray(String[]::new);
}
}
@@ -8,7 +8,7 @@ public class Collect {
}
}
Set<String> names = new HashSet<>();
final Set<String> names = new HashSet<>();
void collectNames(List<Person> persons){
for (Person person : pers<caret>ons) {
names.add(person.getName());
@@ -4,7 +4,7 @@ import java.util.*;
class A {
void fun(List<String>... lists) {
for (List<String> list : li<caret>sts) {
System.out.println(list);
list.add("");
}
}
@@ -0,0 +1,15 @@
// "Replace with toArray" "true"
import java.util.*;
public class Test {
String[] test(List<String> list) {
List<String> result = new LinkedList<>();
for(String str : li<caret>st) {
if(str != null) {
result.add(str);
}
}
result.sort(String.CASE_INSENSITIVE_ORDER);
return result.toArray(new String[0]);
}
}