IDEA-162157 Stream API migration: support counted for loop (both outer and flatMapped)

This commit is contained in:
Tagir Valeev
2016-10-06 17:59:25 +07:00
parent bc07d72213
commit 0ad3891e96
26 changed files with 609 additions and 257 deletions
@@ -0,0 +1,11 @@
// "Replace with findFirst()" "true"
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
public class Main {
public String testNestedForLoop(int[] data, List<String> info) {
return Arrays.stream(data).flatMap(val -> IntStream.rangeClosed(0, val)).mapToObj(info::get).filter(str -> !str.isEmpty()).findFirst().orElse(null);
}
}
@@ -0,0 +1,12 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main {
public void testForLoop(List<String> input) {
List<Integer> result = IntStream.range(0, 10).mapToObj(i -> input.get(i).length()).collect(Collectors.toList());
}
}
@@ -0,0 +1,12 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main {
public void testForLoop() {
List<Integer> result = IntStream.rangeClosed(0, 10).boxed().collect(Collectors.toList());
}
}
@@ -0,0 +1,14 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main {
public void testForLoop(List<String> input) {
List<Integer> result;
short s = (short)input.size();
result = IntStream.range(0, s).mapToObj(i -> input.get(i).length()).collect(Collectors.toList());
}
}
@@ -0,0 +1,8 @@
import java.util.Arrays;
// "Replace with forEach" "true"
public class Main {
public void test(int[] arr) {
Arrays.stream(arr).filter(i -> i > 0).forEach(System.out::println);
}
}
@@ -0,0 +1,18 @@
// "Replace with findFirst()" "false"
public class Main {
public boolean check(int value) {
return value == 3;
}
public void find() {
int end = 10;
for(<caret>int i=0; i<end; i++) {
if(check(i)) {
end = i;
break;
}
}
System.out.println(end);
}
}
@@ -0,0 +1,17 @@
// "Replace with findFirst()" "true"
import java.util.List;
public class Main {
public String testNestedForLoop(int[] data, List<String> info) {
for(int val : da<caret>ta) {
for(int x = 0; x <= val; x++) {
String str = info.get(x);
if(!str.isEmpty()) {
return str;
}
}
}
return null;
}
}
@@ -0,0 +1,13 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
public void testForLoop(List<String> input) {
List<Integer> result = new ArrayList<>();
for (in<caret>t i = 0; i < 10; i++) {
result.add(input.get(i).length());
}
}
}
@@ -0,0 +1,13 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
public void testForLoop() {
List<Integer> result = new ArrayList<>();
for (in<caret>t i = 0; 10 >= i; i++) {
result.add(i);
}
}
}
@@ -0,0 +1,14 @@
// "Replace with collect" "false"
import java.util.ArrayList;
import java.util.List;
public class Main {
public void testForLoop(List<String> input) {
List<Integer> result = new ArrayList<>();
float s = (float)input.size();
for (in<caret>t i = 0; i < s; i++) {
result.add(input.get(i).length());
}
}
}
@@ -0,0 +1,14 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
public void testForLoop(List<String> input) {
List<Integer> result = new ArrayList<>();
short s = (short)input.size();
for (in<caret>t i = 0; i < s; i++) {
result.add(input.get(i).length());
}
}
}
@@ -0,0 +1,13 @@
// "Replace with collect" "false"
import java.util.ArrayList;
import java.util.List;
public class Main {
public void testForLoop(List<String> input) {
List<Integer> result = new ArrayList<>();
for (in<caret>t i = 0; i < 10; i++) {
result.add(input.get(i++).length());
}
}
}
@@ -0,0 +1,13 @@
// "Replace with collect" "false"
import java.util.ArrayList;
import java.util.List;
public class Main {
public void testForLoop(List<String> input) {
List<Integer> result = new ArrayList<>();
for (in<caret>t i = 0; i > 10; i++) {
result.add(input.get(i).length());
}
}
}
@@ -0,0 +1,13 @@
// "Replace with collect" "false"
import java.util.ArrayList;
import java.util.List;
public class Main {
public void testForLoop(List<String> input) {
List<Integer> result = new ArrayList<>();
for (in<caret>t i = 0; i < 10; i+=2) {
result.add(input.get(i).length());
}
}
}
@@ -0,0 +1,13 @@
// "Replace with collect" "false"
import java.util.ArrayList;
import java.util.List;
public class Main {
public void testForLoop(List<String> input) {
List<Integer> result = new ArrayList<>();
for (in<caret>t i = 0, j=0; i < 10; i++) {
result.add(input.get(i).length());
}
}
}
@@ -1,7 +1,7 @@
// "Replace with forEach" "false"
// "Replace with forEach" "true"
public class Main {
public void test(int[] arr) {
for(int i : arr) {
for(int i : a<caret>rr) {
if(i > 0) {
System.out.println(i);
}
@@ -0,0 +1,10 @@
// "Replace with forEach" "false"
public class Main {
public void test(int[] arr) {
for(float i : a<caret>rr) {
if(i > 0) {
System.out.println(i);
}
}
}
}
@@ -0,0 +1,18 @@
// "Replace with sum()" "false"
import java.util.List;
public class Main {
public long testFor(List<List<String>> list) {
long count = 0;
for (int i = 0; i < list.size(); i++) {
for (String s : list.g<caret>et(i)) {
String trimmed = s.trim();
if (trimmed.isEmpty()) {
count += i;
}
}
}
return count;
}
}