|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object
|
+--org.abora.white.xpp.basic.Heaper
|
+--org.abora.white.collection.steppers.Accumulator
An Accumulator is a thing which collects a sequence of objects one at a time for some purpose. Typically, this purpose is to construct a new object out of all the collected objects. When used in this way, one can think of the Accumulator as being sort of like a pseudo-constructor which is spread out in time, and whose arguments are identified by the sequence they occur in. Accumulators are typically used in loops.
A (future) example of an Accumulator which is not like "a pseudo-constructor spread out in time" is a communications stream between two threads (or even coroutines) managed by an Accumulator / Stepper pair. The producer process produces by putting objects into his Accumulator, and the consuming process consumes by pulling values out of his Stepper. If you want to stretch the analogy, I suppose you can see the Accumulator of the pair as a pseudo-constructor which constructs the Stepper, but *overlapped* in time.
It is normally considered bad style for two methods/functions to be pointing at the same Acumulator. As long as Accumulators are used locally and without aliasing (i.e., as if they were pass-by-value Vars), these implementationally side-effecty objects can be understood applicatively. If a copy of an Accumulator can be passed instead of a pointer to the same one, this is to be prefered. This same comment applies even more so for Steppers.
Example: To build a set consisting of some transform of the elements of an existing set
(what Smalltalk would naturally do with "collect:"), a natural form for the loop would be:
SPTR(Accumulator) acc = setAccumulator();
FOR_EACH(Heaper,each,oldSet->stepper(), {
acc->step (transform (each));
});
return CAST(ImmuSet,acc->value());
See class Stepper for documentation of FOR_EACH.
| Constructor Summary | |
protected |
Accumulator()
|
protected |
Accumulator(Rcvr rcvr)
|
| Method Summary | |
int |
actualHashForEqual()
Defined by subclasses to produce the value returned by hashForEqual. |
abstract Accumulator |
copy()
Return a new Accumulator just like the current one, except that from now on they accumulate separately |
boolean |
isEqual(Heaper other)
Return true if the two objects are equal. |
static Accumulator |
ptrArray()
An accumulator that returns a PtrArray of the object put into it, in sequence |
abstract void |
step(Heaper someObj)
Accumulate a new object into the Accumulator |
abstract Heaper |
value()
Return the object that results from accumulating all those objects |
| Methods inherited from class org.abora.white.xpp.basic.Heaper |
destroy, destruct, equals, hashForEqual, printContentsOn, printOn, sendSelfTo, toString |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
protected Accumulator()
protected Accumulator(Rcvr rcvr)
| Method Detail |
public static Accumulator ptrArray()
public abstract void step(Heaper someObj)
public abstract Heaper value()
public abstract Accumulator copy()
public int actualHashForEqual()
Heaper
actualHashForEqual in class Heaperpublic boolean isEqual(Heaper other)
Heaper
isEqual in class Heaper
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||