net.sf.jagg
Class AggregateValue<T>

java.lang.Object
  extended by net.sf.jagg.AggregateValue<T>

public class AggregateValue<T>
extends java.lang.Object

This class represents the result of a "group by" operation, where certain fields of a type are selected for a "group by", and certain values can be extracted by referring to Aggregators.

Since:
0.1.0
Author:
Randy Gettman

Constructor Summary
AggregateValue(AggregateValue<T> other)
          Create an AggregateValue using another AggregateValue.
AggregateValue(T object)
          Create an AggregateValue that wraps the given object.
 
Method Summary
 java.lang.Object getAggregateValue(Aggregator agg)
          Retrieves the value for the given Aggregator.
 java.lang.Object getAggregateValue(int index)
          Retrieves the value for the Aggregator at the given index.
 int getGroupingId(java.util.List<?> fields)
          Determines the distinct grouping ID of the given referenced fields by determining whether each given referenced field represents "all values" in super-aggregation.
 T getObject()
          Retrieves the T representing the "group-by" aggregation.
 java.lang.Object getPropertyValue(int propIndex)
          Retrieves a property value representing a "group-by" category, with the property specified by a 0-based index into the original list of properties that was specified in Builder.getProperties.
 java.lang.Object getPropertyValue(java.lang.String property)
          Retrieves a property value representing a "group-by" category by name.
 boolean isGrouping(int field)
          Determines whether the referenced field represents the set of all values in a super-aggregate value.
 boolean isGrouping(java.lang.String propertyName)
          Determines whether the referenced field represents the set of all values in a super-aggregate value.
 void setAggregateValue(Aggregator agg, java.lang.Object value)
          This method is used internally to store the given value associated with the given Aggregator for later retrieval.
 java.lang.String toString()
          Returns the string representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AggregateValue

public AggregateValue(T object)
Create an AggregateValue that wraps the given object. It will also store aggregation values.

Parameters:
object - The object for which this AggregateValue will wrap.

AggregateValue

public AggregateValue(AggregateValue<T> other)
Create an AggregateValue using another AggregateValue. This will wrap the same object that the other AggregateValue wraps.

Parameters:
other - Another AggregateValue.
Since:
0.7.0
Method Detail

getObject

public T getObject()

Retrieves the T representing the "group-by" aggregation. This method is used to directly access the property values, when aggregating by calling Aggregation.groupByComparable.

If Aggregation.groupBy is called instead, then this method will still succeed. However, if super-aggregation is used (cube, rollups, grouping sets), the object returned here will not indicate that this AggregateValue represents "all values" for a certain property. In this case, either of the two overloaded getPropertyValue methods will correctly return the null value if that property represents "all values".

Returns:
The T object representing the "group-by" aggregation.
See Also:
Aggregation.groupByComparable(java.util.List), getPropertyValue(String), getPropertyValue(int)

getPropertyValue

public java.lang.Object getPropertyValue(java.lang.String property)

Retrieves a property value representing a "group-by" category by name. This method is used to access the property values, when aggregating by calling Aggregation.groupBy after specifying "group-by" properties. Because super-aggregation is possible in this case, if the referenced property represents "all values", then this method will return null instead of the actual property value.

Parameters:
property - The property name.
Returns:
The property value.
Since:
0.7.0
See Also:
Aggregation.groupBy(java.util.List)

getPropertyValue

public java.lang.Object getPropertyValue(int propIndex)

Retrieves a property value representing a "group-by" category, with the property specified by a 0-based index into the original list of properties that was specified in Builder.getProperties.

If Aggregation.groupByComparable was called, then there are no "group-by" properties, so this method would return null.

Parameters:
propIndex - The 0-based index into the list of properties.
Returns:
The property value.
Since:
0.7.0

setAggregateValue

public void setAggregateValue(Aggregator agg,
                              java.lang.Object value)
This method is used internally to store the given value associated with the given Aggregator for later retrieval. It also appends the given value to an internal list for later retrieval by index.

Parameters:
agg - An Aggregator.
value - The aggregated value.
See Also:
Aggregator

getAggregateValue

public java.lang.Object getAggregateValue(Aggregator agg)
Retrieves the value for the given Aggregator.

Parameters:
agg - An Aggregator.
Returns:
The aggregated value, or null if no such Aggregator is found.

getAggregateValue

public java.lang.Object getAggregateValue(int index)
Retrieves the value for the Aggregator at the given index.

Parameters:
index - The 0-based index.
Returns:
The aggregated value.
Throws:
java.lang.IndexOutOfBoundsException - If the index is out of range.
Since:
0.3.0

isGrouping

public boolean isGrouping(int field)

Determines whether the referenced field represents the set of all values in a super-aggregate value. This can be used to distinguish an actual null value in normal aggregation vs. a null that represents "all values" in super-aggregation.

For example, if there are 4 group-by properties, and super-aggregation is used, and this aggregate value happens to represent the grouping set {0, 1}, then properties 2 and 3 are "all values", and ...

Parameters:
field - A field reference integer, from 0 to n - 1, where n is the the number of group-by properties.
Returns:
true if the field represents "all values" in super-aggregation, false otherwise.
Throws:
java.lang.IllegalArgumentException - If the integer field reference is out of range.
Since:
0.7.0

isGrouping

public boolean isGrouping(java.lang.String propertyName)

Determines whether the referenced field represents the set of all values in a super-aggregate value. This can be used to distinguish an actual null value in normal aggregation vs. a null that represents "all values" in super-aggregation.

For example, if there are 4 group-by properties ({"prop0", "prop1", "prop2", "prop3"}), and super-aggregation is used, and this aggregate value happens to represent the grouping set {0, 1}, then properties 2 and 3 are "all values", and ...

Parameters:
propertyName - A property name.
Returns:
true if the field represents "all values" in super-aggregation, false otherwise.
Throws:
java.lang.IllegalArgumentException - If the property name is not a group-by property.
Since:
0.7.0

getGroupingId

public int getGroupingId(java.util.List<?> fields)

Determines the distinct grouping ID of the given referenced fields by determining whether each given referenced field represents "all values" in super-aggregation.

For example, if there are 4 group-by properties ({"prop0", "prop1", "prop2", "prop3"}), and super-aggregation is used, and this aggregate value happens to represent the grouping set {0, 1}, then properties 2 and 3 are "all values", and ...

In the above examples, each integer n reference can be freely substituted with the equivalent property name, e.g. 0 is equivalent to "prop0".

Parameters:
fields - A List of field references, which can be integer field references, from 0 to n - 1, where n is the number of group-by properties, or they can be property names. Each field reference maps to a bit in the returned number.
Returns:
An integer, with each set bit corresponding to an "all values" determination. The most significant bit corresponds to the first element.
Throws:
java.lang.IllegalArgumentException - If any of the fields represent integer field references that are out of range, or they represent string property names that aren't group-by properties.
Since:
0.7.0

toString

public java.lang.String toString()
Returns the string representation.

Overrides:
toString in class java.lang.Object
Returns:
The string representation.
Since:
0.7.0


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