To accomplish the aggregate functionality desired, the abstract Aggregator class implements the AggregateFunction interface, supplying functionality for such methods that are common to all aggregate functions. The Aggregator class does the following:

  1. Implements the setInUse, isInUse methods from the AggregateFunction interface.
  2. Acts a Factory for creating Aggregator objects. The static Factory Method “Aggregator.getAggregator” accesses an AggregatorCache.
  3. Uses a MethodCache that uses reflection to find and cache Method objects so that subclasses may access the object’s desired properties for the purposes of the aggregation calculation.
  4. Defines equals and hashCode so that it may be the key to a HashMap stored internally in the AggregateValue class, which stores the actual aggregate values.
  5. Leaves init, iterate, merge, and terminate undefined, so that subclasses may implement them.
  6. Defines a terminateDoubleDouble method that returns a DoubleDouble. The usage of this method is described below.

Subclasses of Aggregator implement the abstract methods init, iterate, merge, and terminate that do the actual aggregation. They also implement the abstract method replicate to return a new Aggregator of the same type, but un-initialized.

Additionally, subclasses of Aggregator may use other Aggregators internally to facilitate calculations. These would typically need to create a numeric result precisely. Optionally, some Aggregators override the terminateDoubleDouble method. This allows an Aggregator subclass to be used internally by other Aggregators, to maintain a high level of precision during internal calculations.

Factory Method

The Aggregator class defines a static Factory Method called getAggregator that takes as its only argument an aggregator specification string, in the format "aggname(property)", where "aggname" is name of the AggregateFunction class, minus the suffix "Aggregator", and "property" is the property string normally sent to the Aggregator's constructor. This factory method is an alternative to directly instantiating Aggregators in code. It may return an existing, unused Aggregator that is already in the internal cache. Such a cached Aggregator would be the desired type and have the same property to process.