Prolog Cafe v1.2

jp.ac.kobe_u.cs.prolog.lang
Class VariableTerm

java.lang.Object
  extended by jp.ac.kobe_u.cs.prolog.lang.Term
      extended by jp.ac.kobe_u.cs.prolog.lang.VariableTerm
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Term>, Undoable

public class VariableTerm
extends Term
implements Undoable

Variable.
The VariableTerm class represents a logical variable.
For example,

   Term t = new VariableTerm();
 

See Also:
Serialized Form

Field Summary
protected  long timeStamp
          A CPF time stamp when this object is newly constructed.
protected  Term val
          Holds a term to which this variable is bound.
 
Fields inherited from class jp.ac.kobe_u.cs.prolog.lang.Term
AFTER, BEFORE, EQUAL
 
Constructor Summary
VariableTerm()
          Constructs a new logical variable so that the timeStamp field is set to Long.MIN_VALUE.
VariableTerm(Prolog engine)
          Constructs a new logical variable so that the timeStamp field is set to the current value of CPFTimeStamp of the specified Prolog engine.
 
Method Summary
 void bind(Term t, Trail trail)
          Binds this variable to a given term.
 int compareTo(Term anotherTerm)
          Compares two terms in Prolog standard order of terms.
 boolean convertible(java.lang.Class type)
          Checks whether this object is convertible with the given Java class type if this variable is unbound.
protected  Term copy(Prolog engine)
          Returns a copy of this object if unbound variable.
 Term dereference()
          Returns the dereference value of this term.
 boolean equals(java.lang.Object obj)
          Checks term equality of two terms.
 boolean isGround()
          Check whether this term is a ground term.
protected  java.lang.String name()
          Returns a string representation of this object.
 long timeStamp()
          Returns the value of timeStamp.
 java.lang.Object toJava()
          Returns this if this variable is unbound.
 java.lang.String toQuotedString()
          Returns a quoted string representation of this term if unbound.
 java.lang.String toString()
          Returns a string representation of this term if unbound.
 void undo()
          Undoes this object.
 boolean unify(Term t, Trail trail)
          Checks whether the argument term is unified with this one.
 
Methods inherited from class jp.ac.kobe_u.cs.prolog.lang.Term
convertible, instanceOfTerm, isClosure, isDouble, isInteger, isJavaObject, isList, isNil, isNumber, isStructure, isSymbol, isVariable
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

val

protected Term val
Holds a term to which this variable is bound. Initial value is this (self-reference).


timeStamp

protected long timeStamp
A CPF time stamp when this object is newly constructed.

Constructor Detail

VariableTerm

public VariableTerm()
Constructs a new logical variable so that the timeStamp field is set to Long.MIN_VALUE.


VariableTerm

public VariableTerm(Prolog engine)
Constructs a new logical variable so that the timeStamp field is set to the current value of CPFTimeStamp of the specified Prolog engine.

Parameters:
engine - Current Prolog engine.
See Also:
Prolog.getCPFTimeStamp()
Method Detail

timeStamp

public long timeStamp()
Returns the value of timeStamp.

See Also:
timeStamp

name

protected java.lang.String name()
Returns a string representation of this object.


unify

public boolean unify(Term t,
                     Trail trail)
Checks whether the argument term is unified with this one. If this is an unbound variable, the unify method binds this to the dereferenced value of argument term: bind(t.dereference(), trail), and returns true. Otherwise, it returns a boolean whose value is val.unify(t, trail).

Specified by:
unify in class Term
Parameters:
t - the term to be unified with.
trail - Trail Stack.
Returns:
true if succeeds, otherwise false.
See Also:
val, bind(Term,Trail), Trail

bind

public void bind(Term t,
                 Trail trail)
Binds this variable to a given term. And pushs this variable to trail stack if necessary.

Parameters:
t - a term to be bound.
trail - Trail Stack
See Also:
Trail

convertible

public boolean convertible(java.lang.Class type)
Checks whether this object is convertible with the given Java class type if this variable is unbound. Otherwise, returns the value of val.convertible(type).

Overrides:
convertible in class Term
Parameters:
type - the Java class type to compare with.
Returns:
true if this (or dereferenced term) is convertible with type. Otherwise false.
See Also:
val

copy

protected Term copy(Prolog engine)
Returns a copy of this object if unbound variable. Otherwise, returns the value of val.copy(engine).

Overrides:
copy in class Term
See Also:
val

dereference

public Term dereference()
Description copied from class: Term
Returns the dereference value of this term.

Overrides:
dereference in class Term

isGround

public boolean isGround()
Description copied from class: Term
Check whether this term is a ground term.

Overrides:
isGround in class Term
Returns:
true if ground, otherwise false.

toJava

public java.lang.Object toJava()
Returns this if this variable is unbound. Otherwise, returns a Java object that corresponds to the dereferenced term: val.toJava().

Overrides:
toJava in class Term
Returns:
a Java object defined in Prolog Cafe interoperability with Java.
See Also:
val

toQuotedString

public java.lang.String toQuotedString()
Returns a quoted string representation of this term if unbound. Otherwise, returns the value of dereferenced term: val.toQuotedString()

Overrides:
toQuotedString in class Term
See Also:
val

equals

public boolean equals(java.lang.Object obj)
Checks term equality of two terms. This method returns a boolean whose value is (this == obj) if this variable is unbound. Otherwise, it returns the value of val.equals(obj).

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare with. This must be dereferenced.
Returns:
true if this (or dereferenced term) is the same as the argument; false otherwise.
See Also:
val, compareTo(jp.ac.kobe_u.cs.prolog.lang.Term)

toString

public java.lang.String toString()
Returns a string representation of this term if unbound. Otherwise, returns the value of dereferenced term: val.toString()

Overrides:
toString in class java.lang.Object
See Also:
val

undo

public void undo()
Description copied from interface: Undoable
Undoes this object.

Specified by:
undo in interface Undoable
See Also:
Trail.unwind(int)

compareTo

public int compareTo(Term anotherTerm)
Compares two terms in Prolog standard order of terms.
It is noted that t1.compareTo(t2) == 0 has the same boolean value as t1.equals(t2).

Specified by:
compareTo in interface java.lang.Comparable<Term>
Parameters:
anotherTerm - the term to compare with. It must be dereferenced.
Returns:
the value 0 if two terms are identical; a value less than 0 if this term is before the anotherTerm; and a value greater than 0 if this term is after the anotherTerm.

Prolog Cafe v1.2

Copyright (C) 1997-2008 M.BANBARA and N.TAMURA