net.sf.jagg
Class Aggregations

java.lang.Object
  extended by net.sf.jagg.Aggregations

public class Aggregations
extends java.lang.Object

This class is a utility class that represents an alternate API for some jAgg operations. Before 0.7.0, this class was the sole API. As of 0.7.0, this class no longer represents the complete API. For the operations it does support, it defers to the new API (Aggregation class).

It supports "group by" functionality that allows aggregate functions, or Aggregators, to return aggregate values over a List of Objects.

It can aggregate over Comparable objects or, with a supplied list of properties, any objects. Parallel execution is also avaialable.

To use super-aggregation, e.g. rollups, cubes, or grouping sets, please use the Aggregation class (and its Builder class) directly.

Since:
0.1.0
Author:
Randy Gettman
See Also:
Aggregation, Aggregation.Builder

Method Summary
static
<T extends java.lang.Comparable<? super T>>
java.util.List<AggregateValue<T>>
groupBy(java.util.List<T> values, java.util.List<Aggregator> aggregators)
          Perform one or more aggregate operations on a List<T>.
static
<T extends java.lang.Comparable<? super T>>
java.util.List<AggregateValue<T>>
groupBy(java.util.List<T> values, java.util.List<Aggregator> aggregators, int parallelism)
          Perform one or more aggregate operations on a List<T>.
static
<T> java.util.List<AggregateValue<T>>
groupBy(java.util.List<T> values, java.util.List<java.lang.String> properties, java.util.List<Aggregator> aggregators)
          Perform one or more aggregate operations on a List<T>.
static
<T> java.util.List<AggregateValue<T>>
groupBy(java.util.List<T> values, java.util.List<java.lang.String> properties, java.util.List<Aggregator> aggregators, boolean useMsd)
          Perform one or more aggregate operations on a List<T>.
static
<T> java.util.List<AggregateValue<T>>
groupBy(java.util.List<T> values, java.util.List<java.lang.String> properties, java.util.List<Aggregator> aggregators, int parallelism)
          Perform one or more aggregate operations on a List<T>.
static
<T> java.util.List<AggregateValue<T>>
groupBy(java.util.List<T> values, java.util.List<java.lang.String> properties, java.util.List<Aggregator> aggregators, int parallelism, boolean useMsd)
          Perform one or more aggregate operations on a List<T>.
static
<T> int
indexOfLastMatching(java.util.List<T> list, java.util.Comparator<? super T> comparator, int startIdx)
          In the already sorted list, return the highest index whose item in the list compares equal to the item at the given start index.
static
<T> int
indexOfLastMatching(java.util.List<T> list, java.util.Comparator<? super T> comparator, int startIdx, int maxIdx)
          In the already sorted list, return the highest index whose item in the list compares equal to the item at the given start index, except that no value larger than the maximum index will be returned.
static
<T> java.util.List<AggregateValue<T>>
mergeLists(java.util.List<net.sf.jagg.PositionedAggregatorList<T>> listOfPals, java.util.Comparator<? super T> comparator, boolean useSuperAggregation, java.util.List<java.lang.String> properties)
          Merge Lists of PositionedAggregatorLists, by taking the following structure and merging and terminating any unfinished Aggregators:
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

groupBy

public static <T extends java.lang.Comparable<? super T>> java.util.List<AggregateValue<T>> groupBy(java.util.List<T> values,
                                                                                                    java.util.List<Aggregator> aggregators)
Perform one or more aggregate operations on a List<T>. T should have a "natural ordering", that is, it must be Comparable, and compareTo defines the properties with which to "group by" with its consideration of different properties to determine order.

Type Parameters:
T - The object type to aggregate.
Parameters:
values - The List<T> of objects to aggregate.
aggregators - The List of Aggregators to apply to values.
Returns:
A List<AggregateValue<T>>.
See Also:
Aggregator

groupBy

public static <T extends java.lang.Comparable<? super T>> java.util.List<AggregateValue<T>> groupBy(java.util.List<T> values,
                                                                                                    java.util.List<Aggregator> aggregators,
                                                                                                    int parallelism)
Perform one or more aggregate operations on a List<T>. T should have a "natural ordering", that is, it must be Comparable, and compareTo defines the properties with which to "group by" with its consideration of different properties to determine order. This version accepts an integer argument corresponding to the parallelization desired.

Type Parameters:
T - The object type to aggregate.
Parameters:
values - The List<T> of objects to aggregate.
aggregators - The List of Aggregators to apply to values.
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:
A List<AggregateValue<T>>.
See Also:
Aggregator, Runtime.availableProcessors()

groupBy

public static <T> java.util.List<AggregateValue<T>> groupBy(java.util.List<T> values,
                                                            java.util.List<java.lang.String> properties,
                                                            java.util.List<Aggregator> aggregators)
Perform one or more aggregate operations on a List<T>. T does not need to be Comparable. The given properties list defines the properties with which to "group by". This method sorts a copy of the list based on the list of properties.

Type Parameters:
T - The object type to aggregate.
Parameters:
values - The List<T> of objects to aggregate.
properties - The List<String> of properties to "group by".
aggregators - The List of Aggregators to apply to values.
Returns:
A List<AggregateValue<T>>
See Also:
Aggregator

groupBy

public static <T> java.util.List<AggregateValue<T>> groupBy(java.util.List<T> values,
                                                            java.util.List<java.lang.String> properties,
                                                            java.util.List<Aggregator> aggregators,
                                                            boolean useMsd)
