
net.sf.jagg.CumeDistAnalytic Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jagg-core Show documentation
Show all versions of jagg-core Show documentation
jAgg is a Java 5.0 API that supports “group by” operations on Lists of Java objects: aggregate operations such as count, sum, max, min, avg, and many more. It also allows custom aggregate operations.
The newest version!
package net.sf.jagg;
import net.sf.jagg.math.DoubleDouble;
import net.sf.jagg.model.WindowClause;
/**
* A CumeDistAnalytic
is an
* AbstractDependentAnalyticFunction
that performs this
* calculation:
* count(*) range(, 0) / count(*) range()
* I.e. The count of values so far divided by the overall count.
*
* @author Randy Gettman
* @since 0.9.0
*/
public class CumeDistAnalytic extends AbstractDependentAnalyticFunction
{
/**
* Constructs a CumeDistAnalytic
, with no property.
*
* @param property Should be an empty string or null
.
*/
public CumeDistAnalytic(String property)
{
setProperty(property);
}
/**
* Constructs an CumeDistAnalytic
, with no property.
*/
public CumeDistAnalytic()
{
setProperty(null);
}
/**
* Returns an uninitialized copy of this Aggregator
object,
* with the same property(ies) to analyze.
* @return An uninitialized copy of this Aggregator
object.
*/
public CumeDistAnalytic replicate()
{
return new CumeDistAnalytic();
}
/**
* This depends on 2 functions.
* @return 2
.
*/
public int getNumDependentFunctions()
{
return 2;
}
/**
* Depends on two CountAggregators
.
* @param index A 0-based index, ranging from 0
through
* getNumDependentFunctions() - 1
.
* @return
* 0
=> CountAggregator("*")
* 1
=> CountAggregator("*")
*
*/
public AnalyticFunction getAnalyticFunction(int index)
{
switch(index)
{
case 0:
return new CountAggregator("*");
case 1:
return new CountAggregator("*");
default:
throw new IndexOutOfBoundsException("Invalid index: " + index);
}
}
/**
* WindowClause
0 is range(, 0)
and
* WindowClause
1 is range()
.
* @param index A 0-based index, ranging from 0
through
* getNumDependentFunctions() - 1
.
* @return
* 0
=> range(, 0)
* 1
=> range()
*
*/
public WindowClause getWindowClause(int index)
{
switch(index)
{
case 0:
return new WindowClause(WindowClause.Type.RANGE, null, 0);
case 1:
return new WindowClause(WindowClause.Type.RANGE, null, null);
default:
throw new IndexOutOfBoundsException("Invalid index: " + index);
}
}
/**
* Returns the cumulative distribution as a Double
.
* @return The cumulative distribution as a Double
.
*/
public Double terminate()
{
return terminateDoubleDouble().doubleValue();
}
/**
* Returns the cumulative distribution as a DoubleDouble
.
* @return the cumulative distribution as a DoubleDouble
.
*/
public DoubleDouble terminateDoubleDouble()
{
DoubleDouble result = new DoubleDouble((Long) getValue(0));
result.divideSelfBy((Long) getValue(1));
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy