IDEA-167580 Uncompilable code after conversion Stream -> Loop with generics

This commit is contained in:
Tagir Valeev
2017-02-02 22:08:44 +03:00
parent 803b3aa940
commit a767bc9672
3 changed files with 40 additions and 1 deletions

View File

@@ -1,8 +1,12 @@
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import static java.util.stream.Collectors.*;
public class Main {
static Predicate<String> nonEmpty = s -> s != null && !s.isEmpty();
@@ -16,6 +20,24 @@ public class Main {
return count;
}
private Set<Identifier> test(Set<Identifier> identifiers) {
Set<Identifier> set = new HashSet<>();
Predicate<? super Identifier> predicate = isReady(identifiers);
for (Identifier identifier : identifiers) {
if (predicate.test(identifier)) {
set.add(identifier);
}
}
return set;
}
private Predicate<? super Identifier> isReady(Set<Identifier> identifiers) {
return null;
}
private static class Identifier {
}
private static long testStreamOfFunctions(List<Predicate<String>> predicates, List<String> strings) {
long count = 0L;
for (Predicate<String> pred : predicates) {

View File

@@ -1,8 +1,11 @@
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import static java.util.stream.Collectors.*;
public class Main {
static Predicate<String> nonEmpty = s -> s != null && !s.isEmpty();
@@ -10,6 +13,17 @@ public class Main {
return strings.stream().filter(nonEmpty).cou<caret>nt();
}
private Set<Identifier> test(Set<Identifier> identifiers) {
return identifiers.stream().filter(isReady(identifiers)).collect(toSet());
}
private Predicate<? super Identifier> isReady(Set<Identifier> identifiers) {
return null;
}
private static class Identifier {
}
private static long testStreamOfFunctions(List<Predicate<String>> predicates, List<String> strings) {
return predicates.stream().filter(pred -> pred != null)
.flatMap(p -> strings.stream().filter(p)).count();