|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.jga.fn.Functor<R> net.sf.jga.fn.UnaryFunctor<java.util.Iterator<? extends T>,T> net.sf.jga.fn.algorithm.Accumulate<T>
Summarize
public class Accumulate<T>
Applies a BinaryFunctor to each element in an iteration, and returns the final result. Each member of the collection is passed to the functor along with the previous result. If the two arg constructor is used, then the given value is used on the first invocation of the functor: otherwise the first element of the iteration is consumed and passed as the starting value.
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.
To Serialize an Accumulate, the generic parameter T must be serializable.
Copyright © 2003-2005 David A. Hall
Nested Class Summary | |
---|---|
static interface |
Accumulate.Visitor
Deprecated. Interface for classes that may interpret an Accumulate functor. |
Constructor Summary | |
---|---|
Accumulate(BinaryFunctor<T,T,T> fn)
Deprecated. Builds an Accumulate functor that will use the given functor to process elements in an iteration. |
|
Accumulate(T startValue,
BinaryFunctor<T,T,T> fn)
Deprecated. 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)
Deprecated. Calls the Visitor's visit(Accumulate) method, if it
implements the nested Visitor interface. |
T |
fn(java.util.Iterator<? extends T> iterator)
Deprecated. Apply the functor to the elements of the iteration and return the final result. |
BinaryFunctor<T,T,T> |
getFunction()
Deprecated. Returns the functor used to process elements in the iteration. |
T |
getStartValue()
Deprecated. Returns the start value, or null if no start value was given. |
boolean |
hasStartValue()
Deprecated. Returns true if a start value was passed at construction. |
java.lang.String |
toString()
Deprecated. |
Methods inherited from class net.sf.jga.fn.UnaryFunctor |
---|
bind, bind0th, bindNth, compose, compose, compose, composeNth, composeNth, eval, generate, generateNth |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Accumulate(BinaryFunctor<T,T,T> fn)
public Accumulate(T startValue, BinaryFunctor<T,T,T> fn)
Method Detail |
---|
public BinaryFunctor<T,T,T> getFunction()
public T getStartValue()
public boolean hasStartValue()
public T fn(java.util.Iterator<? extends T> iterator)
fn
in class UnaryFunctor<java.util.Iterator<? extends T>,T>
public void accept(Visitor v)
visit(Accumulate)
method, if it
implements the nested Visitor interface.
accept
in interface Visitable
accept
in class Functor<T>
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |