Package org.projog.core.predicate
Class PredicateKey
- java.lang.Object
-
- org.projog.core.predicate.PredicateKey
-
- All Implemented Interfaces:
java.lang.Comparable<PredicateKey>
public final class PredicateKey extends java.lang.Object implements java.lang.Comparable<PredicateKey>
Represents the structure of aTerm.Defines
Terms by their name (functor) and number of arguments (arity). This "metadata" or "descriptor information" allows rules whose heads (consequences) share the same structure to be grouped together.As
AtomandStructureare the only subclasses ofTermthat can be the head (consequent) of a rule they are the only subclasses ofTermthatPredicateKeyis intended to describe.PredicateKeys are constant; their values cannot be changed after they are created.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Stringnameprivate intnumArgsprivate static java.lang.StringPREDICATE_KEY_FUNCTOR
-
Constructor Summary
Constructors Constructor Description PredicateKey(java.lang.String name, int numArgs)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(PredicateKey o)Ordered on name or, if names identical, number of arguments.static PredicateKeycreateForTerm(Term t)Returns aPredicateKeyfor the specified term.static PredicateKeycreateFromNameAndArity(Term t)booleanequals(java.lang.Object o)private static java.lang.StringgetInvalidTypeExceptionMessage(Term t)java.lang.StringgetName()intgetNumArgs()inthashCode()java.lang.StringtoString()TermtoTerm()
-
-
-
Field Detail
-
PREDICATE_KEY_FUNCTOR
private static final java.lang.String PREDICATE_KEY_FUNCTOR
- See Also:
- Constant Field Values
-
name
private final java.lang.String name
-
numArgs
private final int numArgs
-
-
Method Detail
-
createForTerm
public static PredicateKey createForTerm(Term t)
Returns aPredicateKeyfor the specified term.- Parameters:
t- a term the returnedPredicateKeyshould represent (needs to have aTerm.getType()value ofTermType.ATOMorTermType.STRUCTURE)- Returns:
- a
PredicateKeyfor the specified term. - Throws:
ProjogException- iftis not of typeTermType.ATOMorTermType.STRUCTURE
-
createFromNameAndArity
public static PredicateKey createFromNameAndArity(Term t)
- Parameters:
t- must be a structure named/where the first argument is the name of the predicate to represent and the second (and final) argument is the arity.
-
getInvalidTypeExceptionMessage
private static java.lang.String getInvalidTypeExceptionMessage(Term t)
-
getName
public java.lang.String getName()
-
getNumArgs
public int getNumArgs()
-
toTerm
public Term toTerm()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the reference object with which to compare.- Returns:
trueifois an instanceofPredicateKeyand has the same name and number of arguments as this instance
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- Returns:
name+"/"+numArgs
-
compareTo
public int compareTo(PredicateKey o)
Ordered on name or, if names identical, number of arguments.- Specified by:
compareToin interfacejava.lang.Comparable<PredicateKey>
-
-