Code changes and CHANGES.txt editted.

The majority of the code seems to already be using anyMatch and noneMatch logic, these few remaining instances were using count() and comparing the result to 0.
This changes everything to anyMatch and noneMatch, which is also potentially more performant.

Extra newline.
This commit is contained in:
KoenDG 2019-06-13 02:05:59 +02:00
parent a9607b2a88
commit e2a285b6df
4 changed files with 8 additions and 6 deletions

View File

@ -69,6 +69,8 @@ Other Changes
* SOLR-13655:Upgrade Collections.unModifiableSet to Set.of and Set.copyOf (Atri Sharma via Tomás Fernández Löbbe) * SOLR-13655:Upgrade Collections.unModifiableSet to Set.of and Set.copyOf (Atri Sharma via Tomás Fernández Löbbe)
* SOLR-13542: Code cleanup - Avoid using stream filter count where possible
================== 8.3.0 ================== ================== 8.3.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release. Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

View File

@ -53,7 +53,7 @@ public class ColumnEvaluator extends RecursiveEvaluator {
Object firstLevel = containedEvaluators.get(0).evaluate(tuple); Object firstLevel = containedEvaluators.get(0).evaluate(tuple);
if(!(firstLevel instanceof List<?>) || 0 != ((List<?>)firstLevel).stream().filter(value -> !(value instanceof Tuple)).count()){ if(!(firstLevel instanceof List<?>) || ((List<?>) firstLevel).stream().anyMatch(value -> !(value instanceof Tuple))){
throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - expecting a list of tuples but found %s", toExpression(constructingFactory), firstLevel.getClass().getSimpleName())); throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - expecting a list of tuples but found %s", toExpression(constructingFactory), firstLevel.getClass().getSimpleName()));
} }

View File

@ -43,7 +43,7 @@ public class ConversionEvaluator extends RecursiveNumericEvaluator implements On
throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - expecting exactly 3 parameters but found %d", super.toExpression(constructingFactory), containedEvaluators.size())); throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - expecting exactly 3 parameters but found %d", super.toExpression(constructingFactory), containedEvaluators.size()));
} }
if(0 != containedEvaluators.subList(0, 2).stream().filter(item -> !(item instanceof RawValueEvaluator) && !(item instanceof FieldValueEvaluator)).count()){ if(containedEvaluators.subList(0, 2).stream().anyMatch(item -> !(item instanceof RawValueEvaluator) && !(item instanceof FieldValueEvaluator))){
throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - first two parameters must be strings", super.toExpression(constructingFactory))); throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - first two parameters must be strings", super.toExpression(constructingFactory)));
} }

View File

@ -38,13 +38,13 @@ public class KolmogorovSmirnovEvaluator extends RecursiveObjectEvaluator impleme
@Override @Override
public Object doWork(Object first, Object second) throws IOException{ public Object doWork(Object first, Object second) throws IOException{
if(null == first || (first instanceof List<?> && 0 != ((List<?>)first).stream().filter(item -> null == item).count())){ if(null == first || (first instanceof List<?> && ((List<?>) first).stream().anyMatch(item -> null == item))){
throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the first value",toExpression(constructingFactory))); throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the first value",toExpression(constructingFactory)));
} }
if(null == second || (second instanceof List<?> && 0 != ((List<?>)second).stream().filter(item -> null == item).count())){ if(null == second || (second instanceof List<?> && ((List<?>) second).stream().anyMatch(item -> null == item))){
throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the second value",toExpression(constructingFactory))); throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the second value",toExpression(constructingFactory)));
} }
if(!(second instanceof List<?>) || 0 != ((List<?>)second).stream().filter(item -> !(item instanceof Number)).count()){ if(!(second instanceof List<?>) || ((List<?>) second).stream().anyMatch(item -> !(item instanceof Number))){
throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - found type %s for the second value, expecting a List of numbers",toExpression(constructingFactory), first.getClass().getSimpleName())); throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - found type %s for the second value, expecting a List of numbers",toExpression(constructingFactory), first.getClass().getSimpleName()));
} }
@ -59,7 +59,7 @@ public class KolmogorovSmirnovEvaluator extends RecursiveObjectEvaluator impleme
m.put("d-statistic", ks.kolmogorovSmirnovStatistic(realDistribution, data)); m.put("d-statistic", ks.kolmogorovSmirnovStatistic(realDistribution, data));
return new Tuple(m); return new Tuple(m);
} }
else if(first instanceof List<?> && 0 == ((List<?>)first).stream().filter(item -> !(item instanceof Number)).count()){ else if(first instanceof List<?> && ((List<?>) first).stream().noneMatch(item -> !(item instanceof Number))){
double[] data2 = ((List<?>)first).stream().mapToDouble(item -> ((Number)item).doubleValue()).toArray(); double[] data2 = ((List<?>)first).stream().mapToDouble(item -> ((Number)item).doubleValue()).toArray();
Map<String,Double> m = new HashMap<>(); Map<String,Double> m = new HashMap<>();