org.abora.white.collection.steppers
Class Accumulator

java.lang.Object
  |
  +--org.abora.white.xpp.basic.Heaper
        |
        +--org.abora.white.collection.steppers.Accumulator
Direct Known Subclasses:
BoxAccumulator, EdgeAccumulator, IntegerEdgeAccumulator, PtrArrayAccumulator, SetAccumulator, TableAccumulator, UnionRecruiter

public abstract class Accumulator
extends Heaper

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

Accumulator

protected Accumulator()

Accumulator

protected Accumulator(Rcvr rcvr)
Method Detail

ptrArray

public static Accumulator ptrArray()
An accumulator that returns a PtrArray of the object put into it, in sequence


step

public abstract void step(Heaper someObj)
Accumulate a new object into the Accumulator


value

public abstract Heaper value()
Return the object that results from accumulating all those objects


copy

public abstract Accumulator copy()
Return a new Accumulator just like the current one, except that from now on they accumulate separately


actualHashForEqual

public int actualHashForEqual()
Description copied from class: Heaper
Defined by subclasses to produce the value returned by hashForEqual.

Overrides:
actualHashForEqual in class Heaper

isEqual

public boolean isEqual(Heaper other)
Description copied from class: Heaper
Return true if the two objects are equal.

Specified by:
isEqual in class Heaper


Copyright © 2003 David G Jones. All Rights Reserved.
Original Udanax-Gold - Copyright © 1979-1999 Udanax.com. All rights reserved.