
net.sf.jagg.AbstractDependentAnalyticFunction 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 java.util.HashMap;
import java.util.Map;
import net.sf.jagg.model.WindowClause;
/**
* An AbstractDependentAnalyticFunction
is an Aggregator
.
* It implements DependentAnalyticFunction
by keeping track of the
* values from the AnalyticFunctions
that get supplied by the
* setValue
method.
*
* A concrete subclass must implement the following methods to complete the
* DependentAnalyticFunction
interface:
*
* getNumDependentFunctions()
- The number of
* AnalyticFunctions
on which this function depends.
* getAnalyticFunction(int index)
- Supply the functions
* by index.
* getWindowClause(int index)
- Supply the corresponding
* WindowClauses
by index.
* terminate()
- Call getValue
to get the
* values from the functions on which this function depends, and calculate or
* construct the result of this function.
* replicate()
Create an unitialized copy of this function.
*
*
* @author Randy Gettman
* @since 0.9.0
*/
public abstract class AbstractDependentAnalyticFunction extends Aggregator implements DependentAnalyticFunction
{
private Map myValues = new HashMap();
/**
* Performs no initialization. Initialization will however occur in any
* AnalyticFunctions
on which this
* AbstractDependentAnalyticFunction
depends.
*/
public final void init() { }
/**
* Performs no iteration. Iteration will however occur in any
* AnalyticFunctions
on which this
* AbstractDependentAnalyticFunction
depends.
* @param value Ignored.
*/
public final void iterate(Object value) { }
/**
* Performs no merging. Merging will however occur in any
* AnalyticFunctions
on which this
* AbstractDependentAnalyticFunction
depends.
* @param agg Ignored.
*/
public final void merge(AggregateFunction agg) { }
/**
* Performs no deleting. Deleting will however occur in any
* AnalyticFunctions
on which this
* AbstractDependentAnalyticFunction
depends.
* @param value Ignored.
*/
public final void delete(Object value) { }
/**
* No AbstractDependentAnalyticFunctions
can take a
* user-supplied WindowClause
.
* @return false
.
*/
public final boolean takesWindowClause()
{
return false;
}
/**
* The default WindowClause
for an
* AbstractDependentAnalyticFunction
is range()
.
* This ensures that nothing is terminated until the entire partition is
* processed. This guarantees that all values are available for calculation.
* @return range()
.
*/
public final WindowClause getWindowClause()
{
return new WindowClause(WindowClause.Type.RANGE, null, null);
}
/**
* Stores the current value of the AnalyticFunction
at the given
* index. Analytic
calls this getNumDependentFunctions()
* times prior to calling terminate()
, so that terminate
* can make a calculation based on these values.
* @param index A 0-based index, ranging from 0
through
* getNumDependentFunctions() - 1
.
* @param value The current value of the AnalyticFunction
.
*/
public final void setValue(int index, Object value)
{
myValues.put(index, value);
}
/**
* Returns the current value of the AnalyticFunction
at the
* given index. In terminate
, call this method to retrieve the
* values necessary for the calculation.
* @param index A 0-based index, ranging from 0
through
* getNumDependentFunctions() - 1
.
* @return The current value of the AnalyticFunction
.
*/
protected final Object getValue(int index)
{
return myValues.get(index);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy