IDEA-165063 Stream API migration: support simple limit conversions

This commit is contained in:
Tagir Valeev
2016-12-20 16:31:57 +07:00
parent b9b2151f24
commit a15916ae24
14 changed files with 355 additions and 38 deletions
@@ -0,0 +1,17 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class Main {
private List<String> test(String[] list, int limit) {
List<String> result;
List<String> other = new ArrayList<>();
System.out.println("hello");
result = Arrays.stream(list).filter(Objects::nonNull).limit(limit).map(s -> s + s).sorted().collect(Collectors.toList());
return result;
}
}
@@ -0,0 +1,10 @@
// "Replace with count()" "true"
import java.util.Arrays;
public class Main {
public long test(String[] array) {
long longStrings = Arrays.stream(array).map(String::trim).filter(trimmed -> trimmed.length() > 10).limit(100).count();
return longStrings;
}
}
@@ -0,0 +1,10 @@
// "Replace with count()" "true"
import java.util.Arrays;
public class Main {
public long test(String[] array, long limit) {
long longStrings = Arrays.stream(array).map(String::trim).filter(trimmed -> trimmed.length() > 10).limit(limit + 1).count();
return longStrings;
}
}
@@ -0,0 +1,10 @@
// "Replace with count()" "true"
import java.util.Arrays;
public class Main {
public long test(String[] array) {
long longStrings = Arrays.stream(array).map(String::trim).filter(trimmed -> trimmed.length() > 10).limit(100).count();
return longStrings;
}
}
@@ -0,0 +1,24 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
private List<String> test(String[] list, int limit) {
List<String> result = new ArrayList<>();
List<String> other = new ArrayList<>();
System.out.println("hello");
for(String s : li<caret>st) {
if (s == null) {
continue;
}
result.add(s+s);
if(result.size() != limit) {
continue;
}
break;
}
result.sort(null);
return result;
}
}
@@ -0,0 +1,23 @@
// "Replace with collect" "false"
import java.util.*;
public class Main {
private Set<String> test(String[] list, int limit) {
Set<String> result = new HashSet<>();
List<String> other = new ArrayList<>();
System.out.println("hello");
for(String s : li<caret>st) {
if (s == null) {
continue;
}
result.add(s+s);
if(result.size() != limit) {
continue;
}
break;
}
result.sort(null);
return result;
}
}
@@ -0,0 +1,24 @@
// "Replace with collect" "false"
import java.util.ArrayList;
import java.util.List;
public class Main {
private List<String> test(String[] list, int limit) {
List<String> result = new ArrayList<>();
List<String> other = new ArrayList<>();
System.out.println("hello");
for(String s : li<caret>st) {
if (s == null) {
continue;
}
result.add(s+s);
if(other.size() != limit) {
continue;
}
break;
}
result.sort(null);
return result;
}
}
@@ -0,0 +1,15 @@
// "Replace with count()" "true"
public class Main {
public long test(String[] array) {
long longStrings = 0;
for(String str : a<caret>rray) {
String trimmed = str.trim();
if(trimmed.length() > 10) {
longStrings = longStrings + 1;
if(longStrings >= 100) break;
}
}
return longStrings;
}
}
@@ -0,0 +1,17 @@
// "Replace with count()" "true"
public class Main {
public long test(String[] array, long limit) {
long longStrings = 0;
for(String str : a<caret>rray) {
String trimmed = str.trim();
if(trimmed.length() > 10) {
longStrings++;
if(longStrings > limit) {
break;
}
}
}
return longStrings;
}
}
@@ -0,0 +1,15 @@
// "Replace with count()" "true"
public class Main {
public long test(String[] array) {
long longStrings = 0;
for(String str : a<caret>rray) {
String trimmed = str.trim();
if(trimmed.length() > 10) {
if(100 > ++longStrings) continue;
break;
}
}
return longStrings;
}
}
@@ -0,0 +1,15 @@
// "Replace with count()" "false"
public class Main {
public long test(String[] array) {
long longStrings = 0;
for(String str : a<caret>rray) {
String trimmed = str.trim();
if(trimmed.length() > 10) {
longStrings = longStrings + 1;
if(longStrings >= trimmed.length()) break;
}
}
return longStrings;
}
}