net.sf.jagg
Class Aggregation.Builder

java.lang.Object
  extended by net.sf.jagg.Aggregation.Builder
Enclosing class:
Aggregation

public static class Aggregation.Builder
extends java.lang.Object

This Builder class follows the "Builder" pattern to create an Aggregation object.


Constructor Summary
Aggregation.Builder()
          Constructs a Builder with no aggregators, no properties, parallelism of 1, and not using multiset discrimination.
 
Method Summary
 Aggregation build()
          Build the Aggregation object.
 Aggregation.Builder setAggregators(java.util.List<Aggregator> aggregators)
          Sets the List of Aggregators to use.
 Aggregation.Builder setCube(java.util.List<java.lang.Integer> cube)
          Sets the set of cube properties to use.
 Aggregation.Builder setGroupingSets(java.util.List<java.util.List<java.lang.Integer>> groupingSets)
          Sets the grouping sets to use.
 Aggregation.Builder setParallelism(int parallelism)
          Sets the degree of parallelism.
 Aggregation.Builder setProperties(java.util.List<java.lang.String> properties)
          Sets the List of properties.
 Aggregation.Builder setRollup(java.util.List<java.lang.Integer> rollup)
          Sets the rollup properties to use.
 Aggregation.Builder setRollups(java.util.List<java.util.List<java.lang.Integer>> rollups)
          Sets multiple sets of rollup properties to use.
 Aggregation.Builder setUseMsd(boolean useMsd)
          Sets whether multiset discrimination is to be used to distinguish sets of objects with shared attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Aggregation.Builder

public Aggregation.Builder()
Constructs a Builder with no aggregators, no properties, parallelism of 1, and not using multiset discrimination.

Method Detail

setAggregators

public Aggregation.Builder setAggregators(java.util.List<Aggregator> aggregators)
Sets the List of Aggregators to use. The Aggregators define which aggregate operatons to perform.

Parameters:
aggregators - A List of Aggregators. Aggregators can be created in two ways: direct instantiation, or by using the factory method.
  • Aggregator agg = new SumAggregator("value");
  • Aggregator agg = Aggregator.getAggregator("Sum(value)");
Returns:
This Builder.
See Also:
Aggregator

setProperties

public Aggregation.Builder setProperties(java.util.List<java.lang.String> properties)
Sets the List of properties. jAgg uses this list of properties to "group by" the different property values. For optional super aggregation, this is the list to which the 0-based indices reference the properties.

Parameters:
properties - The List<String> of properties to "group by". If this call is omitted, then values to be aggregated must be Comparable.
Returns:
This Builder.

setParallelism

public Aggregation.Builder setParallelism(int parallelism)
Sets the degree of parallelism.

Parameters:
parallelism - The degree of parallelism desired; if less than 1, then 1 will be used; if more than 1, then minimum of this number and the number of processors available to the JVM will be used, as determined by Runtime.availableProcessors.
Returns:
This Builder.
See Also:
Runtime.availableProcessors()

setUseMsd

public Aggregation.Builder setUseMsd(boolean useMsd)
Sets whether multiset discrimination is to be used to distinguish sets of objects with shared attributes. If not called, then the Builder defaults to false (use sorting).

Parameters:
useMsd - Whether multiset discrimination is to be used. This is ignored if the objects to be aggregated are being distinguished using the fact that they are Comparable.
Returns:
This Builder.

setGroupingSets

public Aggregation.Builder setGroupingSets(java.util.List<java.util.List<java.lang.Integer>> groupingSets)
Sets the grouping sets to use. Each list contains a list of integer references, ranging from 0 to n - 1, if n is the number of properties already specified through setProperties. If this is not called, then it defaults to one grouping set consisting of all properties, e.g. {{0, 1, ..., n - 1}}.

Parameters:
groupingSets - A List of Lists of integer references. E.g. If there are 3 properties, then the following examples would be valid grouping sets:
  • {{}} Group by no properties. (The empty grouping set produces grand totals.)
  • {{0, 1, 2}} The default: "group by all".
  • {{}, {0}, {1}, {2}, {0, 1}, {0, 2}, {1, 2}, {0, 1, 2}} Create a data cube.
  • {{1, 2}, {0, 1, 2}} Create a rollup on the first (index 0) property.
  • {{1}, {0, 2}, {0, 1, 2}} Other combinations are possible.
