Aggregator

To accomplish the aggregate functionality desired, the Aggregations class uses a cache of Aggregator objects that perform the actual aggregation calculations. These Aggregator objects are analogous to the Oracle object types that can be created for custom aggregation functions. The Aggregator class itself is an abstract class that does the following:

  1. Defines the interface that the Aggregations class expects.
  2. Acts a Factory for creating Aggregator objects. The static Factory Method “Aggregator.getAggregator” accesses an AggregatorCache.
  3. Calculates an aggregate value based on all values in the original List of Objects that have equivalent “group by” properties.
  4. The Aggregator class 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.
  5. 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.

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 Aggregator 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.