diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-01-17 21:59:41 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-01-17 22:08:42 +0100 |
commit | 88495645019196f2d71e38b82f6ef71e6f2a81bb (patch) | |
tree | 14b9fd8a0fc01d6b89a1f99091a511e144f5f1d6 /predicate-search-core | |
parent | 6c4c57469342d4d28bdebef9e38d45ec8281c99c (diff) |
Unify on Streams.toList()
Diffstat (limited to 'predicate-search-core')
-rw-r--r-- | predicate-search-core/src/main/java/com/yahoo/search/predicate/optimization/OrSimplifier.java | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/predicate-search-core/src/main/java/com/yahoo/search/predicate/optimization/OrSimplifier.java b/predicate-search-core/src/main/java/com/yahoo/search/predicate/optimization/OrSimplifier.java index 0215ed63d73..a261c6696b7 100644 --- a/predicate-search-core/src/main/java/com/yahoo/search/predicate/optimization/OrSimplifier.java +++ b/predicate-search-core/src/main/java/com/yahoo/search/predicate/optimization/OrSimplifier.java @@ -7,12 +7,13 @@ import com.yahoo.document.predicate.FeatureSet; import com.yahoo.document.predicate.Negation; import com.yahoo.document.predicate.Predicate; +import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; import static java.util.stream.Collectors.groupingBy; import static java.util.stream.Collectors.reducing; -import static java.util.stream.Collectors.toList; /** * Simplifies Disjunction nodes where all children are of type FeatureSet. All FeatureSet that share the same key @@ -28,19 +29,16 @@ public class OrSimplifier implements PredicateProcessor { } public Predicate simplifyTree(Predicate predicate) { - if (predicate instanceof Disjunction) { - Disjunction disjunction = (Disjunction) predicate; + if (predicate instanceof Disjunction disjunction) { List<Predicate> newChildren = - disjunction.getOperands().stream().map(this::simplifyTree).collect(toList()); + disjunction.getOperands().stream().map(this::simplifyTree).toList(); return compressFeatureSets(newChildren); - } else if (predicate instanceof Negation) { - Negation negation = (Negation) predicate; + } else if (predicate instanceof Negation negation) { negation.setOperand(simplifyTree(negation.getOperand())); return negation; - } else if (predicate instanceof Conjunction) { - Conjunction conjunction = (Conjunction) predicate; + } else if (predicate instanceof Conjunction conjunction) { List<Predicate> newChildren = - conjunction.getOperands().stream().map(this::simplifyTree).collect(toList()); + conjunction.getOperands().stream().map(this::simplifyTree).toList(); conjunction.setOperands(newChildren); return conjunction; } else { @@ -50,7 +48,7 @@ public class OrSimplifier implements PredicateProcessor { // Groups and merges the feature sets based on key. private static Predicate compressFeatureSets(List<Predicate> children) { - List<Predicate> newChildren = children.stream().filter(p -> !(p instanceof FeatureSet)).collect(toList()); + List<Predicate> newChildren = children.stream().filter(p -> !(p instanceof FeatureSet)).collect(Collectors.toCollection(ArrayList::new)); children.stream() .filter(FeatureSet.class::isInstance) .map(FeatureSet.class::cast) |