mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 15:27:45 +07:00
IDEA-151523 Replace with collect when working with an existing collection
This commit is contained in:
+2
-3
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -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);
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -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
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace with collect" "true"
|
||||
// "Replace with forEach" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace with collect" "true"
|
||||
// "Replace with forEach" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace with collect" "true"
|
||||
// "Replace with forEach" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace with collect" "true"
|
||||
// "Replace with forEach" "true"
|
||||
import java.util.*;
|
||||
|
||||
public abstract class Collect implements Collection<String>{
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace with collect" "true"
|
||||
// "Replace with forEach" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace with collect" "true"
|
||||
// "Replace with forEach" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace with collect" "true"
|
||||
// "Replace with forEach" "true"
|
||||
import java.util.List;
|
||||
|
||||
class Sample {
|
||||
|
||||
Reference in New Issue
Block a user