Perform one or more aggregate operations on a List<T>. T does not need to be Comparable. The given properties list defines the properties with which to "group by". This method allows a choice to use multiset discrimination to group the elements.

Type Parameters:
T - The object type to aggregate.
Parameters:
values - The List<T> of objects to aggregate.
properties - The List<String> of properties to "group by".
aggregators - The List of Aggregators to apply to values.
useMsd - true to use multiset discrimination, false to only use sorting. If multiset discrimination fails, then this method falls back on sorting.
Returns:
A List<AggregateValue<T>>
Since:
0.5.0
See Also:
Aggregator

groupBy

public static <T> java.util.List<AggregateValue<T>> groupBy(java.util.List<T> values,
                                                            java.util.List<java.lang.String> properties,
                                                            java.util.List<Aggregator> aggregators,
                                                            int parallelism)
Perform one or more aggregate operations on a List<T>. T does not need to be Comparable. The given properties list defines the properties with which to "group by". This version accepts an integer argument corresponding to the parallelization desired. This method sorts a copy of the list based on the list of properties.

Type Parameters:
T - The object type to aggregate.
Parameters:
values - The List<T> of objects to aggregate.
properties - The List<String> of properties to "group by".
aggregators - The List of Aggregators to apply to values.
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:
A List<AggregateValue<T>>
See Also:
Aggregator, Runtime.availableProcessors()

groupBy

public static <T> java.util.List<AggregateValue<T>> groupBy(java.util.List<T> values,
                                                            java.util.List<java.lang.String> properties,
                                                            java.util.List<Aggregator> aggregators,
                                                            int parallelism,
                                                            boolean useMsd)
Perform one or more aggregate operations on a List<T>. T does not need to be Comparable. The given properties list defines the properties with which to "group by". This version accepts an integer argument corresponding to the parallelization desired. This method allows a choice to use multiset discrimination to group the elements.

Type Parameters:
T - The object type to aggregate.
Parameters:
values - The List<T> of objects to aggregate.
properties - The List<String> of properties to "group by".
aggregators - The List of Aggregators to apply to values.
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.
useMsd - true to use multiset discrimination, false to only use sorting. If multiset discrimination fails, then this method falls back on sorting.
Returns:
A List<AggregateValue<T>>
Since:
0.5.0
See Also:
Aggregator, Runtime.availableProcessors()

mergeLists

public static <T> java.util.List<AggregateValue<T>> mergeLists(java.util.List<net.sf.jagg.PositionedAggregatorList<T>> listOfPals,
                                                               java.util.Comparator<? super T> comparator,
                                                               boolean useSuperAggregation,
                                                               java.util.List<java.lang.String> properties)

Merge Lists of PositionedAggregatorLists, by taking the following structure and merging and terminating any unfinished Aggregators:

listOfPals[0] {initObject: T, initAggregators: List<Aggregator>, midAggValues: List<AggregateValue<T>>, endingObject: T, endingAggregators; List<Aggregator>} listOfPals[1] {initObject: T, initAggregators: List<Aggregator>, midAggValues: List<AggregateValue<T>>, endingObject: T, endingAggregators; List<Aggregator>} ... listOfPals[n - 1] {initObject: T, initAggregators: List<Aggregator>, midAggValues: List<AggregateValue<T>>, endingObject: T, endingAggregators; List<Aggregator>}

Above, this will terminate all Aggregators in the initial list of the first PositionedAggregatorLists and create the first AggregateValue. Then it will include all middle AggregateValues, which have already been calculated. On the borders between PositionedAggregatorLists, it will determine if the ending object of one is equal to the initial object of the next. If so, it will merge the Aggregators before creating one AggregateValue, else it will create separate AggregateValues. It will determine if the same object is represented in multiple PositionedAggregatorLists, and merge them all together. Finally, it will terminate all Aggregators in the ending list of the last PositionedAggregatorLists and create the last AggregateValue.

If super-aggregation will occur, then this will store the associated List of Aggregators with each completed AggregateValue.

Parameters:
listOfPals - A List of PositionedAggregatorLists.
comparator - A Comparator of T values.
useSuperAggregation - If true, store the list of aggregators with each AggregateValue, instead of setting them as not used.
properties - The List of properties.
Returns:
A merged List (of one item) of Lists of Aggregators.

indexOfLastMatching

public static <T> int indexOfLastMatching(java.util.List<T> list,
                                          java.util.Comparator<? super T> comparator,
                                          int startIdx)
In the already sorted list, return the highest index whose item in the list compares equal to the item at the given start index.

Type Parameters:
T - The type of objects in the List of values.
Parameters:
list - The List of values.
comparator - Decides how to compare values for equality.
startIdx - Start looking for the last match at this index.
Returns:
The index that represents the last object in the given List that compares equal to the object represented by the start index.

indexOfLastMatching

public static <T> int indexOfLastMatching(java.util.List<T> list,
                                          java.util.Comparator<? super T> comparator,
                                          int startIdx,
                                          int maxIdx)
In the already sorted list, return the highest index whose item in the list compares equal to the item at the given start index, except that no value larger than the maximum index will be returned.

Type Parameters:
T - The type of objects in the List of values.
Parameters:
list - The List of values.
comparator - Decides how to compare values for equality.
startIdx - Start looking for the last match at this index.
maxIdx - Don't look past this index.
Returns:
The lesser of the index that represents the last object in the given List that compares equal to the object represented by the start index, and maxIdx.


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