org.rubato.logeo.predicates
Class AbstractPredicate

java.lang.Object
  extended by org.rubato.logeo.predicates.AbstractPredicate
All Implemented Interfaces:
java.util.Comparator<Predicate>, Predicate
Direct Known Subclasses:
ExtensionPredicate, FormPredicate

public abstract class AbstractPredicate
extends java.lang.Object
implements Predicate

This class implements predicates on denotators. Predicates may have any arity. The signature of predicate is indicated by implementing the getInputForm method.

Author:
Gérard Milmeister

Constructor Summary
AbstractPredicate()
           
 
Method Summary
 Predicate and(Predicate p1)
          Returns a predicate that is the conjuction of this and p.
abstract  boolean call(Denotator... denotators)
          Calls the predicate with a list of arguments.
 int compare(Predicate o1, Predicate o2)
          Implements the compare method required by the Comparator interface.
abstract  int getArity()
          Returns the arity of the predicate.
abstract  Form getInputForm(int i)
          Returns the ith argument form.
 java.lang.String getName()
          Returns the name of the predicate.
 boolean isCompatible(Predicate p)
          Returns true if p is compatible to this.
 Predicate negated()
          Returns a predicate that is the negation of this.
 Predicate or(Predicate p)
          Returns a predicate that is the disjunction of this and p.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

AbstractPredicate

public AbstractPredicate()
Method Detail

call

public abstract boolean call(Denotator... denotators)
                      throws RubatoException
Calls the predicate with a list of arguments. The predicate must have arity equal to the length of the list.

Specified by:
call in interface Predicate
Throws:
RubatoException

compare

public int compare(Predicate o1,
                   Predicate o2)
Implements the compare method required by the Comparator interface. The predicate must have arity 2 and call(a,b) is interpreted as a < b.

Specified by:
compare in interface java.util.Comparator<Predicate>

and

public Predicate and(Predicate p1)
              throws RubatoException
Returns a predicate that is the conjuction of this and p. Both predicates must have same arity.

Specified by:
and in interface Predicate
Throws:
RubatoException

or

public Predicate or(Predicate p)
             throws RubatoException
Returns a predicate that is the disjunction of this and p. Both predicates must have same arity.

Specified by:
or in interface Predicate
Throws:
RubatoException

negated

public Predicate negated()
Returns a predicate that is the negation of this.

Specified by:
negated in interface Predicate

getArity

public abstract int getArity()
Returns the arity of the predicate. Must be implemented in a subclass.

Specified by:
getArity in interface Predicate

getInputForm

public abstract Form getInputForm(int i)
Returns the ith argument form. Must be implemented in a subclass.

Specified by:
getInputForm in interface Predicate

getName

public java.lang.String getName()
Returns the name of the predicate.

Specified by:
getName in interface Predicate
Returns:
"anonymous" by default.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

isCompatible

public boolean isCompatible(Predicate p)
Returns true if p is compatible to this. Two predicates are compatible if both have the same arity and if their respective argument forms are the same or one of them is null.

Specified by:
isCompatible in interface Predicate