
net.sf.jagg.RatioToReportAnalytic 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 RatioToReportAnalytic
is an
* AbstractDependentAnalyticFunction
that performs this
* calculation:
* sum(property) rows(0, 0) / sum(property) range()
* I.e. The sum of values so far divided by the overall sum.
*
* @author Randy Gettman
* @since 0.9.0
*/
public class RatioToReportAnalytic extends AbstractDependentAnalyticFunction
{
/**
* Constructs a RatioToReportAnalytic
, with no property.
*
* @param property Should be an empty string or null
.
*/
public RatioToReportAnalytic(String property)
{
setProperty(property);
}
/**
* Returns an uninitialized copy of this Aggregator
object,
* with the same property(ies) to analyze.
* @return An uninitialized copy of this Aggregator
object.
*/
public RatioToReportAnalytic replicate()
{
return new RatioToReportAnalytic(getProperty());
}
/**
* This depends on 2 functions.
* @return 2
.
*/
public int getNumDependentFunctions()
{
return 2;
}
/**
* Depends on two SumAggregators
.
* @param index A 0-based index, ranging from 0
through
* getNumDependentFunctions() - 1
.
* @return
* 0
=> SumAggregator(getProperty())
* 1
=> SumAggregator(getProperty())
*
*/
public AnalyticFunction getAnalyticFunction(int index)
{
String property = getProperty();
switch(index)
{
case 0:
return new SumAggregator(property);
case 1:
return new SumAggregator(property);
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
=> rows(0, 0)
* 1
=> range()
*
*/
public WindowClause getWindowClause(int index)
{
switch(index)
{
case 0:
return new WindowClause(WindowClause.Type.ROWS, 0, 0);
case 1:
return new WindowClause(WindowClause.Type.RANGE, null, null);
default:
throw new IndexOutOfBoundsException("Invalid index: " + index);
}
}
/**
* Returns the ratio to report as a Double
.
* @return The ratio to report as a Double
.
*/
public Double terminate()
{
return terminateDoubleDouble().doubleValue();
}
/**
* Returns the ratio to report as a DoubleDouble
.
* @return the ratio to report as a DoubleDouble
.
*/
public DoubleDouble terminateDoubleDouble()
{
DoubleDouble result = new DoubleDouble((Double) getValue(0));
result.divideSelfBy((Double) getValue(1));
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy