Class OpContainer
- java.lang.Object
-
- com.igormaznitsa.prologparser.terms.PrologTerm
-
- com.igormaznitsa.prologparser.terms.PrologCompound
-
- com.igormaznitsa.prologparser.terms.InternalSpecialCompoundTerm
-
- com.igormaznitsa.prologparser.terms.OpContainer
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<PrologTerm>
public final class OpContainer extends InternalSpecialCompoundTerm
Container of operators which have same name but differently associative.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private intnumberAtContainerprivate OpopFZprivate OpopZFprivate OpopZFZprivate static longserialVersionUID-
Fields inherited from class com.igormaznitsa.prologparser.terms.PrologTerm
quotation, text
-
-
Constructor Summary
Constructors Modifier Constructor Description privateOpContainer(Op operator)privateOpContainer(java.lang.String text, Op fz, Op zf, Op zfz)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(Op operator)Add operator into the container.voidclear()Remove all saved operators.OpfindForArity(int arity)Find operator with arity in the containerOpfindForType(OpAssoc type)Find operator for its typeOpfindSimilar(boolean hasLeftArg, boolean hasRightArg)Find operator for presented arguments.OpfindSimilar(OpAssoc type)Find operator with similar type.intgetArity()Arity of element.OpgetIfSingle()Get operator if it is only one in the containerintgetPrecedence()Get precedence of the term.PrologTermgetTermAt(int position)Get element for its positionTermTypegetType()Get term type.static OpContainermake(Op operator)Create new container based on operator name.static OpContainermake(java.lang.String text, Op fz, Op zf, Op zfz)booleanremove(Op op)Remove operator from the containerbooleanremoveForType(OpAssoc type)Remove operator for typeintsize()Get current size of the container.java.lang.StringtoString()-
Methods inherited from class com.igormaznitsa.prologparser.terms.InternalSpecialCompoundTerm
compareTo, stream
-
Methods inherited from class com.igormaznitsa.prologparser.terms.PrologTerm
assertNonEmptyString, findQuotation, flatComma, getFunctor, getLine, getPos, getQuotation, getText, isAnyBlock, isBlock, isCurlyBlock, setLine, setPos
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
opFZ
private Op opFZ
-
opZF
private Op opZF
-
opZFZ
private Op opZFZ
-
numberAtContainer
private int numberAtContainer
-
-
Method Detail
-
make
public static OpContainer make(Op operator)
Create new container based on operator name.- Parameters:
operator- operator which name will be used and which will be added to the new container- Returns:
- generated container with the operator
-
make
public static OpContainer make(java.lang.String text, Op fz, Op zf, Op zfz)
-
add
public boolean add(Op operator)
Add operator into the container.- Parameters:
operator- the operator to be added- Returns:
- true if the operator has been added, false if it was impossible because similar operator already presented
- Throws:
java.lang.IllegalArgumentException- if operator has different name
-
clear
public void clear()
Remove all saved operators.
-
findForArity
public Op findForArity(int arity)
Find operator with arity in the container- Parameters:
arity- arity to be used (1..2)- Returns:
- found operator or null
-
remove
public boolean remove(Op op)
Remove operator from the container- Parameters:
op- operator to be removed- Returns:
- true if operator was removed, false otherwise
- Throws:
java.lang.IllegalArgumentException- if operator name is not compatible with the container
-
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 position)
Description copied from class:PrologCompoundGet element for its position- Overrides:
getTermAtin classInternalSpecialCompoundTerm- Parameters:
position- zero-based element position- Returns:
- element in position
-
size
public int size()
Get current size of the container.- Returns:
- size of the container
-
getIfSingle
public Op getIfSingle()
Get operator if it is only one in the container- Returns:
- the found only operator, null if there are severe operators
-
findSimilar
public Op findSimilar(boolean hasLeftArg, boolean hasRightArg)
Find operator for presented arguments.- Parameters:
hasLeftArg- should have left argumenthasRightArg- should have right argument- Returns:
- operator for needed condition, null if not found
-
findForType
public Op findForType(OpAssoc type)
Find operator for its type- Parameters:
type- type of needed operator- Returns:
- found operator, null if not found
-
findSimilar
public Op findSimilar(OpAssoc type)
Find operator with similar type. For instance FX is similar to FY and XF is similar to YF.- Parameters:
type- type of operator to find- Returns:
- operator with similar type or null if not found
-
removeForType
public boolean removeForType(OpAssoc type)
Remove operator for type- Parameters:
type- type of removing operator- Returns:
- true if removed, false if not found
-
getPrecedence
public int getPrecedence()
Description copied from class:PrologTermGet precedence of the term.- Overrides:
getPrecedencein classPrologTerm- Returns:
- precedence, must not be negative
-
toString
public java.lang.String toString()
- Overrides:
toStringin classPrologTerm
-
-