IDEA-166499 Stream API migration: support array filling in a loop

This commit is contained in:
Tagir Valeev
2017-01-12 17:37:10 +07:00
parent dd51b4ee06
commit 5b04785164
10 changed files with 202 additions and 1 deletions
@@ -0,0 +1,12 @@
// "Replace with toArray" "true"
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
public class Test {
public void test(List<Integer> ints) {
long[] arr = IntStream.range(0, ints.size()).mapToLong(ints::get).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,12 @@
// "Replace with toArray" "true"
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
public class Test {
public void test(List<List<String>> list) {
List<?>[] arr = IntStream.range(0, list.size()).mapToObj(list::get).toArray(List[]::new);
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<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));
}
}