jason.asSyntax
Class ListTermImpl

Package class diagram package ListTermImpl
java.lang.Object
  extended by jason.asSyntax.DefaultTerm
      extended by jason.asSyntax.Literal
          extended by jason.asSyntax.Atom
              extended by jason.asSyntax.Structure
                  extended by jason.asSyntax.ListTermImpl
All Implemented Interfaces:
ListTerm, LogicalFormula, Term, ToDOM, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Term>, java.lang.Iterable<Term>, java.util.Collection<Term>, java.util.List<Term>

public class ListTermImpl
extends Structure
implements ListTerm

Represents a list node as in prolog .(t1,.(t2,.(t3,.))). Each nth-ListTerm has both a term and the next ListTerm. The last ListTem is an empty ListTerm (term==null). In lists terms with a tail ([a|X]), next is the Tail (next==X, term==a).

See Also:
Serialized Form

Field Summary
static java.lang.String LIST_FUNCTOR
           
 
Fields inherited from class jason.asSyntax.Structure
emptyTermArray, emptyTermList
 
Fields inherited from class jason.asSyntax.Literal
LFalse, LNeg, LPos, LTrue, predicateIndicatorCache
 
Fields inherited from class jason.asSyntax.DefaultTerm
hashCodeCache, srcInfo
 
Constructor Summary
ListTermImpl()
           
 
Method Summary
 void add(int index, Term o)
           
 boolean add(Term o)
           
 boolean addAll(java.util.Collection c)
           
 boolean addAll(int index, java.util.Collection c)
           
 void addTerm(Term t)
           
 ListTerm append(Term t)
          Adds a term in the end of the list
 boolean apply(Unifier u)
          replaces variables by their values in the unifier, returns true if some variable was applied
 int calcHashCode()
           
 void clear()
           
 ListTerm clone()
          make a hard copy of the terms
 ListTerm cloneLT()
          make a hard copy of the terms
 ListTerm cloneLTShallow()
          make a shallow copy of the list (terms are not cloned, only the structure)
 int compareTo(Term o)
           
 ListTerm concat(ListTerm lt)
          Adds a list in the end of this list.
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection c)
           
 ListTerm difference(ListTerm lt)
          returns a new (cloned) list representing the set resulting of the difference of this list and lt.
 boolean equals(java.lang.Object t)
           
 Term get(int index)
           
 int getArity()
          returns the number of terms of this literal
 org.w3c.dom.Element getAsDOM(org.w3c.dom.Document document)
          get as XML
 java.util.List<Term> getAsList()
          Returns this ListTerm as a Java List (implemented by ArrayList).
 ListTerm getLast()
          get the last ListTerm of this List
 ListTerm getNext()
           
 ListTerm getPenultimate()
           
 VarTerm getTail()
          returns this ListTerm's tail element in case the List has the Tail, otherwise, returns null
 Term getTerm()
          gets the term of this ListTerm
 Term getTerm(int i)
          returns the i-th term (first term is 0)
 java.util.List<Term> getTerms()
          return the this ListTerm elements (0=Term, 1=ListTerm)
 int indexOf(java.lang.Object o)
           
 ListTerm insert(Term t)
          insert a term in the begin of this list
 ListTerm intersection(ListTerm lt)
          returns a new (cloned) list representing the set resulting of the intersection of this list and lt.
 boolean isAtom()
           
 boolean isEmpty()
           
 boolean isEnd()
           
 boolean isGround()
           
 boolean isList()
           
 boolean isLiteral()
           
 boolean isTail()
           
 java.util.Iterator<Term> iterator()
          returns an iterator where each element is a Term of this list, the tail of the list is not considered.
 int lastIndexOf(java.lang.Object arg0)
           
 java.util.ListIterator<Term> listIterator()
           
 java.util.ListIterator<Term> listIterator(int startIndex)
           
 java.util.Iterator<ListTerm> listTermIterator()
          gives an iterator that includes the final empty list or tail, for [a,b,c] returns [a,b,c]; [b,c]; [c]; and [].
 java.util.Iterator<Unifier> logicalConsequence(Agent ag, Unifier un)
          logicalConsequence checks whether one particular predicate is a logical consequence of the belief base.
