net.sf.molae.logic.basic
Interface GeneralPredicate

All Superinterfaces:
Predicate
All Known Subinterfaces:
SinglePredicate
All Known Implementing Classes:
AdaptablePredicate, GeneralPredicateProxy, Negation

public interface GeneralPredicate
extends Predicate

Common interface for all sets that are not defined by a list of their elements but by a predicate that defines for each object if it is contained or not.

Since:
1.1

Method Summary
 GeneralPredicate and(GeneralPredicate p)
          Returns the conjunction of this predicate and the specified predicate.
 GeneralPredicate andNot(GeneralPredicate p)
          Returns the difference of this predicate and the specified predicate.
 GeneralPredicate copy()
          Creates and returns a copy of this object.
 boolean equals(Object obj)
          Indicates whether some other object is "equal to" this Predicate.
 boolean evaluate(Object input)
          Applies the predicate to an argument.
 boolean implies(GeneralPredicate p)
          Tests if this predicate implies the specified predicate.
 boolean isEmpty()
          Checks if the evaluate method of this predicate returns always false.
 GeneralPredicate not()
          Returns the negation of this predicate (optional operation).
 GeneralPredicate or(GeneralPredicate p)
          Returns the disjunction of this predicate and the specified predicate.
 GeneralPredicate xor(GeneralPredicate p)
          Returns the exclusive disjunction of this predicate and the specified predicate.
 

Method Detail

equals

public boolean equals(Object obj)
Indicates whether some other object is "equal to" this Predicate.

If two predicates are equal it is expected that they return equal results for all method calls with equal arguments, in particular for the evaluate method.

Overrides:
equals in class Object
Parameters:
obj - the reference object with which to compare
Returns:
true if the specified object is equal to this predicate in the above described sense.

copy

public GeneralPredicate copy()
Creates and returns a copy of this object.
Returns:
a clone of this instance.

isEmpty

public boolean isEmpty()
Checks if the evaluate method of this predicate returns always false.
Returns:
true if this predicate never holds.
Throws:
IllegalStateException - if it is not decidable if this predicate is empty.

evaluate

public boolean evaluate(Object input)
Applies the predicate to an argument.
Specified by:
evaluate in interface Predicate
Parameters:
input - argument on which the predicate is applied.
Returns:
result of the application

implies

public boolean implies(GeneralPredicate p)
Tests if this predicate implies the specified predicate. This is the case if the evaluate method of the specified predicate returns true for every argument for which the evaluate method of this predicate returns true, or more formally:
 implies(p) ⇔ ( ∀x evaluate(x) ⇒ p.evaluate(x) )
 
It is not required but recommended that the inversion also holds.
Parameters:
p - predicate to be checked for implication in this predicate.
Returns:
true if this predicate implies the specified predicate
Throws:
ClassCastException - if this method is not implemented for the specified predicate.
IllegalArgumentException - if this method is not implemented for the specified predicate.
NullPointerException - if p is null.

not

public GeneralPredicate not()
Returns the negation of this predicate (optional operation). The evaluate method of the negation returns true, iff the evaluate methods of this predicate returns false.

This interface does not specify the state of this object after the operation has been performed. It can be changed or unchanged. Therefore this method should either be used with a subinterface that specifies the state of this object or all references to it should be discarded afterwards.

Returns:
the negation of this predicate.
Throws:
UnsupportedOperationException - operation not implemented

and

public GeneralPredicate and(GeneralPredicate p)
Returns the conjunction of this predicate and the specified predicate. The evaluate method of the conjunction returns true, iff the evaluate methods of both (this and the specified predicate) return true.

This interface does not specify the state of this object after the operation has been performed. It can be changed or unchanged. Therefore this method should either be used with a subinterface that specifies the state of this object or all references to it should be discarded afterwards.

Parameters:
p - predicate to be conjoined with this predicate
Returns:
the conjunction of this predicate and the specified predicate.
Throws:
ClassCastException - if the conjunction of this predicate and the specified predicate is not defined.
IllegalArgumentException - if the conjunction of this predicate and the specified predicate is not defined.
NullPointerException - if p is null.

andNot

public GeneralPredicate andNot(GeneralPredicate p)
Returns the difference of this predicate and the specified predicate. The evaluate method of the difference returns true, iff the evaluate methods of this predicate returns true and the evaluate method of the specified predicate returns false.

This interface does not specify the state of this object after the operation has been performed. It can be changed or unchanged. Therefore this method should either be used with a subinterface that specifies the state of this object or all references to it should be discarded afterwards.

Parameters:
p - predicate to be conjoined with this predicate
Returns:
the difference of this predicate and the specified predicate.
Throws:
ClassCastException - if the difference of this predicate and the specified predicate is not defined.
IllegalArgumentException - if the difference of this predicate and the specified predicate is not defined.
NullPointerException - if p is null.

or

public GeneralPredicate or(GeneralPredicate p)
Returns the disjunction of this predicate and the specified predicate. The evaluate method of the disjunction returns false, iff the evaluate methods of both (this and the specified predicate) return false.

This interface does not specify the state of this object after the operation has been performed. It can be changed or unchanged. Therefore this method should either be used with a subinterface that specifies the state of this object or all references to it should be discarded afterwards.

Parameters:
p - predicate to be conjoined with this predicate
Returns:
the disjunction of this predicate and the specified predicate.
Throws:
ClassCastException - if the disjunction of this predicate and the specified predicate is not defined.
IllegalArgumentException - if the disjunction of this predicate and the specified predicate is not defined.
NullPointerException - if p is null.

xor

public GeneralPredicate xor(GeneralPredicate p)
Returns the exclusive disjunction of this predicate and the specified predicate. The evaluate method of the exclusive disjunction returns true, iff the evaluate methods of one of the predicates returns true and the evaluate method of the other predicate returns false.

This interface does not specify the state of this object after the operation has been performed. It can be changed or unchanged. Therefore this method should either be used with a subinterface that specifies the state of this object or all references to it should be discarded afterwards.

Parameters:
p - predicate to be conjoined with this predicate
Returns:
the exclusive disjunction of this predicate and the specified predicate.
Throws:
ClassCastException - if the exclusive disjunction of this predicate and the specified predicate is not defined.
IllegalArgumentException - if the exclusive disjunction of this predicate and the specified predicate is not defined.
NullPointerException - if p is null.