net.sf.jga.fn.algorithm
public class Accumulate<T> extends AbstractUnaryFunctor<Iterator<? extends T>,T> implements Serializable
If the iteration was empty, then the result of this function is the starting value or null if no starting value was given.
If no starting value was given, and the iteration has exactly one element, then the element is returned without the BinaryFunctor being used.
Copyright © 2003 David A. Hall
Nested Class Summary | |
---|---|
interface | Accumulate.Visitor
Interface for classes that may interpret an Accumulate functor. |
Constructor Summary | |
---|---|
Accumulate(BinaryFunctor<T,T,T> fn)
Builds an Accumulate functor that will use the given functor to process
elements in an iteration. | |
Accumulate(T startValue, BinaryFunctor<T,T,T> fn)
Builds an Accumulate functor that will use the given start value and
functor to process elements in an iteration. |
Method Summary | |
---|---|
void | accept(Visitor v)
Calls the Visitor's visit(Accumulate) method, if it
implements the nested Visitor interface. |
T | fn(Iterator<? extends T> iterator)
Apply the functor to the elements of the iteration and return the final
result. |
BinaryFunctor<T,T,T> | getFunction()
Returns the functor used to process elements in the iteration. |
T | getStartValue()
Returns the start value, or null if no start value was given. |
boolean | hasStartValue()
Returns true if a start value was passed at construction. |
String | toString() |
visit(Accumulate)
method, if it
implements the nested Visitor interface.