net.sf.jagg
Class PercentileAggregator

java.lang.Object
  extended by net.sf.jagg.Aggregator
      extended by net.sf.jagg.TwoPropAggregator
          extended by net.sf.jagg.PercentileAggregator

public class PercentileAggregator
extends TwoPropAggregator

This class allows represents the "percentile" aggregator over numeric values. The first property is the desired percentile, between 0 and 1 inclusive, and the second property denotes the desired sort order and return value.

Since:
0.1.0
Author:
Randy Gettman

Field Summary
 
Fields inherited from class net.sf.jagg.Aggregator
PROP_SELF
 
Constructor Summary
PercentileAggregator(double percentile, java.lang.String property)
          Constructs a PercentileAggregator that operates on the specified properties.
PercentileAggregator(java.lang.String properties)
          Constructs a PercentileAggregator on the specified properties, in the format: percentile, property.
 
Method Summary
 void init()
          Initialize an internal list to empty.
 void iterate(java.lang.Object value)
          Make sure the second property's value is not null, then add the entire Object to an internal list.
 void merge(Aggregator agg)
          Merge the given Aggregator into this one by adding the contents of the given Aggregator's internal list into this Aggregator's internal list.
 PercentileAggregator replicate()
          Returns an uninitialized copy of this Aggregator object, with the same property(ies) to analyze.
protected  void setProperty(java.lang.String property)
          Expects that the first "property" given is the actual desired percentile, from 0 to 1 inclusive.
 java.lang.Double terminate()
          Return the value among the values in the specified property that matches the given percentile value, with the following algorithm: Sort the internal list with respect to the second property, using Collections.sort, using a PropertiesComparator that compares values based on the second property given.
 DoubleDouble terminateDoubleDouble()
          Return the result as a DoubleDouble.
 
Methods inherited from class net.sf.jagg.TwoPropAggregator
getProperty2, toString
 
Methods inherited from class net.sf.jagg.Aggregator
equals, getAggregator, getAggregator, getProperty, getValueFromProperty, hashCode, isInUse, setInUse
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PercentileAggregator

public PercentileAggregator(java.lang.String properties)
Constructs a PercentileAggregator on the specified properties, in the format: percentile, property.

Parameters:
properties - A specification string in the format: percentile, property.

PercentileAggregator

public PercentileAggregator(double percentile,
                            java.lang.String property)
Constructs a PercentileAggregator that operates on the specified properties.

Parameters:
percentile - The percentile value, between zero and one.
property - Determine the percentile of this property.
Method Detail

replicate

public PercentileAggregator replicate()
Returns an uninitialized copy of this Aggregator object, with the same property(ies) to analyze.

Specified by:
replicate in class Aggregator
Returns:
An uninitialized copy of this Aggregator object.

setProperty

protected void setProperty(java.lang.String property)
Expects that the first "property" given is the actual desired percentile, from 0 to 1 inclusive. The second "property" is the sort parameter.

Overrides:
setProperty in class TwoPropAggregator
Parameters:
property - The property string, with one comma separating two actual properties.
Throws:
java.lang.NumberFormatException - If the first property, the percentile, is not a number.
java.lang.IllegalArgumentException - If the first property, the percentile, is not between 0 and 1, inclusive.
See Also:
Aggregator.getProperty(), TwoPropAggregator.getProperty2()

init

public void init()
Initialize an internal list to empty.

Specified by:
init in class Aggregator

iterate

public void iterate(java.lang.Object value)
Make sure the second property's value is not null, then add the entire Object to an internal list.

Specified by:
iterate in class Aggregator
Parameters:
value - The value to aggregate.
See Also:
Aggregator.getValueFromProperty(java.lang.Object, java.lang.String)

merge

public void merge(Aggregator agg)
Merge the given Aggregator into this one by adding the contents of the given Aggregator's internal list into this Aggregator's internal list.

Specified by:
merge in class Aggregator
Parameters:
agg - The Aggregator to merge into this one.

terminate

public java.lang.Double terminate()
Return the value among the values in the specified property that matches the given percentile value, with the following algorithm:
  1. Sort the internal list with respect to the second property, using Collections.sort, using a PropertiesComparator that compares values based on the second property given.
  2. Calculate a zero-based "row number" based on the percentile value (the first property given), with the formula r = p * (n - 1), where r is the row number, p is the percentile value, and n is the number of non-null values processed.
  3. If r is an integer, then return the value of that row's property.
  4. Else, return a linear interpolation of the values of the two rows' properties bounding r.

Specified by:
terminate in class Aggregator
Returns:
The desired Double that best matches the given percentile value, or null if no items were processed.
See Also:
Collections.sort(java.util.List), PropertiesComparator

terminateDoubleDouble

public DoubleDouble terminateDoubleDouble()
Return the result as a DoubleDouble. This is used mainly when other Aggregators that use this result must maintain a high precision.

Overrides:
terminateDoubleDouble in class Aggregator
Returns:
The desired DoubleDouble that best matches the given percentile value, or NaN if no values have been accumulated.
Since:
0.4.0
See Also:
DoubleDouble


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