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

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

Introduction

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

Prototype

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

Source Link

Document

Creates an array whose contents will be the element-by-element multiplication of the arguments.

Usage

From source file:org.apache.solr.client.solrj.io.eval.EBEMultiplyEvaluator.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)));
    }//from w ww . ja  va  2  s  . com
    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.ebeMultiply(
            ((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;
}