se.sics.prologbeans
Class PBTerm

java.lang.Object
  extended by se.sics.prologbeans.PBTerm

public abstract class PBTerm
extends java.lang.Object

PBTerm is the Java representations of Prolog terms.


Field Summary
protected  java.lang.String name
           
static PBTerm NIL
          The PBTerm NIL, with the printname "[]", represents the empty list.
 
Method Summary
 java.math.BigInteger bigIntegerValue()
          Returns the BigInteger value of this PBTerm.
 double floatValue()
          Returns the floating-point value of this PBTerm.
 PBTerm getArgument(int index)
          Returns the argument at the specified index.
 int getArity()
          Returns the number of arguments of this compound term or 0 if this PBTerm is not a compound term.
 java.lang.String getName()
          Returns the name of this constant or compound term.
 java.lang.String getString()
          If this PBTerm is a proper list and all its elements are small integers (less than 256), returns a String with the list elements as the character codes of the String.
 PBTerm head()
          Returns the head of this PBTerm if it is a list cell, i.e.
 long intValue()
          Returns the integer value of this PBTerm.
 boolean isAtom()
          Returns true if this PBTerm is an atom and false otherwise.
 boolean isAtomic()
          Returns true if this PBTerm is a constant (e.g. integer, floating-point number, or atom) and false if this PBTerm is a compound term or variable.
 boolean isBignum()
          Returns true if this PBTerm is an bignum integer and false otherwise.
 boolean isCompound()
          Returns true if this PBTerm is a compund term and false otherwise.
 boolean isEmptyList()
          Returns true if this PBTerm is the empty list and false otherwise.
 boolean isFloat()
          Returns true if this PBTerm is a floating-point number and false otherwise.
 boolean isInteger()
          Returns true if this PBTerm is an integer and false otherwise.
 boolean isListCell()
          Returns true if this PBTerm is a list cell, i.e. a compound term with the functor ./2, and false otherwise.
 boolean isNumber()
          Returns true if this PBTerm is a number and false otherwise.
 boolean isProperList()
          Returns true if this PBTerm is a proper list and false otherwise.
 boolean isString()
          Returns true if this PBTerm is a proper list and all of its elements are character codes or one character atoms.
 boolean isVariable()
          Returns true if this PBTerm is a variable and false otherwise.
 int length()
          If this PBTerm is a proper list, returns its length.
static PBTerm makeAtom(java.lang.String value)
          Creates a new PBTerm instance representing an atom.
static PBTerm makeTerm(java.math.BigInteger value)
          Creates a new PBTerm instance representing a BigInteger value.
static PBTerm makeTerm(double value)
          Creates a new PBTerm instance representing a double value.
static PBTerm makeTerm(float value)
          Creates a new PBTerm instance representing a float value.
static PBTerm makeTerm(int value)
          Creates a new PBTerm instance representing an int value.
static PBTerm makeTerm(long value)
          Creates a new PBTerm instance representing a long value.
static PBTerm makeTerm(PBTerm head, PBTerm tail)
          Creates a new PBTerm instance representing a list cell.
static PBTerm makeTerm(java.lang.String value)
          Creates a new PBTerm instance representing a list with the characters, as integer values, in the string argument as its elements.
static PBTerm makeTerm(java.lang.String name, PBTerm[] arguments)
          Creates a new PBTerm instance representing a compound term.
protected  java.lang.String stuffAtom(java.lang.String atom)
           
 PBTerm tail()
          Returns the tail of this PBTerm if it is a list cell, i.e.
abstract  java.lang.String toString()
          Returns a string description of this term.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NIL

public static final PBTerm NIL
The PBTerm NIL, with the printname "[]", represents the empty list.


name

protected final java.lang.String name
Method Detail

isAtom

public boolean isAtom()
Returns true if this PBTerm is an atom and false otherwise.


isAtomic

public boolean isAtomic()
Returns true if this PBTerm is a constant (e.g. integer, floating-point number, or atom) and false if this PBTerm is a compound term or variable.


isNumber

public boolean isNumber()
Returns true if this PBTerm is a number and false otherwise.


isInteger

public boolean isInteger()
Returns true if this PBTerm is an integer and false otherwise.


