# The Java Embedded Aggregator Classes MaxAggregate and MinAggregate

MaxAggregate implements the maximum aggregation, and MinAggregate implements the minimum aggregation.

### For an overview see page Java Aggregator Class

### Class Definition

        public static class MaxAggregate implements Aggregate<Comparable>
        {
            public void initialize(Comparable val)
            {
                max = val;
            }

            public void accumulate(Comparable val)
            {
                if (val.compareTo(max) > 0)
                {
                    max = val;
                }
            }

            public Object result()
            {
                return max;
            }

            public void merge(Aggregate<Comparable> other)
            {
                accumulate((Comparable)other.result());
            }

            Comparable max;

        }

## MinAggregate

The MinAggregate implementation is exactly identical to that of MaxAggregate below, except that the variable name is `min` instead of `max` (highlighted below) and the `compareTo()` expression is

        if (val.compareTo(min) < 0)

instead of

        if (val.compareTo(max) > 0)