static ListTerm parseList(java.lang.String sList)
           
 Term remove(int index)
           
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection c)
           
 Term removeLast()
           
 boolean retainAll(java.util.Collection c)
           
 ListTerm reverse()
          Creates a new (cloned) list with the same elements of this list, but in the reversed order.
 Term set(int index, Term t)
           
 void setNext(Term l)
           
 void setTail(VarTerm v)
          set the tail of this list
 void setTerm(int i, Term t)
           
 void setTerm(Term t)
           
protected  void setValuesFrom(ListTerm lt)
           
 int size()
           
 java.util.List<Term> subList(int arg0, int arg1)
           
 java.util.Iterator<java.util.List<Term>> subSets(int k)
          returns all subsets that take k elements of this list
 java.lang.Object[] toArray()
           
<T> T[]
toArray(T[] a)
           
 java.lang.String toString()
           
 ListTerm union(ListTerm lt)
          returns a new (cloned) list representing the set resulting of the union of this list and lt.
 
Methods inherited from class jason.asSyntax.Structure
addTerms, addTerms, countVars, delTerm, getSingletonVars, getTermsSize, hasTerm, hasVar, isStructure, makeTermsAnnon, makeVarsAnnon, makeVarsAnnon, parse, setTerms, varToReplace
 
Methods inherited from class jason.asSyntax.Atom
getFunctor
 
Methods inherited from class jason.asSyntax.Literal
addAnnot, addAnnots, addAnnots, addSource, canBeAddedInBB, clearAnnots, copy, delAnnot, delAnnots, delSource, delSources, equalsAsStructure, forceFullLiteralImpl, getAnnots, getAnnots, getAsListOfTerms, getPredicateIndicator, getSources, getTermsArray, hasAnnot, hasAnnot, hasSource, hasSource, hasSubsetAnnot, hasSubsetAnnot, importAnnots, negated, newFromListOfTerms, parseLiteral, setAnnots, setNegated
 
Methods inherited from class jason.asSyntax.DefaultTerm
getErrorMsg, getSrcInfo, hashCode, isArithExpr, isInternalAction, isNumeric, isPlanBody, isPred, isRule, isString, isUnnamedVar, isVar, resetHashCodeCache, setSrcInfo
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
hashCode
 
Methods inherited from interface jason.asSyntax.Term
countVars, getSrcInfo, hasVar, isArithExpr, isInternalAction, isNumeric, isPlanBody, isPred, isRule, isString, isStructure, isUnnamedVar, isVar, setSrcInfo
 

Field Detail

LIST_FUNCTOR

public static final java.lang.String LIST_FUNCTOR
See Also:
Constant Field Values
Constructor Detail

ListTermImpl

public ListTermImpl()
Method Detail

parseList

public static ListTerm parseList(java.lang.String sList)

clone

public ListTerm clone()
make a hard copy of the terms

Specified by:
clone in interface Term
Overrides:
clone in class Structure

cloneLT

public ListTerm cloneLT()
make a hard copy of the terms

Specified by:
cloneLT in interface ListTerm

cloneLTShallow

public ListTerm cloneLTShallow()
make a shallow copy of the list (terms are not cloned, only the structure)

Specified by:
cloneLTShallow in interface ListTerm

equals

public boolean equals(java.lang.Object t)
Specified by:
equals in interface Term
Specified by:
equals in interface java.util.Collection<Term>
Specified by:
equals in interface java.util.List<Term>
Overrides:
equals in class Structure

calcHashCode

public int calcHashCode()
Overrides:
calcHashCode in class Structure

compareTo

public int compareTo(Term o)
Specified by:
compareTo in interface java.lang.Comparable<Term>
Overrides:
compareTo in class Structure

setTerm

public void setTerm(Term t)
Specified by:
setTerm in interface ListTerm

getTerm

