/*
 * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
 * Haulmont Technology proprietary and confidential.
 * Use is subject to license terms.

 * Author: Nikolay Gorodnov
 * Created: 25.02.2010 23:03:55
 *
 * $Id$
 */
package com.haulmont.cuba.gui.aggregation;

import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.lang.ArrayUtils;

import java.util.Set;
import java.util.HashSet;

public class NumberAggregationHelper {
    private final Set<Double> items;

    public NumberAggregationHelper() {
        items = new HashSet<Double>();
    }

    public void addItem(Double newItem) {
        items.add(newItem);
    }

    public Double sum() {
        double sum = 0d;
        for (final Double item : items) {
            if (item != null) {
                sum += item;
            }
        }
        return sum;
    }

    public Double avg() {
        return sum () / items.size();
    }

    public Double min() {
        return NumberUtils.min(ArrayUtils.toPrimitive(items.toArray(new Double[items.size()])));
    }

    public Double max() {
        return NumberUtils.max(ArrayUtils.toPrimitive(items.toArray(new Double[items.size()])));
    }
}

@@ -430,16 +430,69 @@
 ashSet;%0D
+%0Aimport java.util.List;%0D%0Aimport java.util.ArrayList;%0D
 %0A%0D%0Apubli
@@ -544,18 +544,19 @@
 e final 
-Se
+Lis
 t%3CDouble
@@ -627,22 +627,24 @@
 s = new 
-HashSe
+ArrayLis
 t%3CDouble

change set to list