IDEA-166814 Stream API migration: support more post-loop steps

This commit is contained in:
Tagir Valeev
2017-01-19 14:14:20 +07:00
parent 964e8dea52
commit 327e51962b
12 changed files with 380 additions and 150 deletions
@@ -0,0 +1,10 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Test {
public static LinkedList<String> test(String[] args) {
return Arrays.stream(args).filter(s -> !s.isEmpty()).distinct().sorted().collect(Collectors.toCollection(LinkedList::new));
}
}
@@ -0,0 +1,9 @@
// "Replace with toArray" "true"
import java.util.*;
public class Test {
public static String[] test(String[] args) {
return Arrays.stream(args).filter(s -> !s.isEmpty()).distinct().sorted().toArray(String[]::new);
}
}
@@ -0,0 +1,9 @@
// "Replace with toArray" "true"
import java.util.*;
public class Test {
public static void test(String[] args) {
System.out.println(Arrays.toString(Arrays.stream(args).filter(s -> !s.isEmpty()).distinct().sorted(String.CASE_INSENSITIVE_ORDER).toArray(String[]::new)));
}
}
@@ -0,0 +1,9 @@
// "Replace with toArray" "true"
import java.util.*;
public class Test {
public static String[] test(String[] args) {
return Arrays.stream(args).filter(s -> !s.isEmpty()).distinct().sorted().toArray(String[]::new);
}
}
@@ -0,0 +1,10 @@
// "Replace with toArray" "true"
import java.util.*;
public class Test {
public static String[] test(String[] args) {
String[] array = Arrays.stream(args).filter(s -> !s.isEmpty()).distinct().sorted(String.CASE_INSENSITIVE_ORDER).toArray(String[]::new);
return array;
}
}
@@ -0,0 +1,16 @@
// "Replace with collect" "true"
import java.util.*;
public class Test {
public static LinkedList<String> test(String[] args) {
Set<String> set = new HashSet<>();
for(String s : ar<caret>gs) {
if(!s.isEmpty())
set.add(s);
}
List<String> list = new ArrayList<>(set);
list.sort(null);
return new LinkedList<>(list);
}
}
@@ -0,0 +1,16 @@
// "Replace with toArray" "true"
import java.util.*;
public class Test {
public static String[] test(String[] args) {
Set<String> set = new HashSet<>();
for(String s : a<caret>rgs) {
if(!s.isEmpty())
set.add(s);
}
List<String> list = new ArrayList<>(set);
list.sort(null);
return list.toArray(new String[0]);
}
}
@@ -0,0 +1,16 @@
// "Replace with toArray" "true"
import java.util.*;
public class Test {
public static void test(String[] args) {
Set<String> set = new HashSet<>();
for(String s : ar<caret>gs) {
if(!s.isEmpty())
set.add(s);
}
List<String> list = new LinkedList<>(set);
list.sort(String.CASE_INSENSITIVE_ORDER);
System.out.println(Arrays.toString(list.toArray(new String[0])));
}
}
@@ -0,0 +1,15 @@
// "Replace with toArray" "true"
import java.util.*;
public class Test {
public static String[] test(String[] args) {
List<String> list = new ArrayList<>();
for(String s : ar<caret>gs) {
if(!s.isEmpty())
list.add(s);
}
Set<String> set = new TreeSet<>(list);
return set.toArray(new String[0]);
}
}
@@ -0,0 +1,17 @@
// "Replace with toArray" "true"
import java.util.*;
public class Test {
public static String[] test(String[] args) {
List<String> list = new ArrayList<>();
for(String s : ar<caret>gs) {
if(!s.isEmpty())
list.add(s);
}
Set<String> set = new HashSet<>(list);
String[] array = set.toArray(new String[set.size()]);
Arrays.sort(array, String.CASE_INSENSITIVE_ORDER);
return array;
}
}