public Term getTerm()
gets the term of this ListTerm

Specified by:
getTerm in interface ListTerm

setNext

public void setNext(Term l)
Specified by:
setNext in interface ListTerm

getNext

public ListTerm getNext()
Specified by:
getNext in interface ListTerm

getArity

public int getArity()
Description copied from class: Literal
returns the number of terms of this literal

Overrides:
getArity in class Structure

getTerm

public Term getTerm(int i)
Description copied from class: Literal
returns the i-th term (first term is 0)

Overrides:
getTerm in class Structure

setTerm

public void setTerm(int i,
                    Term t)
Overrides:
setTerm in class Structure

getTerms

public java.util.List<Term> getTerms()
return the this ListTerm elements (0=Term, 1=ListTerm)

Overrides:
getTerms in class Structure

addTerm

public void addTerm(Term t)
Overrides:
addTerm in class Structure

size

public int size()
Specified by:
size in interface java.util.Collection<Term>
Specified by:
size in interface java.util.List<Term>

isAtom

public boolean isAtom()
Specified by:
isAtom in interface Term
Overrides:
isAtom in class Structure

isList

public boolean isList()
Specified by:
isList in interface Term
Overrides:
isList in class DefaultTerm

isLiteral

public boolean isLiteral()
Specified by:
isLiteral in interface Term
Overrides:
isLiteral in class Literal

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection<Term>
Specified by:
isEmpty in interface java.util.List<Term>

isEnd

public boolean isEnd()
Specified by:
isEnd in interface ListTerm

isGround

public boolean isGround()
Specified by:
isGround in interface Term
Overrides:
isGround in class Structure

apply

public boolean apply(Unifier u)
Description copied from interface: Term
replaces variables by their values in the unifier, returns true if some variable was applied

Specified by:
apply in interface Term
Overrides:
apply in class Structure

logicalConsequence

public java.util.Iterator<Unifier> logicalConsequence(Agent ag,
                                                      Unifier un)
Description copied from class: Literal
logicalConsequence checks whether one particular predicate is a logical consequence of the belief base. Returns an iterator for all unifiers that are logCons.

Specified by:
logicalConsequence in interface LogicalFormula
Overrides:
logicalConsequence in class Literal

isTail

public boolean isTail()
Specified by:
isTail in interface ListTerm

getTail

public VarTerm getTail()
returns this ListTerm's tail element in case the List has the Tail, otherwise, returns null

Specified by:
getTail in interface ListTerm

setTail

public void setTail(VarTerm v)
set the tail of this list

Specified by:
setTail in interface ListTerm

getLast

public ListTerm getLast()
get the last ListTerm of this List

Specified by:
getLast in interface ListTerm

getPenultimate

public ListTerm getPenultimate()
Specified by:
getPenultimate in interface ListTerm

removeLast

public Term removeLast()
Specified by:
removeLast in interface ListTerm

append

public ListTerm append(Term t)
Adds a term in the end of the list

Specified by:
append in interface ListTerm
Returns:
the ListTerm where the term was added (i.e. the last ListTerm of the list)

insert

public ListTerm insert(Term t)
insert a term in the begin of this list

Specified by:
insert in interface ListTerm
Returns:
the new starter of the list

concat

public ListTerm concat(ListTerm lt)
Adds a list in the end of this list. This method do not clone lt.

Specified by:
concat in interface ListTerm
Returns:
the last ListTerm of the new list

reverse

public ListTerm reverse()
Creates a new (cloned) list with the same elements of this list, but in the reversed order. The Tail remains the Tail: reverse([a,b|T]) = [b,a|T].

Specified by:
reverse in interface ListTerm

union

public ListTerm union(ListTerm lt)
returns a new (cloned) list representing the set resulting of the union of this list and lt.

Specified by:
union in interface ListTerm

intersection

public ListTerm intersection(ListTerm lt)
returns a new (cloned) list representing the set resulting of the intersection of this list and lt.

Specified by:
intersection in interface ListTerm

difference

