Class ListTermImpl

All Implemented Interfaces:
ListTerm, LogicalFormula, Term, ToDOM, ToJson, 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).
Author:
Jomi
See Also:
Serialized Form
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
      Constant Field Values
    • logger

      private static java.util.logging.Logger logger
    • LIST_FUNCTOR

      public static final java.lang.String LIST_FUNCTOR
      See Also:
      Constant Field Values
    • term

      private Term term
    • next

      private Term next
  • Constructor Details

    • ListTermImpl

      public ListTermImpl()
    • ListTermImpl

      private ListTermImpl​(Term t, Term n)
  • Method Details

    • 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
    • capply

      public ListTerm capply​(Unifier u)
      make a hard copy of the terms
      Specified by:
      capply in interface Term
      Overrides:
      capply in class Structure
    • 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 java.util.Collection<Term>
      Specified by:
      equals in interface java.util.List<Term>
      Specified by:
      equals in interface 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 Atom
    • 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
    • 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
    • reverse_internal

      private ListTerm reverse_internal​(ListTerm r)
    • 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
    • setToList

      private ListTerm setToList​(java.util.Set<Term> set)
    • 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.util.Collection<Term>
      Specified by:
      iterator in interface java.lang.Iterable<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
    • getAsJson

      public javax.json.JsonValue getAsJson()
      Specified by:
      getAsJson in interface ToJson
      Overrides:
      getAsJson in class Literal