JTP API Documentation

jtp.fol
Class Variable

java.lang.Object
  |
  +--jtp.fol.Variable
All Implemented Interfaces:
Comparable, Serializable, Unifyable

public class Variable
extends Object
implements Unifyable, Comparable, Serializable

A Variable can be bound to (substituted with) some other Object.

See Also:
Serialized Form

Nested Class Summary
static class Variable.NameComparator
           
 
Constructor Summary
Variable(String s)
          Creates a Variable with name s.
Variable(String name, long serialNumber)
           
 
Method Summary
 int compareTo(Object o)
           
 boolean contains(Variable v)
          Determines whether or not v is contained within this Variable.
 String debugPrintout()
           
 Object deReferenceVariables()
          Returns the Object that this Variable is bound to.
 String getName()
          Name used primarily for printing purposes.
 long getSerialNumber()
           
 Collection getVariables(Collection c)
          Retrieves the variables in this Unifyable and places them into a provided target collection.
 void setValue(Object val)
          Bind this variable to val.
 Object substitute(Map h)
           
 String toString()
           
 void unbind()
          Set the bound value of this Variable to null.
 boolean unify(Object o, List bindings)
          Attempts to unify this with o.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Variable

public Variable(String s)
Creates a Variable with name s.

Parameters:
s - name of the Variable to be created.

Variable

public Variable(String name,
                long serialNumber)
Method Detail

getName

public String getName()
Name used primarily for printing purposes.

Returns:
the name of this Variable

getSerialNumber

public long getSerialNumber()

setValue

public void setValue(Object val)
Bind this variable to val.

Parameters:
val - an Object that this Variable is to be bound to
Throws:
IllegalStateException - If this Variable is already bound to a different value
Error - If binding to val results in a circular dependency, i.e., val is a Variable that is itself bound to this, possibly nested

unbind

public void unbind()
Set the bound value of this Variable to null. This Variable will no longer be bound.


toString

public String toString()
Overrides:
toString in class Object

debugPrintout

public String debugPrintout()

contains

public boolean contains(Variable v)
Determines whether or not v is contained within this Variable.

Specified by:
contains in interface Unifyable
Parameters:
v - a Variable
Returns:
true if v is == to this or if the bound value of this Variable is a Unifyable that contains v

deReferenceVariables

public Object deReferenceVariables()
Returns the Object that this Variable is bound to. If unbound, return this. If the bound value of this is a Unifyable, call deReferenceVariables() on it to get return value. Otherwise, return getValue().

Specified by:
deReferenceVariables in interface Unifyable
Returns:
Object that this is bound to
See Also:
Variable

unify

public boolean unify(Object o,
                     List bindings)
Attempts to unify this with o. Performs occurs check.

Specified by:
unify in interface Unifyable
Parameters:
o - the object to unify with.
bindings - the variable stack
Returns:
true if successful

substitute

public Object substitute(Map h)

getVariables

public Collection getVariables(Collection c)
Description copied from interface: Unifyable
Retrieves the variables in this Unifyable and places them into a provided target collection.

Specified by:
getVariables in interface Unifyable
Parameters:
c - the collection to which the variables are added. If null, and this Unifyable contains variables, a new collection is created.
Returns:
the target collection. If target is null, and there are no variables, null is returned; if a new collection is created, it has to be modifyable.

compareTo

public int compareTo(Object o)
Specified by:
compareTo in interface Comparable

JTP API Documentation