org.jutil.predicate
Class CompositePredicate

java.lang.Object
  |
  +--org.jutil.predicate.AbstractPredicate
        |
        +--org.jutil.predicate.CompositePredicate
All Implemented Interfaces:
CollectionOperator, Predicate
Direct Known Subclasses:
And, Or

public abstract class CompositePredicate
extends AbstractPredicate

A class of predicates that evaluates an object using a number of other predicates.


Field Summary
static java.lang.String CVS_REVISION
           
 
Constructor Summary
CompositePredicate()
          Initialize a new empty CompositePredicate.
CompositePredicate(Predicate[] predicates)
          Initialize a new CompositePredicate with the given predicates.
 
Method Summary
 void add(Predicate predicate)
          Add the given predicate to the end of this CompositePredicate.
 void clear()
          Clear this CompositePredicate.
 java.util.List getSubPredicates()
          See superclass
 boolean isValidElement(java.lang.Object o)
          This model method is supplied to make proving the correctness of a subclass easier.
 int nbSubPredicates()
          See superclass
 Predicate predicateAt(int index)
          Return the index'th subpredicate of this CompositePredicate.
 void removeAll(Predicate predicate)
          Remove all occurrences of the given predicate from this CompositePredicate.
 void removedPredicateAt(int index)
          Remove the index'th subpredicate from this CompositePredicate.
 
Methods inherited from class org.jutil.predicate.AbstractPredicate
count, equals, exists, filter, forall
 
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
eval
 

Field Detail

CVS_REVISION

public static final java.lang.String CVS_REVISION
Constructor Detail

CompositePredicate

public CompositePredicate()
Initialize a new empty CompositePredicate.

Specifications:
public behavior
ensures nbSubPredicates() == 0;

CompositePredicate

public CompositePredicate(Predicate[] predicates)
Initialize a new CompositePredicate with the given predicates.

Parameters:
predicates - An array containing the predicates.

Specifications:
public behavior
requires predicates != null;
requires ( \forall int i; i >= 0&&i < predicates.length; predicates[i] != null);
ensures ( \forall int i; i >= 0&&i < predicates.length; getSubPredicates().get(i) == predicates[i]);
ensures nbSubPredicates() == predicates.length;
Method Detail

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 == ( \forall Predicate p; getSubPredicates().contains(p); p.isValidElement(o));

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)));

add

public void add(Predicate predicate)
Add the given predicate to the end of this CompositePredicate.

Parameters:
predicate - The Predicate to add.

Specifications:
public behavior
requires predicate != null;
requires predicate != this;
requires !predicate.getSubPredicates().contains(this);
ensures nbSubPredicates() == \old(nbSubPredicates())+1;
ensures predicateAt(nbSubPredicates()) == predicate;

clear

public void clear()
Clear this CompositePredicate.

Specifications:
public behavior
ensures nbSubPredicates() == 0;

removedPredicateAt

public void removedPredicateAt(int index)
Remove the index'th subpredicate from this CompositePredicate.

Parameters:
index - The index of the predicate to remove.

Specifications:
public behavior
requires index > 0;
requires index <= nbSubPredicates();
ensures nbSubPredicates() == \old(nbSubPredicates())-1;
ensures ( \forall int i; i > index&&i <= \old(nbSubPredicates()); predicateAt(i-1) == \old(predicateAt(i)));

removeAll

public void removeAll(Predicate predicate)
Remove all occurrences of the given predicate from this CompositePredicate.

Parameters:
predicate - The predicate to be removed.

Specifications:
public behavior
ensures ( \forall int i; i > 0&&i < \old(nbSubPredicates()); \old(predicateAt(i)) != predicate ==> (\old(predicateAt(i)) == predicateAt(i-(int)( \num_of int j; j > 0&&j < i; \old(predicateAt(j)) == predicate))));
ensures nbSubPredicates() == \old(nbSubPredicates())-( \num_of int i; i > 0&&i <= \old(nbSubPredicates()); \old(predicateAt(i)) == predicate);
signals (ConcurrentModificationException) (* An exception was raised because another thread was modifying this CompositePredicate*);

predicateAt

public Predicate predicateAt(int index)
Return the index'th subpredicate of this CompositePredicate.

Parameters:
index - The index of the requested predicate.

Specifications:
public behavior
requires index > 0;
requires index <= nbSubPredicates();
ensures \result == getSubPredicates().get(index-1);

getSubPredicates

public java.util.List getSubPredicates()
See superclass
Specifications inherited from overridden method in interface Predicate:
public behavior
ensures \result != null;
ensures !\result .contains(null);
ensures !\result .contains(this);

nbSubPredicates

public int nbSubPredicates()
See superclass
Specifications inherited from overridden method in class AbstractPredicate:
      --- None ---
Specifications inherited from overridden method in interface Predicate:
public behavior
ensures \result == getSubPredicates().size();