se.sics.jasper
Interface Term

All Known Implementing Classes:
SPTerm

public interface Term

Terms are Java representations of Prolog terms. See SPTerm for more information on the implementation.


Field Summary
static int TYPE_ATOM
          The term is an atom.
static int TYPE_COMPOUND
          The term is a compound term.
static int TYPE_FLOAT
          The term is a float.
static int TYPE_INTEGER
          The term is an integer.
static int TYPE_VARIABLE
          The term is a variable.
 
Method Summary
 int compare(Term with)
          Compares two terms according to standard order.
 void delete()
          Invalidates the Term object and make the SP_term_ref available for re-use.
 Term getArg(int i, Term arg)
          Gets an argument from a compound term.
 double getDouble()
          Obtains the value of the Prolog float.
 int getFunctorArity()
          Obtains the arity of a functor.
 java.lang.String getFunctorName()
          Obtains the name of a functor.
 long getInteger()
          Obtains the integer value of the Prolog term.
 Term getList(Term head, Term tail)
          Gets the head and tail of a Prolog list.
 java.lang.String getListChars()
          Obtains the value of a list of characters as a string.
 java.lang.String getNumberChars()
          Obtains the value of a Prolog number as a string.
 java.lang.Object getObject()
          Returns the object encapsulated in the Prolog term.
 java.lang.String getString()
          Obtains the value of the Prolog atom as a string.
 boolean isAtom()
          Tests if the term is an atom.
 boolean isAtomic()
          Tests if the term is atomic.
 boolean isCompound()
          Tests if the term is a compound term.
 boolean isEmptyList()
          Tests if the term is the empty list.
 boolean isFloat()
          Tests if the term is a float.
 boolean isInteger()
          Tests if the term is an integer.
 boolean isList()
          Tests if the term is a list cell.
 boolean isNumber()
          Tests if the term is a number.
 boolean isValid()
          Tests if the Prolog term referenced is still accessible through this object.
 boolean isVariable()
          Tests if the term is a variable.
 Term[] toPrologTermArray()
          Converts a list to an array of Terms.
 java.lang.String toString()
          Returns a string-respresentation of a term.
 java.lang.String toString(Term options)
          Returns a string-representation of a term.
 int type()
          Returns the type of this term.
 boolean unify(Term with)
          Unifies the term with another term.
 

Field Detail

TYPE_VARIABLE

static final int TYPE_VARIABLE
The term is a variable.

See Also:
type(), Constant Field Values

TYPE_INTEGER

static final int TYPE_INTEGER
The term is an integer.

See Also:
type(), Constant Field Values

TYPE_ATOM

static final int TYPE_ATOM
The term is an atom.

See Also:
type(), Constant Field Values

TYPE_FLOAT

static final int TYPE_FLOAT
The term is a float.

See Also:
type(), Constant Field Values

TYPE_COMPOUND

static final int TYPE_COMPOUND
The term is a compound term.

See Also:
type(), Constant Field Values
Method Detail

compare

int compare(Term with)
            throws IllegalTermException,
                   java.lang.Exception
Compares two terms according to standard order.

Parameters:
with - The term to compare with.
Returns:
-1 if x < y, 0 if x == y, and 1 if x > y.
Throws:
IllegalTermException
java.lang.Exception

delete

void delete()
            throws java.lang.Exception
Invalidates the Term object and make the SP_term_ref available for re-use. Accessing an invalid Term object throws IllegalTermException.

Throws:
java.lang.Exception

getArg

Term getArg(int i,
            Term arg)
            throws java.lang.InterruptedException,
                   java.lang.Exception
Gets an argument from a compound term. Similar to calling arg/3 with the third argument unbound.

Parameters:
i - The number of the argument.
arg - The term to which the ith argument will be assigned.
Returns:
A reference to itself.
Throws:
java.lang.InterruptedException
java.lang.Exception

getDouble

double getDouble()
                 throws ConversionFailedException,
                        IllegalTermException,
                        java.lang.Exception
Obtains the value of the Prolog float.

Returns:
The value of the Prolog float as a Java double.
Throws:
ConversionFailedException - The term could not be converted to a double.
IllegalTermException
java.lang.Exception

getFunctorArity

int getFunctorArity()
                    throws ConversionFailedException,
                           IllegalTermException,
                           java.lang.Exception
Obtains the arity of a functor.

Returns:
The arity of a functor as a Java int.
Throws:
ConversionFailedException - The term could not be converted to the arity of a functor.
IllegalTermException
java.lang.Exception

getFunctorName

java.lang.String getFunctorName()
                                throws ConversionFailedException,
                                       IllegalTermException,
                                       java.lang.Exception
Obtains the name of a functor.

Returns:
The functor as a Java String.
Throws:
ConversionFailedException - The term could not be converted to the name of a functor.
IllegalTermException
java.lang.Exception

getInteger

long getInteger()
                throws java.lang.Exception
Obtains the integer value of the Prolog term.

