public Double evaluate()

in core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMedianValueAggregatorFunction.java [92:116]


    public Double evaluate(List<Double> data) {
        if (data == null || data.size() == 0) {
            return null;
        }
        // if only one element in it, it is the mean
        if (data.size() == 1) {
            return data.get(0);
        }
        List<Double> copy = data;
        if (useCopy) {
            copy = new ArrayList<Double>(data);
        }
        Collections.sort(copy);
        int n = copy.size();
        int middle = n / 2;
        if (n % 2 == 0) {
            // need to compute the mean of middle and middle-1 (zero based
            // index!)
            return (copy.get(middle) + copy.get(middle - 1)) / 2;
        }

        // we're already positioned on the element in the middle so just return
        // it
        return copy.get(middle);
    }