IDEA-160784 Migration to Stream API: replace with Stream.count() when possible

This commit is contained in:
Tagir Valeev
2016-09-05 17:47:41 +07:00
parent 0263b52b9f
commit e72f6656f8
7 changed files with 199 additions and 13 deletions
@@ -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).count();
return longStrings;
}
}
@@ -0,0 +1,14 @@
// "Replace with count()" "true"
import java.util.List;
import java.util.Set;
public class Main {
public void test(List<Set<String>> nested) {
int count = 0;
for(Set<String> element : nested) {
if(element != null) {
count += element.stream().filter(str -> str.startsWith("xyz")).count();
}
}
}
}
@@ -0,0 +1,10 @@
// "Replace with count()" "true"
import java.util.Collection;
import java.util.List;
import java.util.Set;
public class Main {
public void test(List<Set<String>> nested) {
int count = (int) nested.stream().filter(element -> element != null).flatMap(Collection::stream).filter(str -> str.startsWith("xyz")).count();
}
}
@@ -0,0 +1,14 @@
// "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++;
}
}
return longStrings;
}
}
@@ -0,0 +1,18 @@
// "Replace with count()" "true"
import java.util.List;
import java.util.Set;
public class Main {
public void test(List<Set<String>> nested) {
int count = 0;
for(Set<String> element : nested) {
if(element != null) {
for(String str : eleme<caret>nt) {
if(str.startsWith("xyz")) {
count++;
}
}
}
}
}
}
@@ -0,0 +1,18 @@
// "Replace with count()" "true"
import java.util.List;
import java.util.Set;
public class Main {
public void test(List<Set<String>> nested) {
int count = 0;
for(Set<String> element : neste<caret>d) {
if(element != null) {
for(String str : element) {
if(str.startsWith("xyz")) {
count++;
}
}
}
}
}
}