IDEA-151523 Replace with collect when working with an existing collection

This commit is contained in:
Tagir Valeev
2016-09-08 15:22:06 +07:00
parent 8015562c2d
commit 55c8f0cf46
15 changed files with 69 additions and 65 deletions
@@ -1,6 +1,5 @@
// "Replace with collect" "true"
// "Replace with forEach" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Collect {
class Person {
@@ -11,6 +10,6 @@ public class Collect {
void collectNames(List<Person> persons){
List<String> names = new ArrayList<>(), otherNames = new ArrayList<>(names);
names.addAll(persons.stream().map(Person::getName).collect(Collectors.toList()));
persons.stream().map(Person::getName).forEach(names::add);
}
}
@@ -1,6 +1,5 @@
// "Replace with collect" "true"
// "Replace with forEach" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Collect {
class Person {
@@ -15,6 +14,6 @@ public class Collect {
void collectNames(List<Person> persons){
List<String> names = foo();
names.addAll(persons.stream().map(Person::getName).collect(Collectors.toList()));
persons.stream().map(Person::getName).forEach(names::add);
}
}
@@ -1,6 +1,5 @@
// "Replace with collect" "true"
// "Replace with forEach" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Collect {
class Person {
@@ -11,6 +10,6 @@ public class Collect {
Set<String> names = new HashSet<>();
void collectNames(List<Person> persons){
names.addAll(persons.stream().map(Person::getName).collect(Collectors.toList()));
persons.stream().map(Person::getName).forEach(names::add);
}
}
@@ -1,6 +1,5 @@
// "Replace with collect" "true"
// "Replace with forEach" "true"
import java.util.*;
import java.util.stream.Collectors;
public abstract class Collect implements Collection<String>{
class Person {
@@ -10,6 +9,6 @@ public abstract class Collect implements Collection<String>{
}
void collectNames(List<Person> persons){
addAll(persons.stream().map(Person::getName).collect(Collectors.toList()));
persons.stream().map(Person::getName).forEach(this::add);
}
}
@@ -1,6 +1,5 @@
// "Replace with collect" "true"
// "Replace with forEach" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Collect {
class Person {
@@ -10,6 +9,6 @@ public class Collect {
}
void collectNames(List<Person> persons, Set<String> names){
names.addAll(persons.stream().map(Person::getName).collect(Collectors.toList()));
persons.stream().map(Person::getName).forEach(names::add);
}
}
@@ -1,10 +1,9 @@
// "Replace with collect" "true"
// "Replace with forEach" "true"
import java.util.List;
import java.util.stream.Collectors;
public class A {
private void withStream(List<String> stream, final List<String> activeFilters) {
activeFilters.addAll(stream.stream().filter(String::isEmpty).collect(Collectors.toList()));
stream.stream().filter(String::isEmpty).forEach(activeFilters::add);
}
}
@@ -1,9 +1,8 @@
// "Replace with collect" "true"
// "Replace with forEach" "true"
import java.util.List;
import java.util.stream.Collectors;
class Sample {
public void some(List<String> from, List<Integer> to) {
to.addAll(from.stream().map(String::length).collect(Collectors.toList()));
from.stream().map(String::length).forEach(to::add);
}
}
@@ -1,4 +1,4 @@
// "Replace with collect" "true"
// "Replace with forEach" "true"
import java.util.*;
public class Collect {
@@ -1,4 +1,4 @@
// "Replace with collect" "true"
// "Replace with forEach" "true"
import java.util.*;
public class Collect {
@@ -1,4 +1,4 @@
// "Replace with collect" "true"
// "Replace with forEach" "true"
import java.util.*;
public class Collect {
@@ -1,4 +1,4 @@
// "Replace with collect" "true"
// "Replace with forEach" "true"
import java.util.*;
public abstract class Collect implements Collection<String>{
@@ -1,4 +1,4 @@
// "Replace with collect" "true"
// "Replace with forEach" "true"
import java.util.*;
public class Collect {
@@ -1,4 +1,4 @@
// "Replace with collect" "true"
// "Replace with forEach" "true"
import java.util.List;
@@ -1,4 +1,4 @@
// "Replace with collect" "true"
// "Replace with forEach" "true"
import java.util.List;
class Sample {