# The Java Embedded Aggregator Classes RealSumAggregate and IntegerSumAggregate

RealSumAggregate implements the sum aggregation for real numbers (as `double` precision values) and IntegerSumAggregate implements the sum aggregation for integers (as `longs`).

### For an overview see page Java Aggregator Class

### Class Definitions

Sum aggregate for real values

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

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

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

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

            double sum;
        }

## IntegerSumAggregate

Sum aggregate for integer values:

        public static class IntegerSumAggregate implements Aggregate<Number>
        {
            public void initialize(Number val)
            {
                sum = val.longValue();
            }

            public void accumulate(Number val)
            {
                sum += val.longValue();
            }

            public Object result()
            {
                return new Long(sum);
            }

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

            long sum;
        }