org.jutil.java.collections
Class ForAll

java.lang.Object
  |
  +--org.jutil.java.collections.BooleanAccumulator
        |
        +--org.jutil.java.collections.ForAll
All Implemented Interfaces:
CollectionOperator

public abstract class ForAll
extends BooleanAccumulator

A boolean for-all operator.

A convenience accumulator of collections that checks whether all elements of a collection satisfy the criterion defined in the abstract method public boolean criterion(Object element).

As with Accumulator, this class can best be used as an anonymous inner class.


boolean bool =
  new ForAll() {

       /oo
         o also public behavior
         o
         o post (* additional precondition for criterion method *)
         o
         o public model boolean isValidElement(Object element);
         o/

       /oo
         o also public behavior
         o
         o post \result == ((MyType)element.someProperty() ...)
         o/
        public boolean criterion(Object element) {
          // criterion code
        }
      }.in(collection);

Version:
$Revision: 1.17 $
Author:
Marko van Dooren, Jan Dockx

Field Summary
static java.lang.String CVS_REVISION
           
 
Constructor Summary
ForAll()
           
 
Method Summary
 boolean accumulate(java.lang.Object element, boolean acc)
          also public behavior

post \result == (acc && criterion(element));
abstract  boolean criterion(java.lang.Object element)
          public behavior

pre isValidElement(element);

// criterion should be consistent with equals; subclass can say more
post (\forall object o1;;
(\forall object o2; o2.equals(o1); criterion(o1) == criterion(o2)));
Check whether the given object satisfies the criterion for this ForAll accumulator.
 boolean in(java.util.Collection collection)
          also public behavior

post \result == (\forall Object o; collection.contains(o); criterion(o));
 boolean initialAccumulator()
          also public behavior

post \result == true;
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CVS_REVISION

public static final java.lang.String CVS_REVISION
Constructor Detail

ForAll

public ForAll()
Method Detail

criterion

public abstract boolean criterion(java.lang.Object element)
public behavior

pre isValidElement(element);

// criterion should be consistent with equals; subclass can say more
post (\forall object o1;;
(\forall object o2; o2.equals(o1); criterion(o1) == criterion(o2)));
Check whether the given object satisfies the criterion for this ForAll accumulator.

initialAccumulator

public final boolean initialAccumulator()
also public behavior

post \result == true;
Overrides:
initialAccumulator in class BooleanAccumulator

accumulate

public final boolean accumulate(java.lang.Object element,
                                boolean acc)
also public behavior

post \result == (acc && criterion(element));
Overrides:
accumulate in class BooleanAccumulator
Following copied from class: org.jutil.java.collections.BooleanAccumulator
Parameters:
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.

in

public boolean in(java.util.Collection collection)
also public behavior

post \result == (\forall Object o; collection.contains(o); criterion(o));
Overrides:
in in class BooleanAccumulator
Following copied from class: org.jutil.java.collections.BooleanAccumulator
Parameters:
collection - The collection for which the ForAll operator has to be computed.