com.grack.prologmachine
Class Predicate

java.lang.Object
  |
  +--com.grack.prologmachine.Predicate

public class Predicate
extends java.lang.Object
implements Unifiable

Implements the functionality for a unifiable predicate. An atom is represented by a Predicate with arity 0 for simplicity.


Constructor Summary
Predicate(java.lang.String name, int arity)
          Constructs a new Predicate from a given name and arity.
Predicate(java.lang.String name, int arity, Unifiable argument)
          Constructs a new Predicate from a given name and arity and a single argument.
Predicate(java.lang.String name, int arity, Unifiable[] arguments)
          Constructs a new Predicate from a given name and arity and a list of arguments.
 
Method Summary
 void addArgument(Unifiable argument)
          Add a new argument to the predicate.
 int argumentCount()
          Returns the number of arguments this predicate has.
 Unifiable getArgument(int index)
          Returns the argument at the given index for this predicate.
 int getArity()
          Returns the arity of the predicate.
 java.lang.String getName()
          Returns the name of the predicate.
 PredicateSignature getSignature()
          Computes the predicate signature for this predicate.
 boolean isValid()
          Returns whether this represents a valid predicate or not.
 void setArgument(int index, Unifiable argument)
          Replace an argument with another.
 java.lang.String toString()
          Converts the predicate to a string representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Predicate

public Predicate(java.lang.String name,
                 int arity)
Constructs a new Predicate from a given name and arity. Further arguments can be added with addArgument().
Parameters:
name - The name of the predicate
arity - The arity of the predicate

Predicate

public Predicate(java.lang.String name,
                 int arity,
                 Unifiable argument)
Constructs a new Predicate from a given name and arity and a single argument.
Parameters:
name - The name of the predicate.
arity - The arity of the predicate.
argument - The argument to add to the predicate.

Predicate

public Predicate(java.lang.String name,
                 int arity,
                 Unifiable[] arguments)
Constructs a new Predicate from a given name and arity and a list of arguments.
Parameters:
name - The name of the predicate.
arity - The arity of the predicate.
arguments - The arguments to add to the predicate.
Method Detail

addArgument

public void addArgument(Unifiable argument)
Add a new argument to the predicate.
Parameters:
argument - The argument to add.

setArgument

public void setArgument(int index,
                        Unifiable argument)
Replace an argument with another.
Parameters:
index - The index of the argument.
argument - The argument to replace at this index.

argumentCount

public int argumentCount()
Returns the number of arguments this predicate has.
Returns:
The number of arguments this predicate has.

isValid

public boolean isValid()
Returns whether this represents a valid predicate or not.
Returns:
Whether this represents a valid predicate or not.

getSignature

public PredicateSignature getSignature()
Computes the predicate signature for this predicate.
Returns:
The predicate signature for this predicate.

getArgument

public Unifiable getArgument(int index)
Returns the argument at the given index for this predicate.
Parameters:
index - The index to retrieve the argument from.
Returns:
The argument at the given index.

toString

public java.lang.String toString()
Converts the predicate to a string representation.
Returns:
The string representation.
Overrides:
toString in class java.lang.Object

getName

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

getArity

public int getArity()
Returns the arity of the predicate.
Returns:
The arity of the predicate.