se.sics.prologbeans
Class PBList

java.lang.Object
  |
  +--se.sics.prologbeans.Term
        |
        +--se.sics.prologbeans.PBCompound
              |
              +--se.sics.prologbeans.PBList
Direct Known Subclasses:
PBString

public class PBList
extends PBCompound

PBList is the Java representation of Prolog lists.


Field Summary
protected  Term nextTerm
           
 
Fields inherited from class se.sics.prologbeans.PBCompound
arguments
 
Fields inherited from class se.sics.prologbeans.Term
name
 
Method Summary
 Term getArgument(int index)
          Returns the first or second argument of this list node.
 int getArity()
          Returns the number of arguments of this compound term or 0 if this term is not a compound term.
 Term getEnd()
          Returns the end of this list.
 int getLength()
          Returns the length of this PBList.
 Term getTermAt(int index)
          Returns the element at the specified index in this list.
 boolean isList()
          Returns true if this term is a list and false otherwise.
 java.lang.String toString()
          Returns a string description of this term.
 
Methods inherited from class se.sics.prologbeans.PBCompound
isAtom, isAtomic
 
Methods inherited from class se.sics.prologbeans.Term
doubleValue, floatValue, getName, intValue, isCompound, isFloat, isInteger, isString, isVariable, longValue, stuffAtom
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nextTerm

protected final Term nextTerm
Method Detail

isList

public boolean isList()
Description copied from class: Term
Returns true if this term is a list and false otherwise.
Overrides:
isList in class Term

getArgument

public Term getArgument(int index)
Returns the first or second argument of this list node. Only non-empty lists have arguments. Note: the arguments are indexed from 1 to 2.

Due to performance reasons this should be avoided if not 100% necessary. Please use getTermAt(int index) for accessing the elements of lists.

Overrides:
getArgument in class PBCompound
Parameters:
index - the (one based) index of the argument
Returns:
the argument as a Term
Throws:
java.lang.IllegalStateException - if this term is not compound
See Also:
getTermAt(int)

getArity

public int getArity()
Description copied from class: Term
Returns the number of arguments of this compound term or 0 if this term is not a compound term.
Overrides:
getArity in class PBCompound

getLength

public int getLength()
Returns the length of this PBList.

Please note: this does not correspond to the prolog predicate length/1.

See Also:
Example of how to traverse a PBList.

getTermAt

public Term getTermAt(int index)
Returns the element at the specified index in this list. Note: the elements are indexed from 1 to length.
Parameters:
index - the (one based) index of the element in this list
Returns:
the element as a Term
See Also:
getLength()

getEnd

public Term getEnd()
Returns the end of this list. For closed lists this element is the empty list.

toString

public java.lang.String toString()
Description copied from class: Term
Returns a string description of this term.
Overrides:
toString in class PBCompound