Class PrologStruct
- java.lang.Object
-
- com.igormaznitsa.prologparser.terms.PrologTerm
-
- com.igormaznitsa.prologparser.terms.PrologCompound
-
- com.igormaznitsa.prologparser.terms.PrologStruct
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<PrologTerm>,java.lang.Iterable<PrologTerm>
- Direct Known Subclasses:
PrologList
public class PrologStruct extends PrologCompound implements java.lang.Iterable<PrologTerm>
Representation of prolog structure.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected PrologTerm[]elementsstatic PrologAtomEMPTY_ATOMprotected PrologTermfunctorprivate static longserialVersionUID-
Fields inherited from class com.igormaznitsa.prologparser.terms.PrologTerm
quotation, text
-
-
Constructor Summary
Constructors Modifier Constructor Description PrologStruct(PrologTerm functor)protectedPrologStruct(PrologTerm functor, int arity)PrologStruct(PrologTerm functor, int line, int pos)protectedPrologStruct(PrologTerm functor, int arity, int line, int pos)PrologStruct(PrologTerm functor, PrologTerm[] elements)PrologStruct(PrologTerm functor, PrologTerm[] elements, int line, int pos)PrologStruct(java.lang.String text)PrologStruct(java.lang.String text, int line, int pos)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static PrologTermassertFunctor(PrologTerm functor)PrologStructcopyWithAnotherFunctor(PrologTerm newFunctor)Make copy of the structure with replacement of functor.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.intgetPrecedence()Get precedence of the term.PrologTermgetTermAt(int index)Get element for its positionTermTypegetType()Get term type.booleanisAnyBlock()Check the term describes '()' or '{}' block.booleanisBlock()Check the term describes '()' block.booleanisCurlyBlock()Check the term describes '{}' block.booleanisEmpty()Check that the structure has elements.java.util.Iterator<PrologTerm>iterator()voidsetElementAt(int index, PrologTerm term)Set element for its position.java.util.stream.Stream<PrologTerm>stream()java.lang.StringtoString()-
Methods inherited from class com.igormaznitsa.prologparser.terms.PrologTerm
assertNonEmptyString, compareTo, findQuotation, getLine, getPos, getQuotation, getText, setLine, setPos
-
-
-
-
Field Detail
-
EMPTY_ATOM
public static final PrologAtom EMPTY_ATOM
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
functor
protected final PrologTerm functor
-
elements
protected final PrologTerm[] elements
-
-
Constructor Detail
-
PrologStruct
public PrologStruct(PrologTerm functor, PrologTerm[] elements)
-
PrologStruct
public PrologStruct(PrologTerm functor, PrologTerm[] elements, int line, int pos)
-
PrologStruct
public PrologStruct(java.lang.String text)
-
PrologStruct
public PrologStruct(java.lang.String text, int line, int pos)
-
PrologStruct
public PrologStruct(PrologTerm functor)
-
PrologStruct
public PrologStruct(PrologTerm functor, int line, int pos)
-
PrologStruct
protected PrologStruct(PrologTerm functor, int arity)
-
PrologStruct
protected PrologStruct(PrologTerm functor, int arity, int line, int pos)
-
-
Method Detail
-
assertFunctor
private static PrologTerm assertFunctor(PrologTerm functor)
-
getType
public TermType getType()
Description copied from class:PrologTermGet term type.- Specified by:
getTypein classPrologTerm- Returns:
- term type, must not be null
-
getArity
public int getArity()
Description copied from class:PrologTermArity of element.- Overrides:
getArityin classPrologTerm- Returns:
- arity of element, make sense for compound terms, for primitive terms is 1
-
getTermAt
public PrologTerm getTermAt(int index)
Description copied from class:PrologCompoundGet element for its position- Specified by:
getTermAtin classPrologCompound- Parameters:
index- zero-based element position- Returns:
- element in position
-
setElementAt
public void setElementAt(int index, PrologTerm term)Set element for its position.- Parameters:
index- zero based indexterm- term to set to position- Throws:
java.lang.ArrayIndexOutOfBoundsException- if wrong index
-
getFunctor
public PrologTerm getFunctor()
Description copied from class:PrologTermGet the functor, make sense of structure and its successors, for primitive returns the same term.- Overrides:
getFunctorin classPrologTerm- Returns:
- functor for structure or the same term
-
getPrecedence
public int getPrecedence()
Description copied from class:PrologTermGet precedence of the term.- Overrides:
getPrecedencein classPrologTerm- Returns:
- precedence, must not be negative
-
copyWithAnotherFunctor
public PrologStruct copyWithAnotherFunctor(PrologTerm newFunctor)
Make copy of the structure with replacement of functor.- Parameters:
newFunctor- the new functor, must not be null- Returns:
- the new instance with replaced functor.
-
isAnyBlock
public boolean isAnyBlock()
Description copied from class:PrologTermCheck the term describes '()' or '{}' block.- Overrides:
isAnyBlockin classPrologTerm- Returns:
- true if the term is structure describes any kind of supported block
-
isCurlyBlock
public boolean isCurlyBlock()
Description copied from class:PrologTermCheck the term describes '{}' block.- Overrides:
isCurlyBlockin classPrologTerm- Returns:
- true if the term is structure with '{}' as functor
-
isBlock
public boolean isBlock()
Description copied from class:PrologTermCheck the term describes '()' block.- Overrides:
isBlockin classPrologTerm- Returns:
- true if the term is structure with '()' as functor
-
flatComma
public java.util.List<PrologTerm> flatComma(java.util.List<PrologTerm> list)
Description copied from class:PrologTermFlat content of the term for comma, make sense for structures.- Overrides:
flatCommain classPrologTerm- Parameters:
list- list to be filled by comma separated terms- Returns:
- the same list
-
toString
public java.lang.String toString()
- Overrides:
toStringin classPrologTerm
-
isEmpty
public boolean isEmpty()
Check that the structure has elements.- Returns:
- true if there is not elements, false otherwise
-
stream
public java.util.stream.Stream<PrologTerm> stream()
- Overrides:
streamin classPrologTerm
-
iterator
public java.util.Iterator<PrologTerm> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<PrologTerm>
-
-