|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.jutil.java.collections.BooleanAccumulator
A boolean accumulator for collections.
BooleanAccumulators process each element of a collection, and add the result of the process to the accumulator. The original collection remains unchanged.
Instead of an accumulate(Collection>
method, it has an in(Collection)
method.
That name just seems more convenient.
Field Summary | |
static java.lang.String |
CVS_REVISION
|
Constructor Summary | |
BooleanAccumulator()
|
Method Summary | |
abstract boolean |
accumulate(java.lang.Object element,
boolean acc)
public behavior pre isValidElement(element); |
boolean |
in(java.util.Collection collection)
public behavior pre (\forall Object o, collection.contains(o); isValidElement(o)); post (* the result of the accumulation is returned *); post collection == null => \result == initialAccumulator(); signals (ConcurrentModificationException) (* The collection was modified while accumulating *); |
abstract boolean |
initialAccumulator()
Subclasses should implement this method to return the initialized accumulator. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String CVS_REVISION
Constructor Detail |
public BooleanAccumulator()
Method Detail |
public abstract boolean initialAccumulator()
Subclasses should implement this method to return the initialized accumulator.
This method is called at the start of the accumulation. The result will be used
in the application of public boolean accumulate(Object element, boolean acc)
for the first element.
public abstract boolean accumulate(java.lang.Object element, boolean acc)
This method is called for each element in the collection we are accumulating.
Subclasses should implement this method to process
The result is the accumulator that will be used for the next element of the collection to process.
.element
- The object the method will process and change the accumulator with.acc
- The accumulator for the accumulation.
For the first element to be processed, the result of initialAccumulator
is used. For the other elements, the result of this method applied on
the previous element is used.public boolean in(java.util.Collection collection) throws java.util.ConcurrentModificationException
Perform the accumulation defined in
public boolean accumulate(Object element, boolean acc)
for each
element of public boolean initialAccumulator()
is used as accumulator.
For the other elements, the result of the application of
public boolean accumulate(Object element, boolean acc)
on the
previous element is used as accumulator.
The contents of
The result of this method is the object returned by the application of
public boolean accumulate(Object element, boolean acc)
on the
last element of the collection to be processed.
The precondition is variable. Subclasses could strengthen the postcondition of isValidElement. To the user, this means that this method cannot be called safely in a polymorphic context, since she has no idea what the actual precondition will become in subclasses. This can be resolved by making the model method isValidElement final in the polymorph supertype she needs to use.
collection
- The collection for which the ForAll operator has to be computed.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |