net.sf.molae.logic.basic
Class AdaptablePredicate

java.lang.Object
  |
  +--net.sf.molae.logic.basic.AdaptablePredicate
All Implemented Interfaces:
GeneralPredicate, Predicate
Direct Known Subclasses:
AbstractSinglePredicate

public abstract class AdaptablePredicate
extends Object
implements GeneralPredicate

Provides a predicate with a proxy strategy. Every method that takes a predicate as an argument, checks if the argument predicate provides a proxy for this predicate. If not it is also checked if this predicate provides a proxy for the argument predicate (for symmetric methods only). If a proxy is found it is used, otherwise the call is delegated to the default (base) instance.

Since:
1.1
See Also:
ProxyProvider

Constructor Summary
AdaptablePredicate()
           
 
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.
protected  GeneralPredicate getBasePredicate()
          Returns the base object as a GeneralPredicate.
static GeneralPredicate getProxyFor(GeneralPredicate provider, GeneralPredicate p)
          Tries to get a proxy.
 boolean implies(GeneralPredicate p)
          Tests if this predicate implies the specified predicate.
 GeneralPredicate or(GeneralPredicate p)
          Returns the disjunction of this predicate and the specified predicate.
protected  void setBasePredicate(GeneralPredicate base)
          Sets the base object to the specified value.
 GeneralPredicate xor(GeneralPredicate p)
          Returns the exclusive disjunction of this predicate and the specified predicate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.molae.logic.basic.GeneralPredicate
copy, equals, evaluate, isEmpty, not
 

Constructor Detail

AdaptablePredicate

public AdaptablePredicate()
Method Detail

getBasePredicate

protected GeneralPredicate getBasePredicate()
Returns the base object as a GeneralPredicate.
Returns:
the base object as a GeneralPredicate.
See Also:
setBasePredicate(net.sf.molae.logic.basic.GeneralPredicate)

setBasePredicate

protected void setBasePredicate(GeneralPredicate base)
Sets the base object to the specified value.
Parameters:
base - the default predicate, of which the methods are called, if no proxy was found.
Throws:
IllegalArgumentException - base is this
See Also:
getBasePredicate()

getProxyFor

public static GeneralPredicate getProxyFor(GeneralPredicate provider,
                                           GeneralPredicate p)
Tries to get a proxy.
Parameters:
provider - the ProxyProvider candidate.
p - the predicate for which a proxy is requested.
Returns:
a proxy based on the second predicate. null, if no proxy was found.

implies

public boolean implies(GeneralPredicate p)
Description copied from interface: GeneralPredicate
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.
Specified by:
implies in interface GeneralPredicate
Following copied from interface: net.sf.molae.logic.basic.GeneralPredicate
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.

and

public GeneralPredicate and(GeneralPredicate p)
Description copied from interface: GeneralPredicate
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.

Specified by:
and in interface GeneralPredicate
Following copied from interface: net.sf.molae.logic.basic.GeneralPredicate
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)
Description copied from interface: GeneralPredicate
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.

Specified by:
andNot in interface GeneralPredicate
Following copied from interface: net.sf.molae.logic.basic.GeneralPredicate
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)
Description copied from interface: GeneralPredicate
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.

Specified by:
or in interface GeneralPredicate
Following copied from interface: net.sf.molae.logic.basic.GeneralPredicate
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)
Description copied from interface: GeneralPredicate
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.

Specified by:
xor in interface GeneralPredicate
Following copied from interface: net.sf.molae.logic.basic.GeneralPredicate
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.