Class PrologTerm

java.lang.Object
com.igormaznitsa.prologparser.terms.PrologTerm
All Implemented Interfaces:
Serializable, Comparable<PrologTerm>
Direct Known Subclasses:
Op, PrologAtom, PrologCompound, PrologNumeric, PrologVar

public abstract class PrologTerm extends Object implements Serializable, Comparable<PrologTerm>
Base class describes a Prolog term
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • quotation

      protected final Quotation quotation
    • text

      protected final String text
    • line

      private int line
    • pos

      private int pos
  • Constructor Details

    • PrologTerm

      public PrologTerm(String text, Quotation quotation)
    • PrologTerm

      public PrologTerm(String text, Quotation quotation, int line, int pos)
  • Method Details

    • findQuotation

      public static Quotation findQuotation(String atomText)
      Find appropriate quotation for text.
      Parameters:
      atomText - text, must not be null
      Returns:
      founded quotation
    • assertNonEmptyString

      protected static String assertNonEmptyString(String str)
    • flatComma

      public List<PrologTerm> flatComma(List<PrologTerm> list)
      Flat content of the term for comma, make sense for structures.
      Parameters:
      list - list to be filled by comma separated terms
      Returns:
      the same list
    • getArity

      public int getArity()
      Arity of element.
      Returns:
      arity of element, make sense for compound terms, for primitive terms is 1
    • isAnyBlock

      public boolean isAnyBlock()
      Check the term describes '()' or '{}' block.
      Returns:
      true if the term is structure describes any kind of supported block
      Since:
      2.0.1
    • isBlock

      public boolean isBlock()
      Check the term describes '()' block.
      Returns:
      true if the term is structure with '()' as functor
    • isCurlyBlock

      public boolean isCurlyBlock()
      Check the term describes '{}' block.
      Returns:
      true if the term is structure with '{}' as functor
    • getQuotation

      public Quotation getQuotation()
      Get quotation for the term.
      Returns:
      the quotation for the term, must not be null
    • getPos

      public final int getPos()
      Position of the term in the line, first position is 1
      Returns:
      position in line or -1 if unknown
    • setPos

      public final void setPos(int pos)
    • getLine

      public final int getLine()
      Line of the term, first line is 1
      Returns:
      line or -1 if unknown
    • setLine

      public final void setLine(int line)
    • getText

      public String getText()
      Get the term text.
      Returns:
      the term text, must not be null
    • getPrecedence

      public int getPrecedence()
      Get precedence of the term.
      Returns:
      precedence, must not be negative
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getType

      public abstract TermType getType()
      Get term type.
      Returns:
      term type, must not be null
    • stream

      public Stream<PrologTerm> stream()
    • getFunctor

      public PrologTerm getFunctor()
      Get the functor, make sense of structure and its successors, for primitive returns the same term.
      Returns:
      functor for structure or the same term
    • compareTo

      public int compareTo(PrologTerm that)
      Specified by:
      compareTo in interface Comparable<PrologTerm>