Class PrologTerm
- java.lang.Object
-
- com.igormaznitsa.prologparser.terms.PrologTerm
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<PrologTerm>
- Direct Known Subclasses:
Op,PrologAtom,PrologCompound,PrologNumeric,PrologVar
public abstract class PrologTerm extends java.lang.Object implements java.io.Serializable, java.lang.Comparable<PrologTerm>
Base class describes a Prolog term- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description PrologTerm(java.lang.String text, Quotation quotation)PrologTerm(java.lang.String text, Quotation quotation, int line, int pos)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static java.lang.StringassertNonEmptyString(java.lang.String str)intcompareTo(PrologTerm that)static QuotationfindQuotation(java.lang.String atomText)Find appropriate quotation for text.java.util.List<PrologTerm>flatComma(java.util.List<PrologTerm> list)Flat content of the term for comma, make sense for structures.intgetArity()Arity of element.PrologTermgetFunctor()Get the functor, make sense of structure and its successors, for primitive returns the same term.intgetLine()Line of the term, first line is 1intgetPos()Position of the term in the line, first position is 1intgetPrecedence()Get precedence of the term.QuotationgetQuotation()Get quotation for the term.java.lang.StringgetText()Get the term text.abstract TermTypegetType()Get term type.booleanisAnyBlock()Check the term describes '()' or '{}' block.booleanisBlock()Check the term describes '()' block.booleanisCurlyBlock()Check the term describes '{}' block.voidsetLine(int line)voidsetPos(int pos)java.util.stream.Stream<PrologTerm>stream()java.lang.StringtoString()
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
quotation
protected final Quotation quotation
-
text
protected final java.lang.String text
-
line
private int line
-
pos
private int pos
-
-
Method Detail
-
findQuotation
public static Quotation findQuotation(java.lang.String atomText)
Find appropriate quotation for text.- Parameters:
atomText- text, must not be null- Returns:
- founded quotation
-
assertNonEmptyString
protected static java.lang.String assertNonEmptyString(java.lang.String str)
-
flatComma
public java.util.List<PrologTerm> flatComma(java.util.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 java.lang.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 java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getType
public abstract TermType getType()
Get term type.- Returns:
- term type, must not be null
-
stream
public java.util.stream.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:
compareToin interfacejava.lang.Comparable<PrologTerm>
-
-