List of usage examples for org.apache.commons.math3.stat StatUtils sumDifference
public static double sumDifference(final double[] sample1, final double[] sample2) throws DimensionMismatchException, NoDataException
From source file:org.apache.solr.client.solrj.io.eval.SumDifferenceEvaluator.java
@Override public Object doWork(Object first, Object second) throws IOException { if (null == first) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - null found for the first value", toExpression(constructingFactory))); }/* w w w . j av a2 s . c o m*/ if (null == second) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - null found for the second value", toExpression(constructingFactory))); } if (!(first instanceof List<?>)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the first value, expecting a list of numbers", toExpression(constructingFactory), first.getClass().getSimpleName())); } if (!(second instanceof List<?>)) { 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())); } return StatUtils.sumDifference( ((List) first).stream().mapToDouble(value -> ((BigDecimal) value).doubleValue()).toArray(), ((List) second).stream().mapToDouble(value -> ((BigDecimal) value).doubleValue()).toArray()); }