org.jutil.predicate
Class TotalPredicate

java.lang.Object
  |
  +--org.jutil.predicate.AbstractPredicate
        |
        +--org.jutil.predicate.TotalPredicate
All Implemented Interfaces:
CollectionOperator, Predicate
Direct Known Subclasses:
NegationAsFailure, PrimitiveTotalPredicate

public abstract class TotalPredicate
extends AbstractPredicate

A class of Predicates that do not throw exceptions.

If your predicate don't throw exceptions, you should subclass TotalPredicate. This saves the client from writing useless try-catch blocks.

Typically, this class will be used as an anonymous inner class as follows:

TotalPredicate myPredicate = new TotalPredicate() {
            public boolean eval(Object o) {
              //calculate boolean value
              //using the given object
            }
            public int nbSubPredicates() {
              // ...
            }
            public List getSubPredicates() {
              // ...
            }
          };
 

Note that if your predicate doesn't contain any sub predicates, it should extend PrimitiveTotalPredicate instead of this class.


Field Summary
static java.lang.String CVS_REVISION
           
 
Constructor Summary
TotalPredicate()
           
 
Method Summary
 int count(java.util.Collection collection)
          See superclass
abstract  boolean eval(java.lang.Object object)
          Evaluate this Predicate for the given object.
 boolean exists(java.util.Collection collection)
          See superclass
 void filter(java.util.Collection collection)
          See superclass
 boolean forall(java.util.Collection collection)
          See superclass
 boolean isValidElement(java.lang.Object o)
          This model method is supplied to make proving the correctness of a subclass easier.
 
Methods inherited from class org.jutil.predicate.AbstractPredicate
equals, nbSubPredicates
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jutil.predicate.Predicate
getSubPredicates
 

Field Detail

CVS_REVISION

public static final java.lang.String CVS_REVISION
Constructor Detail

TotalPredicate

public TotalPredicate()
Method Detail

eval

public abstract boolean eval(java.lang.Object object)
Description copied from interface: Predicate
Evaluate this Predicate for the given object.

Specifications:
     also
public behavior
signals (Exception) false;

Specifications inherited from overridden method in interface Predicate:
public behavior
ensures \result == true|\result == false;
signals (Exception) !isValidElement(object);

isValidElement

public boolean isValidElement(java.lang.Object o)
Description copied from interface: CollectionOperator

This model method is supplied to make proving the correctness of a subclass easier. It offers a tunnel for information the caller of methods that operate on the collection.

Most often, this information concerns the type of the elements and them not being null.

The algorithm does not use this method, so we will not force subclasses to implement it. A strengthened specification should be given to enable proving the correctness of a specific operator.

This is actually an abstract precondition as used in Eiffel.

Specifications:
     also
public behavior
ensures \result == true;

Specifications inherited from overridden method in interface CollectionOperator:
public behavior
ensures ( \forall Object o1; ; ( \forall Object o2; (o2 != null)&&o2.equals(o1); isValidElement(o1) == isValidElement(o2)));

exists

public boolean exists(java.util.Collection collection)
Description copied from class: AbstractPredicate
See superclass

Specifications:
     also
public behavior
signals (Exception) false;

Specifications inherited from overridden method in class AbstractPredicate:
      --- None ---
Specifications inherited from overridden method in interface Predicate:
public behavior
ensures collection != null ==> \result == ( \exists Object o; Collections.containsExplicitly(collection,o); eval(o) == true);
ensures collection == null ==> \result == false;
signals (ConcurrentModificationException) (* The collection was modified while accumulating *);
signals (Exception) (collection != null)&&( \exists Object o; (collection != null)&&Collections.containsExplicitly(collection,o); !isValidElement(o));

forall

public boolean forall(java.util.Collection collection)
Description copied from class: AbstractPredicate
See superclass

Specifications:
     also
public behavior
signals (Exception) false;

Specifications inherited from overridden method in class AbstractPredicate:
      --- None ---
Specifications inherited from overridden method in interface Predicate:
public behavior
ensures collection != null ==> \result == ( \forall Object o; Collections.containsExplicitly(collection,o); eval(o) == true);
ensures collection == null ==> \result == true;
signals (ConcurrentModificationException) (* The collection was modified while accumulating *);
signals (Exception) (collection != null)&&( \exists Object o; (collection != null)&&Collections.containsExplicitly(collection,o); !isValidElement(o));

count

public int count(java.util.Collection collection)
Description copied from class: AbstractPredicate
See superclass

Specifications:
     also
public behavior
signals (Exception) false;

Specifications inherited from overridden method in class AbstractPredicate:
      --- None ---
Specifications inherited from overridden method in interface Predicate:
public behavior
ensures collection != null ==> \result == ( \num_of Object o; Collections.containsExplicitly(collection,o); eval(o) == true);
ensures collection == null ==> \result == 0;
signals (ConcurrentModificationException) (* The collection was modified while accumulating *);
signals (Exception) (collection != null)&&( \exists Object o; (collection != null)&&Collections.containsExplicitly(collection,o); !isValidElement(o));

filter

public void filter(java.util.Collection collection)
Description copied from class: AbstractPredicate
See superclass

Specifications:
     also
public behavior
signals (Exception) false;

Specifications inherited from overridden method in class AbstractPredicate:
      --- None ---
Specifications inherited from overridden method in interface Predicate:
public behavior
ensures collection != null ==> ( \forall Object o; Collections.containsExplicitly(collection,o); eval(o) == true);
ensures collection != null ==> ( \forall Object o; \old(Collections.containsExplicitly(collection,o)); (eval(o) == true) ==> (Collections.nbExplicitOccurrences(o,collection) == \old(Collections.nbExplicitOccurrences(o,collection))));
signals (ConcurrentModificationException) (* The collection was modified while accumulating *);
signals (Exception) (collection != null)&&( \exists Object o; (collection != null)&&Collections.containsExplicitly(collection,o); !isValidElement(o));