- java.lang.Object
-
- com.igormaznitsa.prologparser.terms.PrologTerm
-
- com.igormaznitsa.prologparser.terms.PrologCompound
-
- com.igormaznitsa.prologparser.terms.PrologStruct
-
- All Implemented Interfaces:
Serializable,Comparable<PrologTerm>,Iterable<PrologTerm>
- Direct Known Subclasses:
PrologList
public class PrologStruct extends PrologCompound implements Iterable<PrologTerm>
Representation of prolog structure.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected PrologTerm[]elementsstatic PrologAtomEMPTY_ATOMprotected PrologTermfunctor-
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(String text)PrologStruct(String text, int line, int pos)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PrologStructcopyWithAnotherFunctor(PrologTerm newFunctor)Make copy of the structure with replacement of functor.List<PrologTerm>flatComma(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.Iterator<PrologTerm>iterator()voidsetElementAt(int index, PrologTerm term)Set element for its position.Stream<PrologTerm>stream()StringtoString()-
Methods inherited from class com.igormaznitsa.prologparser.terms.PrologTerm
assertNonEmptyString, compareTo, findQuotation, getLine, getPos, getQuotation, getText, setLine, setPos
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
EMPTY_ATOM
public static final PrologAtom EMPTY_ATOM
-
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(String text)
-
PrologStruct
public PrologStruct(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
-
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:
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 List<PrologTerm> flatComma(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 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 Stream<PrologTerm> stream()
- Overrides:
streamin classPrologTerm
-
iterator
public Iterator<PrologTerm> iterator()
- Specified by:
iteratorin interfaceIterable<PrologTerm>
-
-