# The Java Embedded Aggregator Class AvgAggregate

AvgAggregate implements the average aggregation.

### For an overview see page Java Aggregator Class

### Class Definition

        public static class AvgAggregate implements Aggregate<Number>
        {
            public void initialize(Number val)
            {
                sum = val.doubleValue();
                count = 1;
            }

            public void accumulate(Number val)
            {
                sum += val.doubleValue();
                count += 1;
            }

            public Object result()
            {
                return new Double(sum/count);
            }

            public void merge(Aggregate<Number> other)
            {
                AvgAggregate otherAvg = (AvgAggregate)other;
                sum += otherAvg.sum;
                count += otherAvg.count;
            }

            double sum;
            long count;
        }