Example usage for org.apache.commons.math3.util MathArrays ebeDivide

List of usage examples for org.apache.commons.math3.util MathArrays ebeDivide

Introduction

In this page you can find the example usage for org.apache.commons.math3.util MathArrays ebeDivide.

Prototype

public static double[] ebeDivide(double[] a, double[] b) 

Source Link

Document

Creates an array whose contents will be the element-by-element division of the first argument by the second.

Usage

From source file:org.apache.solr.client.solrj.io.eval.EBEDivideEvaluator.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  ww. j  a v a2  s . c om
    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()));
    }

    double[] result = MathArrays.ebeDivide(
            ((List) first).stream().mapToDouble(value -> ((BigDecimal) value).doubleValue()).toArray(),
            ((List) second).stream().mapToDouble(value -> ((BigDecimal) value).doubleValue()).toArray());

    List<Number> numbers = new ArrayList();
    for (double d : result) {
        numbers.add(d);
    }

    return numbers;
}