support min/max in stream api migration, rearrange tests

This commit is contained in:
Roman Ivanov
2017-08-02 12:57:45 +07:00
parent dd4ba58889
commit 72bab18a58
561 changed files with 2091 additions and 17 deletions
@@ -0,0 +1,12 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Main {
List<String> test(List<String> list) {
List<String> result = list.stream().distinct().filter(s -> !s.contains("foo")).collect(Collectors.toList());
return result;
}
}
@@ -0,0 +1,13 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class Main {
List<String> test(Map<String, List<String>> map, int limit) {
List<String> list = map.entrySet().stream().filter(entry -> entry.getValue() != null).flatMap(entry -> entry.getValue().stream()).distinct().limit(limit).collect(Collectors.toList());
return list;
}
}
@@ -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);
}
}
@@ -0,0 +1,10 @@
// "Replace with toArray" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
public Object[] testToArray(List<String> data) {
return data.stream().filter(str -> !str.isEmpty()).toArray();
}
}
@@ -0,0 +1,13 @@
// "Replace with toArray" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
public Object[] testToArray(List<String> data) {
Object[] arr;
arr = data.stream().filter(str -> !str.isEmpty()).toArray();
System.out.println(Arrays.toString(arr));
return arr;
}
}
@@ -0,0 +1,11 @@
// "Replace with toArray" "true"
import java.util.Arrays;
import java.util.List;
public class Test {
public void test(List<Integer> ints) {
long[] arr = ints.stream().mapToLong(anInt -> anInt).toArray();
System.out.println(Arrays.toString(arr));
}
}
@@ -0,0 +1,11 @@
// "Replace with toArray" "true"
import java.util.Arrays;
import java.util.stream.IntStream;
public class Test {
public void test(int bound) {
Object[] arr = IntStream.range(0, bound).boxed().toArray(Integer[]::new);
System.out.println(Arrays.toString(arr));
}
}
@@ -0,0 +1,11 @@
// "Replace with toArray" "true"
import java.util.Arrays;
import java.util.stream.IntStream;
public class Test {
public void test(int bound) {
Integer[][] arr = IntStream.range(0, bound).mapToObj(i -> new Integer[]{i}).toArray(Integer[][]::new);
System.out.println(Arrays.toString(arr));
}
}
@@ -0,0 +1,11 @@
// "Replace with toArray" "true"
import java.util.Arrays;
import java.util.List;
public class Test {
public void test(List<List<String>> list) {
List<?>[] arr = list.toArray(new List[0]);
System.out.println(Arrays.toString(arr));
}
}
@@ -0,0 +1,12 @@
// "Replace with toArray" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
public Object[] testToArray(List<String> data) {
Object[] arr = data.stream().filter(str -> !str.isEmpty()).toArray();
System.out.println(Arrays.toString(arr));
return arr;
}
}
@@ -0,0 +1,9 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public List<?>[] testToArray(List<String> data) {
return data.stream().filter(str -> !str.isEmpty()).map(Collections::singletonList).distinct().toArray(List<?>[]::new);
}
}
@@ -0,0 +1,9 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public String[] testToArray(List<String> data) {
return data.stream().filter(str -> !str.isEmpty()).distinct().toArray(String[]::new);
}
}
@@ -0,0 +1,9 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public CharSequence[] testToArray(List<String> data) {
return data.stream().filter(str -> !str.isEmpty()).distinct().toArray(CharSequence[]::new);
}
}
@@ -0,0 +1,14 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public String[] testToArray(List<String> data) {
Set<String> result = new LinkedHashSet<>();
if(!data.isEmpty()) {
return data.stream().filter(str -> !str.isEmpty()).map(String::trim).distinct().toArray(String[]::new);
}
result.add("None");
return result.toArray(new String[1]);
}
}
@@ -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,9 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public Object[] testToArray(List<String> data) {
return data.stream().filter(str -> !str.isEmpty()).distinct().sorted().toArray(String[]::new);
}
}
@@ -0,0 +1,9 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public String[][] testToArray(List<String> data) {
return data.stream().filter(str -> !str.isEmpty()).map(str -> new String[]{str}).toArray(String[][]::new);
}
}
@@ -0,0 +1,20 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
List<String> test(List<String> list) {
List<String> result = new ArrayList<>();
for(String s : li<caret>st) {
if(result.contains(s)) {
continue;
}
if(s.contains("foo")) {
continue;
}
result.add(s);
}
return result;
}
}
@@ -0,0 +1,22 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Main {
List<String> test(Map<String, List<String>> map, int limit) {
List<String> list = new ArrayList<>();
for (Map.Entry<String, List<String>> entry : map.<caret>entrySet()) {
if(entry.getValue() != null) {
for(String str : entry.getValue()) {
if (!list.contains(str)) {
list.add(str);
}
if (list.size() >= limit) return list;
}
}
}
return list;
}
}
@@ -0,0 +1,20 @@
// "Replace with collect" "false"
import java.util.ArrayList;
import java.util.List;
public class Main {
List<String> test(List<String> list) {
List<String> result = new ArrayList<>();
for (String s : li<caret>st) {
if (result.contains(s)) {
continue;
}
if (s.contains("foo")) {
continue;
}
result.add(s + s);
}
return result;
}
}
@@ -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]);
}
}
@@ -0,0 +1,15 @@
// "Replace with toArray" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
public Object[] testToArray(List<String> data) {
List<String> result = new ArrayList<>();
for (String str : d<caret>ata) {
if (!str.isEmpty())
result.add(str);
}
return result.toArray();
}
}
@@ -0,0 +1,18 @@
// "Replace with toArray" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
public Object[] testToArray(List<String> data) {
Object[] arr;
List<String> result = new ArrayList<>();
for (String str : d<caret>ata) {
if (!str.isEmpty())
result.add(str);
}
arr = result.toArray();
System.out.println(Arrays.toString(arr));
return arr;
}
}
@@ -0,0 +1,14 @@
// "Replace with toArray" "true"
import java.util.Arrays;
import java.util.List;
public class Test {
public void test(List<Integer> ints) {
long[] arr = new long[ints.size()];
for(int <caret>i = 0; i < ints.size(); i++) {
arr[i] = ints.get(i);
}
System.out.println(Arrays.toString(arr));
}
}
@@ -0,0 +1,13 @@
// "Replace with toArray" "true"
import java.util.Arrays;
public class Test {
public void test(int bound) {
Object[] arr = new Integer[bound];
for(int <caret>i = 0; i < bound; i++) {
arr[i] = i;
}
System.out.println(Arrays.toString(arr));
}
}
@@ -0,0 +1,13 @@
// "Replace with toArray" "true"
import java.util.Arrays;
public class Test {
public void test(int bound) {
Integer[][] arr = new Integer[bound][];
for(int <caret>i = 0; i < arr.length; i++) {
arr[i] = new Integer[] {i};
}
System.out.println(Arrays.toString(arr));
}
}
@@ -0,0 +1,14 @@
// "Replace with toArray" "true"
import java.util.Arrays;
import java.util.List;
public class Test {
public void test(List<List<String>> list) {
List<?>[] arr = new List[list.size()];
for(i<caret>nt i = 0; i < arr.length; i++) {
arr[i] = list.get(i);
}
System.out.println(Arrays.toString(arr));
}
}
@@ -0,0 +1,17 @@
// "Replace with toArray" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
public Object[] testToArray(List<String> data) {
List<String> result = new ArrayList<>();
for (String str : d<caret>ata) {
if (!str.isEmpty())
result.add(str);
}
Object[] arr = result.toArray();
System.out.println(Arrays.toString(arr));
return arr;
}
}
@@ -0,0 +1,17 @@
// "Replace with toArray" "false"
import java.util.ArrayList;
import java.util.List;
public class Main {
public Object[] testToArray(List<String> data) {
List<String> result = new ArrayList<>();
for (String str : d<caret>ata) {
if (!str.isEmpty())
result.add(str);
}
Object[] arr = result.toArray();
System.out.println(result);
return arr;
}
}
@@ -0,0 +1,16 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public List<?>[] testToArray(List<String> data) {
Set<List<String>> result = new LinkedHashSet<>();
for (String str : dat<caret>a) {
if (!str.isEmpty()) {
List<String> list = Collections.singletonList(str);
result.add(list);
}
}
return result.toArray(new List<?>[0]);
}
}
@@ -0,0 +1,14 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public String[] testToArray(List<String> data) {
Set<String> result = new HashSet<>();
for (String str : d<caret>ata) {
if (!str.isEmpty())
result.add(str);
}
return result.toArray(new String[0]);
}
}
@@ -0,0 +1,15 @@
// "Replace with toArray" "false"
import java.util.ArrayList;
import java.util.List;
public class Main {
public Object[] testToArray(List<String> data) {
Set<String> result = new IdentityHashSet<>();
for (String str : d<caret>ata) {
if (!str.isEmpty())
result.add(str);
}
return result.toArray();
}
}
@@ -0,0 +1,14 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public CharSequence[] testToArray(List<String> data) {
Set<String> result = new LinkedHashSet<>();
for (String str : d<caret>ata) {
if (!str.isEmpty())
result.add(str);
}
return result.toArray(new CharSequence[result.size()]);
}
}
@@ -0,0 +1,19 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public String[] testToArray(List<String> data) {
Set<String> result = new LinkedHashSet<>();
if(!data.isEmpty()) {
for (String str : d<caret>ata) {
if (!str.isEmpty()) {
result.add(str.trim());
}
}
return result.toArray(new String[result.size()]);
}
result.add("None");
return result.toArray(new String[1]);
}
}
@@ -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;
}
}
@@ -0,0 +1,14 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public Object[] testToArray(List<String> data) {
Set<String> result = new TreeSet<>();
for (String str : d<caret>ata) {
if (!str.isEmpty())
result.add(str);
}
return result.toArray(new String[result.size()]);
}
}
@@ -0,0 +1,16 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public String[][] testToArray(List<String> data) {
List<String[]> result = new ArrayList<>();
for (String str : dat<caret>a) {
if (!str.isEmpty()) {
String[] arr = {str};
result.add(arr);
}
}
return result.toArray(new String[result.size()][]);
}
}
@@ -0,0 +1,15 @@
// "Replace with toArray" "false"
import java.util.ArrayList;
import java.util.List;
public class Main {
public Object[] testToArray(List<String> data) {
List<String> result = new ArrayList<>();
for (String str : d<caret>ata) {
if (!str.isEmpty())
result.add(str);
}
return result.toArray(new String[10]);
}
}