mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-25 14:25:04 +07:00
FuseStreamOperationsInspection
Fixes IDEA-179303 Suggest replacing Collectors.toList()/toSet() + collection constructor with Collectors.toCollection
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
// "Fix all 'Subsequent steps can be fused into Stream API chain' problems in file" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
interface Foo {
|
||||
}
|
||||
|
||||
// IDEA-179303
|
||||
void test1(Stream<Foo> fooStream) {
|
||||
ArrayList<Foo> collectedFoos = fooStream.collect(Collectors.toCollection(ArrayList::new));
|
||||
}
|
||||
|
||||
void test2(Stream<Foo> fooStream) {
|
||||
List<Foo> collectedFoos = fooStream.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Fuse HashSet and ArrayList into the Stream API chain" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
Collection<String> test(String[] args) {
|
||||
return Arrays.stream(args).filter(String::isEmpty).distinct().collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Fuse ArrayList, 'sort' and 'toArray' into the Stream API chain" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
public void testSetListSort(String[] args) {
|
||||
System.out.println(Arrays.stream(args).distinct().sorted().toArray());
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Fuse 'sort' into the Stream API chain" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
public List<String> testToArray(String[] args) {
|
||||
List<String> list = Arrays.stream(args).sorted().collect(Collectors.toList());
|
||||
return list;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Fuse 'toArray' into the Stream API chain" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
public String[] testToArray(String[] args) {
|
||||
return Arrays.stream(args).toArray(String[]::new);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Fuse 'toArray' into the Stream API chain" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
public String[] testToArray(String[] args) {
|
||||
return Arrays.stream(args).distinct().sorted().toArray(String[]::new);
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Fix all 'Subsequent steps can be fused into Stream API chain' problems in file" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
interface Foo {
|
||||
}
|
||||
|
||||
// IDEA-179303
|
||||
void test1(Stream<Foo> fooStream) {
|
||||
ArrayList<Foo> collectedFoos = new ArrayList<>(fooStream.co<caret>llect(Collectors.toList()));
|
||||
}
|
||||
|
||||
void test2(Stream<Foo> fooStream) {
|
||||
List<Foo> collectedFoos = new ArrayList<>(fooStream.collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Fuse HashSet and ArrayList into the Stream API chain" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
Collection<String> test(String[] args) {
|
||||
List<String> list = Arrays.stream(args).filter(String::isEmpty).coll<caret>ect(Collectors.toList());
|
||||
HashSet<String> strings = new HashSet<>(list);
|
||||
return new ArrayList<>(strings);
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Fuse ArrayList, 'sort' and 'toArray' into the Stream API chain" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
public void testSetListSort(String[] args) {
|
||||
Set<String> set = Arrays.stream(args).co<caret>llect(Collectors.toSet());
|
||||
List<String> list = new ArrayList<>(set);
|
||||
list.sort(null);
|
||||
System.out.println(list.toArray());
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Fuse 'sort' into the Stream API chain" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
public List<String> testToArray(String[] args) {
|
||||
List<String> list = Arrays.stream(args).c<caret>ollect(Collectors.toList());
|
||||
list.sort(null);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Fuse 'toArray' into the Stream API chain" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
public String[] testToArray(String[] args) {
|
||||
List<String> list = Arrays.stream(args).co<caret>llect(Collectors.toList());
|
||||
return list.toArray(new String[list.size()]);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Fuse 'toArray' into the Stream API chain" "true"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
public String[] testToArray(String[] args) {
|
||||
Set<String> set = Arrays.stream(args).co<caret>llect(Collectors.toCollection(TreeSet::new));
|
||||
return set.toArray(new String[set.size()]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user