isBignum

public boolean isBignum()
Returns true if this PBTerm is an bignum integer and false otherwise.


isFloat

public boolean isFloat()
Returns true if this PBTerm is a floating-point number and false otherwise.


isCompound

public boolean isCompound()
Returns true if this PBTerm is a compund term and false otherwise.


isListCell

public boolean isListCell()
Returns true if this PBTerm is a list cell, i.e. a compound term with the functor ./2, and false otherwise.


isProperList

public boolean isProperList()
Returns true if this PBTerm is a proper list and false otherwise.


isEmptyList

public boolean isEmptyList()
Returns true if this PBTerm is the empty list and false otherwise.


isString

public boolean isString()
Returns true if this PBTerm is a proper list and all of its elements are character codes or one character atoms. Returns false otherwise.


head

public PBTerm head()
Returns the head of this PBTerm if it is a list cell, i.e. a compound term with the functor ./2.

Throws:
{@if.java - java.lang. }IllegalStateException if this PBTerm is not a list cell.

tail

public PBTerm tail()
Returns the tail of this PBTerm if it is a list cell, i.e. a compound term with the functor ./2.

Throws:
{@if.java - java.lang. }IllegalStateException if this PBTerm is not a list cell.

isVariable

public boolean isVariable()
Returns true if this PBTerm is a variable and false otherwise.


getName

public java.lang.String getName()
Returns the name of this constant or compound term.


getArgument

public PBTerm getArgument(int index)
Returns the argument at the specified index. Only compound terms have arguments.
Note: the arguments are indexed from 1 to arity.

Parameters:
index - the (one based) index of the argument
Returns:
the argument as a PBTerm
Throws:
{@if.java - java.lang. }IllegalStateException if this term is not compound

length

public int length()
If this PBTerm is a proper list, returns its length.

Throws:
{@if.java - java.lang. }IllegalStateException if this PBTerm is not a proper list.

getArity

public int getArity()
Returns the number of arguments of this compound term or 0 if this PBTerm is not a compound term.


intValue

public long intValue()
Returns the integer value of this PBTerm.

Throws:
{@if.java - java.lang. }IllegalStateException if this PBTerm is not an integer.

bigIntegerValue

public java.math.BigInteger bigIntegerValue()
Returns the BigInteger value of this PBTerm.

Throws:
{@if.java - java.lang. }IllegalStateException if this PBTerm is not a bignum integer.
See Also:
BigInteger

floatValue

public double floatValue()
Returns the floating-point value of this PBTerm.

Throws:
{@if.java - java.lang. }IllegalStateException if this PBTerm is not a number.

getString

public java.lang.String getString()
If this PBTerm is a proper list and all its elements are small integers (less than 256), returns a String with the list elements as the character codes of the String.

Throws:
{@if.java - java.lang. }IllegalStateException if this PBTerm is not a proper list.

toString

public abstract java.lang.String toString()
Returns a string description of this term.

Overrides:
toString in class java.lang.Object

makeTerm

public static PBTerm makeTerm(float value)
Creates a new PBTerm instance representing a float value.


makeTerm

public static PBTerm makeTerm(double value)
Creates a new PBTerm instance representing a double value.


makeTerm

public static PBTerm makeTerm(int value)
Creates a new PBTerm instance representing an int value.


makeTerm

public static PBTerm makeTerm(long value)
Creates a new PBTerm instance representing a long value.


makeTerm

public static PBTerm makeTerm(java.math.BigInteger value)
Creates a new PBTerm instance representing a BigInteger value.


makeTerm

public static PBTerm makeTerm(java.lang.String value)
Creates a new PBTerm instance representing a list with the characters, as integer values, in the string argument as its elements.


makeTerm

public static PBTerm makeTerm(java.lang.String name,
                              PBTerm[] arguments)
Creates a new PBTerm instance representing a compound term.


makeTerm

public static PBTerm makeTerm(PBTerm head,
                              PBTerm tail)
Creates a new PBTerm instance representing a list cell.


makeAtom

public static PBTerm makeAtom(java.lang.String value)
Creates a new PBTerm instance representing an atom.


stuffAtom

protected java.lang.String stuffAtom(java.lang.String atom)