public ListTerm difference(ListTerm lt)
returns a new (cloned) list representing the set resulting of the difference of this list and lt.

Specified by:
difference in interface ListTerm

subSets

public java.util.Iterator<java.util.List<Term>> subSets(int k)
returns all subsets that take k elements of this list

Specified by:
subSets in interface ListTerm

listTermIterator

public java.util.Iterator<ListTerm> listTermIterator()
gives an iterator that includes the final empty list or tail, for [a,b,c] returns [a,b,c]; [b,c]; [c]; and []. for [a,b|T] returns [a,b|T]; [b|T]; [b|T]; and T.

Specified by:
listTermIterator in interface ListTerm

iterator

public java.util.Iterator<Term> iterator()
returns an iterator where each element is a Term of this list, the tail of the list is not considered. for [a,b,c] returns 'a', 'b', and 'c'. for [a,b|T] returns 'a' and 'b'.

Specified by:
iterator in interface java.lang.Iterable<Term>
Specified by:
iterator in interface java.util.Collection<Term>
Specified by:
iterator in interface java.util.List<Term>

getAsList

public java.util.List<Term> getAsList()
Returns this ListTerm as a Java List (implemented by ArrayList). Note: the tail of the list, if any, is not included!

Specified by:
getAsList in interface ListTerm

toString

public java.lang.String toString()
Overrides:
toString in class Structure

add

public void add(int index,
                Term o)
Specified by:
add in interface java.util.List<Term>

add

public boolean add(Term o)
Specified by:
add in interface java.util.Collection<Term>
Specified by:
add in interface java.util.List<Term>

addAll

public boolean addAll(java.util.Collection c)
Specified by:
addAll in interface java.util.Collection<Term>
Specified by:
addAll in interface java.util.List<Term>

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Specified by:
addAll in interface java.util.List<Term>

clear

public void clear()
Specified by:
clear in interface java.util.Collection<Term>
Specified by:
clear in interface java.util.List<Term>

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection<Term>
Specified by:
contains in interface java.util.List<Term>

containsAll

public boolean containsAll(java.util.Collection c)
Specified by:
containsAll in interface java.util.Collection<Term>
Specified by:
containsAll in interface java.util.List<Term>

get

public Term get(int index)
Specified by:
get in interface java.util.List<Term>

indexOf

public int indexOf(java.lang.Object o)
Specified by:
indexOf in interface java.util.List<Term>

lastIndexOf

public int lastIndexOf(java.lang.Object arg0)
Specified by:
lastIndexOf in interface java.util.List<Term>

listIterator

public java.util.ListIterator<Term> listIterator()
Specified by:
listIterator in interface java.util.List<Term>

listIterator

public java.util.ListIterator<Term> listIterator(int startIndex)
Specified by:
listIterator in interface java.util.List<Term>

setValuesFrom

protected void setValuesFrom(ListTerm lt)

remove

public Term remove(int index)
Specified by:
remove in interface java.util.List<Term>

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection<Term>
Specified by:
remove in interface java.util.List<Term>

removeAll

public boolean removeAll(java.util.Collection c)
Specified by:
removeAll in interface java.util.Collection<Term>
Specified by:
removeAll in interface java.util.List<Term>

retainAll

public boolean retainAll(java.util.Collection c)
Specified by:
retainAll in interface java.util.Collection<Term>
Specified by:
retainAll in interface java.util.List<Term>

set

public Term set(int index,
                Term t)
Specified by:
set in interface java.util.List<Term>

subList

public java.util.List<Term> subList(int arg0,
                                    int arg1)
Specified by:
subList in interface java.util.List<Term>

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection<Term>
Specified by:
toArray in interface java.util.List<Term>

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface java.util.Collection<Term>
Specified by:
toArray in interface java.util.List<Term>

getAsDOM

public org.w3c.dom.Element getAsDOM(org.w3c.dom.Document document)
Description copied from class: Structure
get as XML

Specified by:
getAsDOM in interface ToDOM
Overrides:
getAsDOM in class Structure