Returns:
The value of the Prolog term as a Java long.
Throws:
java.lang.Exception

getList

Term getList(Term head,
             Term tail)
             throws java.lang.InterruptedException,
                    java.lang.Exception
Gets the head and tail of a Prolog list.

Parameters:
head - The term which will be assigned the head
tail - The term which will be assigned the tail
Returns:
A reference to itself.
Throws:
java.lang.InterruptedException
java.lang.Exception

getListChars

java.lang.String getListChars()
                              throws java.lang.Exception
Obtains the value of a list of characters as a string.

Returns:
The value of the list as a Java String.
Throws:
java.lang.Exception

getNumberChars

java.lang.String getNumberChars()
                                throws java.lang.Exception
Obtains the value of a Prolog number as a string.

Returns:
The value of the number as a Java String.
Throws:
java.lang.Exception

getObject

java.lang.Object getObject()
                           throws java.lang.Exception
Returns the object encapsulated in the Prolog term. In multi-threaded Jasper, this method should only be called on terms created with the method Prolog.newObjectTerm(java.lang.Object).

See SPTerm.getObject() for documentation on the single threaded implementation.

Returns:
A Java object
Throws:
java.lang.Exception

getString

java.lang.String getString()
                           throws java.lang.Exception
Obtains the value of the Prolog atom as a string.

Returns:
The value of the Prolog atom as a Java String.
Throws:
java.lang.Exception

isAtom

boolean isAtom()
               throws java.lang.Exception
Tests if the term is an atom.

Returns:
true if the term is an atom; false otherwise
Throws:
java.lang.Exception

isAtomic

boolean isAtomic()
                 throws java.lang.Exception
Tests if the term is atomic. A term is atomic if it is instantiated to an atom or a number.

Returns:
true if the term is atomic; false otherwise
Throws:
java.lang.Exception

isCompound

boolean isCompound()
                   throws java.lang.Exception
Tests if the term is a compound term.

Returns:
true if the term is a compound term; false otherwise
Throws:
java.lang.Exception

isEmptyList

boolean isEmptyList()
                    throws java.lang.Exception
Tests if the term is the empty list.

Returns:
true if the term is the atom []; false otherwise
Throws:
java.lang.Exception

isFloat

boolean isFloat()
                throws java.lang.Exception
Tests if the term is a float.

Returns:
true if the term is a float; false otherwise
Throws:
java.lang.Exception

isInteger

boolean isInteger()
                  throws java.lang.Exception
Tests if the term is an integer.

Returns:
true if the term is an integer; false otherwise
Throws:
java.lang.Exception

isList

boolean isList()
               throws java.lang.Exception
Tests if the term is a list cell. Equivalent to the Prolog code isList(T) :- nonvar(T), T=[_|_].

Returns:
true if the term is a list cell; false otherwise
Throws:
java.lang.Exception

isNumber

boolean isNumber()
                 throws java.lang.Exception
Tests if the term is a number. A number is a term instantiated to an integer or a float.

Returns:
true if the term is a number; false otherwise
Throws:
java.lang.Exception

isValid

boolean isValid()
                throws java.lang.Exception
Tests if the Prolog term referenced is still accessible through this object. Term object becomes invalid as the result of of explicit delete, closing, cutting or asking for the nextSolution of an enclosing SPQuery.

Returns:
true if still valid; false otherwise.
Throws:
java.lang.Exception

isVariable

boolean isVariable()
                   throws java.lang.Exception
Tests if the term is a variable.

Returns:
true if the term is a variable; false otherwise
Throws:
java.lang.Exception

toString

java.lang.String toString()
Returns a string-respresentation of a term.

Overrides:
toString in class java.lang.Object

toString

java.lang.String toString(Term options)
                          throws SPException,
                                 java.lang.Exception
Returns a string-representation of a term. This is an interface to write_term/3, which see.

Throws:
SPException
java.lang.Exception

toPrologTermArray

Term[] toPrologTermArray()
                         throws java.lang.Exception
Converts a list to an array of Terms. Useful when examining lists returned from Prolog queries. This is of course only possible on a list.

Returns:
An array of the terms.
Throws:
java.lang.Exception

type

int type()
         throws java.lang.Exception
Returns the type of this term. The return value is as defined by the constants TYPE_INTEGER, TYPE_FLOAT, TYPE_ATOM, TYPE_VARIABLE, and TYPE_COMPOUND

Throws:
java.lang.Exception
See Also:
TYPE_INTEGER, TYPE_ATOM, TYPE_FLOAT, TYPE_VARIABLE, TYPE_COMPOUND, isVariable(), isInteger(), isAtom(), isFloat(), isCompound(), isList(), isAtomic(), isNumber()

unify

boolean unify(Term with)
              throws java.lang.Exception
Unifies the term with another term.

Parameters:
with - The term with which to unify.
Returns:
True/False depending on whether the unification succeeded.
Throws:
java.lang.Exception