org.jutil.predicate
Class NegationAsFailure

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

public class NegationAsFailure
extends TotalPredicate

A class of predicates that wrap another predicate and treat the occurrence of an exception in eval() as false.

Note that if you wrap a NegationAsFailure object in another predicate, you will not get the same result as when switching the wrapping predicate and the NegationAsFailure. E.g. new Not(new NegationAsFailure(predicate)) will not always return the same value as new NegationAsFailure(new Not(predicate)).


Field Summary
static java.lang.String CVS_REVISION
           
 
Constructor Summary
NegationAsFailure(Predicate predicate)
          Initialize a new NegationAsFailure with the given predicate.
 
Method Summary
 boolean eval(java.lang.Object object)
          Evaluate this Predicate for the given object.
 Predicate getPredicate()
          Return the wrapped predicate.
 java.util.List getSubPredicates()
          Return the subpredicates of this Predicate.
 int nbSubPredicates()
          See superclass
 
Methods inherited from class org.jutil.predicate.TotalPredicate
count, exists, filter, forall, isValidElement
 
Methods inherited from class org.jutil.predicate.AbstractPredicate
equals
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CVS_REVISION

public static final java.lang.String CVS_REVISION
Constructor Detail

NegationAsFailure

public NegationAsFailure(Predicate predicate)
Initialize a new NegationAsFailure with the given predicate.

Parameters:
predicate - The predicate to be wrapped.

Specifications:
public behavior
requires predicate != null;
ensures getPredicate() == predicate;
Method Detail

eval

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

Specifications:
     also
public behavior
ensures getPredicate().isValidElement(object) ==> \result == getPredicate().eval(object);
ensures !getPredicate().isValidElement(object) ==> false;

Specifications inherited from overridden method in class TotalPredicate:
     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);

getPredicate

public Predicate getPredicate()
Return the wrapped predicate.

Specifications:
public behavior
ensures \result == getSubPredicates().get(1);

getSubPredicates

public java.util.List getSubPredicates()
Description copied from interface: Predicate
Return the subpredicates of this Predicate.

Specifications:
     also
public behavior
ensures Collections.containsExplicitly(\result ,getPredicate());
ensures \result .size() == 1;

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