Entry Point
The "Aggregation" class is the entry point for a developer attempting to present a
view of aggregate data in an application. It defines a static nested class "Builder"
that follows the Builder Pattern. This Builder class builds an
Aggregation object that can be used to perform aggregate operations.
Builder Class
The "Builder" class builds Aggregation objects. It has many methods
that can be used to control how the resultant Aggregation object behaves.
- setAggregators(List<AnalyticFunction> aggregators) - This method
is required, or build() will throw an Exception. This method
supplies all AggregateFunctions to be used in
the aggregation operation. Create Aggregators by instantiating them directly,
or by using the Aggregator class's factory method for creating
them using aggregator specification strings:
- Aggregator agg1 = new SumAggregator("qty");
- Aggregator agg2 = Aggregator.getAggregator("Avg(qty)");
- setProperties(List<String> properties) - This method is
optional. It is used to supply a list of "group by" properties that will be
used to calculate multiple aggregate results. If this method is not called,
then the only way that the resultant Aggregation object can be used is with its
"groupByComparable" method, which differentiates Comparable
objects according to their compare methods. To specify not to use
any properties at all, supply an empty List here and then call "groupBy" on the
resultant Aggregation object.
- setParallelism(int parallelism) - This method is optional. It is
used to specify a desired degree of parallelism to be used during the
calculation of aggregate results. jAgg will not use more Threads than there
are CPUs available on the machine. If not called, then jAgg defaults to 1 (no
parallelism).
- setUseMsd(boolean useMsd) - This method is optional. Normally,
jAgg sorts a copy of the supplied object values list, to "line up" all objects
with equivalent properties. An alternative method is to use
Multiset Discrimination to get object values to
"line up" with equivalent properties. Multiset discrimination is generally
faster than sorting, but the results will not be in sorted order. This
defaults to false (don't use Multiset Discrimination, just use
sorting) when not called.
- setRollup(List<Integer> rollup) - This method is optional.
When this is called, jAgg will perform
rollup super-aggregation on the properties
specified by the integer contents of the list. These integer references are
0-based indexes into the original list of properties specified through
setProperties.
- setRollups(List<List<Integer>> rollups) - This method
is optional. When this is called, jAgg will perform multiple
rollup super-aggregation operations on the
sets of rollups specified. Each supplied list is a separate rollup
specification, each containing 0-based indexes into the original list of
properties specified through setProperties.
- setCube(List<Integer> cube) - This method is optional. When
this is called, jAgg will perform cube
super-aggregation on the properties specified by the integer contents of the
list. These integer references are 0-based indexes into the original list of
properties specified through setProperties.
- setGroupingSets(List<List<Integer>> groupingSets) -
This method is optional. When this is called, jAgg will perform all
super-aggregate operations specified with the given grouping sets, and no more.
Each sub-list specifies a separate grouping set, and it contains 0-based
indexes into the original list of properties specified through
setProperties.
- build() - This method builds an Aggregation object
that can be used to perform the actual aggregate operations. This method
should be called last, after all of the desired "setter" methods above have
been called.
Each setter method above returns the same Builder object, so that calls may be
chained, e.g.
Aggregation agg = new Aggregation.Builder().setAggregators(aggList).setProperties(propsList).build();
Aggregation Class
The "Aggregation" object is responsible for performing all aggregate operations. It
has two methods that perform the actual aggregate operations.
- <T extends Comparable<? super T>> groupByComparable(List<T> values)
- When the Builder did NOT supply a List of properties, then this method is the
only possible method to call. The Aggregation object "lines up" all objects
using Collections.sort, relying on the fact that all of the value
objects are Comparable.
- <T> groupBy(List<T> values) - If a list of properties
was supplied, then this method can be called. Here, the values objects need
not be Comparable. The Aggregation object "lines up" all objects
using the Collections.sort overloading that takes a
Comparator. jAgg supplies its own
PropertiesComparator, which compares the value objects based on
the list of properties. Alternatively, Multiset Discrimination can be used to
accomplish this task.
Both methods return a List of
AggregateValues, which contain the completed
aggregate results.