Returns:
This Builder.
Throws:
java.lang.IllegalArgumentException - If the "group by" properties have not been set yet; if any index is outside the range from 0 to n -1, where n is the number of "group by" properties; if any index is repeated within the same grouping set; if any grouping set is a duplicate of any other, even if the fields are in a different order.
See Also:
setProperties(java.util.List)

setRollup

public Aggregation.Builder setRollup(java.util.List<java.lang.Integer> rollup)

Sets the rollup properties to use. The list contains a list of integer references, ranging from 0 to n - 1, if n is the number of properties already specified through setProperties. This produces a set of grouping sets that together form a "rollup" of the referenced properties. E.g. setProperties("prop0", "prop1", "prop2", "prop3", "prop4") .setRollup({1, 2, 3}) yields grouping sets {{0, 1, 2, 3, 4}, {0, 1, 2, 4}, {0, 1, 4}, {0, 4}.

This method acts as if all rollup grouping set combinations are found, then they are passed to setGroupingSets.

Parameters:
rollup - A List of integer references. Grouping sets are created that each contain all properties not referenced here, and each individual grouping set contains a different number of referenced properties in order.
Returns:
This Builder.
Throws:
java.lang.IllegalArgumentException - If any index is specified more than once; if any index is out of range from 0 to n -1, where n is the number of "group by" properties.
See Also:
setGroupingSets(java.util.List>), setProperties(java.util.List)

setRollups

public Aggregation.Builder setRollups(java.util.List<java.util.List<java.lang.Integer>> rollups)

Sets multiple sets of rollup properties to use. Each list contains a list of integer references, ranging from 0 to n - 1, if n is the number of properties already specified through setProperties. This produces a set of grouping sets that together form "rollups" of the referenced properties. E.g. setProperties("prop0", "prop1", "prop2", "prop3", "prop4") .setRollups({{0, 1}, {2, 3}) yields grouping sets {{0, 1, 2, 3, 4}, {0, 2, 3, 4}, {0, 1, 2, 4}, {2, 3, 4}, {0, 2, 4}, {0, 1, 4}, {2, 4}, {0, 4}, {4}}. Grouping sets for the first rollup are created, and each grouping set is used to create any subsequent rollups. Notice how a property reference not listed ("4") exists in every grouping set.

This method acts as if all rollup grouping set combinations are found, then they are passed to setGroupingSets.

Parameters:
rollups - A List of integer references. Grouping sets are created that each contain all properties not referenced here, and each individual grouping set contains a different number of referenced properties in order.
Returns:
This Builder.
Throws:
java.lang.IllegalArgumentException - If any index is specified more than once; if any index is out of range from 0 to n -1, where n is the number of "group by" properties.
See Also:
setGroupingSets(java.util.List>), setProperties(java.util.List)

setCube

public Aggregation.Builder setCube(java.util.List<java.lang.Integer> cube)

Sets the set of cube properties to use. The list contains a integer references, ranging from 0 to n - 1, if n is the number of properties already specified through setProperties. This produces a set of grouping sets that together form a "cube" of the referenced properties. E.g. setProperties("prop0", "prop1", "prop2", "prop3", "prop4") .setCube({{0, 1, 3}) yields grouping sets {{0, 1, 2, 3, 4}, {0, 1, 2, 4}, {0, 2, 3, 4}, {1, 2, 3, 4}, {0, 2, 4}, {1, 2, 4}, {2, 3, 4}, {2, 4}}. Notice how all property references not listed ("2, 4") exist in every grouping set.

This method acts as if all cube grouping set combinations are found, then they are passed to setGroupingSets.

Because cube(x, y) is the same as cube(x), cube(y), this method only accepts a simple list, instead of a list of lists.

Parameters:
cube - A List of integer references. Grouping sets are created that each contain all properties not referenced here, and each individual grouping set contains a different number of referenced properties in order.
Returns:
This Builder.
Throws:
java.lang.IllegalArgumentException - If any index is specified more than once; if any index is out of range from 0 to n -1, where n is the number of "group by" properties.
See Also:
setGroupingSets(java.util.List>), setProperties(java.util.List)

build

public Aggregation build()
Build the Aggregation object.

Returns:
An Aggregation object that can be used to perform the actual aggregate calculations.
Throws:
java.lang.IllegalArgumentException - If at least one Aggregator was not supplied with the setAggregators method.
See Also:
setAggregators(java.util.List)


Copyright © 2010-2013 jAgg Team. All Rights Reserved.