Package com.singularsys.jep
Class OperatorTable
java.lang.Object
com.singularsys.jep.OperatorTable
- All Implemented Interfaces:
JepComponent,OperatorTableI,Serializable
- Direct Known Subclasses:
StandardOperatorTable
Base class for the older style Operator table.
Superseded by
OperatorTable2- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intNumber operators in this table.protected intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intunary division i.e.protected static final intprotected static final intprotected Operator[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddOperator(int key, Operator op) Add an operator with a given key.addOperator(int key, Operator op, Operator existingOp) Add operator with the same precedence level as an existing operator.addOperator(Operator op) Add an operator with no key specified.addOperator(Operator op, Operator existingOp) Add operator with the same precedence level as an existing operator.appendOperator(int key, Operator op, Operator existingOp) Add an operator which a new precedence level which is higher than the existing opappendOperator(Operator op, Operator existingOp) Add an operator which a new precedence level which is higher than the existing opgetAdd()Gets the operator used for additiongetAnd()Gets the operator used for logical ANDGets the operator used for assignmentgetCross()Gets the operator used for 3D cross productGets the operator used for divisiongetDot()Gets the operator used for the dot productgetEle()Gets the operator used for getting and setting elements of a listgetEQ()Gets the operator used for equalsgetGE()Gets the operator used for greater than or equals togetGT()Gets the operator used for greater-thangetLE()Gets the operator used for less-than or equals toGets a light-weight instance suitable for using in multiple threads.getList()Gets the operator used for creation of lists[1,2,3]getLT()Gets the operator used for less-thangetMod()Gets the operator used for modulusGets the operator used for multiplicationgetNE()Gets the operator used for not equalsgetNop()Gets the no-op operatorgetNot()Gets the operator used for logical NOTintgetOperator(int key) Get operator by its key code.getOperatorsByName(String name) Get the operator with a given namegetOperatorsBySymbol(String symbol) Gets all the operators with a given symbolgetOr()Gets the operator used for logical ORgetPower()Gets the operator used for powersgetRange()Gets the operator used for specifying a rangeGets the operator used for subtractionunary division i.e.Gets the operator used for unitary minus-xgetUPlus()Gets the operator used for unary addition+xvoidInitialize the component.insertOperator(int key, Operator op, Operator existingOp) Add an operator with a new precedence level which is lower than the existing op.insertOperator(Operator op, Operator existingOp) Add an operator which a new precedence level which is lower than the existing opvoidRemove an operator from the table.replaceOperator(Operator oldOp, Operator op) replace an existing operator by a new one.protected booleansetBinaryInverseOp(int key1, int key2) protected booleansetDistributiveOver(int key1, int key2) protected booleansetInverseOp(int key1, int key2) protected voidsetNumOps(int size) final booleansetPrecedenceTable(int[][] precArray) Sets the precedence of all operators at one time.protected booleansetRootOp(int key1, int key2) protected voidSets up the standard relations between +,-,*,/Create a new version of this OperatorTable.protected Operator[]threadSafeMapCopy(Operator[] ops2) toString()String rep operators ordered by precedence, one per line.
-
Field Details
-
ops
-
OP_NOP
protected static final int OP_NOP- See Also:
-
OP_ADD
protected static final int OP_ADD- See Also:
-
OP_SUBTRACT
protected static final int OP_SUBTRACT- See Also:
-
OP_NEGATE
protected static final int OP_NEGATE- See Also:
-
OP_UPLUS
protected static final int OP_UPLUS- See Also:
-
OP_MULTIPLY
protected static final int OP_MULTIPLY- See Also:
-
OP_DIVIDE
protected static final int OP_DIVIDE- See Also:
-
OP_MOD
protected static final int OP_MOD- See Also:
-
OP_RECIP
protected static final int OP_RECIPunary division i.e. 1/x or x^(-1) *- See Also:
-
OP_POWER
protected static final int OP_POWER- See Also:
-
OP_GT
protected static final int OP_GT- See Also:
-
OP_LT
protected static final int OP_LT- See Also:
-
OP_EQ
protected static final int OP_EQ- See Also:
-
OP_LE
protected static final int OP_LE- See Also:
-
OP_GE
protected static final int OP_GE- See Also:
-
OP_NE
protected static final int OP_NE- See Also:
-
OP_AND
protected static final int OP_AND- See Also:
-
OP_OR
protected static final int OP_OR- See Also:
-
OP_NOT
protected static final int OP_NOT- See Also:
-
OP_ASSIGN
protected static final int OP_ASSIGN- See Also:
-
OP_DOT
protected static final int OP_DOT- See Also:
-
OP_CROSS
protected static final int OP_CROSS- See Also:
-
OP_LIST
protected static final int OP_LIST- See Also:
-
OP_ELEMENT
protected static final int OP_ELEMENT- See Also:
-
OP_RANGE
protected static final int OP_RANGE- See Also:
-
baseNumOps
protected static final int baseNumOpsNumber operators in this table. Can be used by subclasses- See Also:
-
numOps
protected int numOps
-
-
Constructor Details
-
OperatorTable
public OperatorTable() -
OperatorTable
-
-
Method Details
-
init
Description copied from interface:JepComponentInitialize the component. This method is called whenever a component is added to Jep. Hence, it allows components to keep track of the other components they may rely on.- Specified by:
initin interfaceJepComponent- Parameters:
jep- the current Jep instance
-
setNumOps
protected void setNumOps(int size) -
getNumOps
public int getNumOps() -
addOperator
Add an operator with a given key.- Parameters:
key- integer key valueop-- Returns:
- the operator op
-
addOperator
Add an operator with no key specified.- Parameters:
op-- Returns:
- the operator op
-
addOperator
Add operator with the same precedence level as an existing operator.- Parameters:
key-op-existingOp-- Returns:
- the operator
-
addOperator
Add operator with the same precedence level as an existing operator.- Parameters:
op-existingOp-- Returns:
- the operator
-
insertOperator
Add an operator with a new precedence level which is lower than the existing op. Increments the precedence of all operators with a greater precedence by one.- Parameters:
key-op-existingOp-- Returns:
- the operator
-
insertOperator
Add an operator which a new precedence level which is lower than the existing op- Parameters:
op-existingOp-- Returns:
- the operator
-
appendOperator
Add an operator which a new precedence level which is higher than the existing op- Parameters:
key-op-existingOp-- Returns:
- the operator
-
appendOperator
Add an operator which a new precedence level which is higher than the existing op- Parameters:
op-existingOp-- Returns:
- the operator
-
removeOperator
Remove an operator from the table.- Parameters:
op- the operator to be removed
-
replaceOperator
replace an existing operator by a new one.- Parameters:
oldOp- the old operatorop- the new operator- Returns:
- the new operator
-
getOperator
Get operator by its key code. Most efficient way to get an operator.- Parameters:
key- code used in the table- Returns:
- the operator or null if not found
-
getOperatorsBySymbol
Gets all the operators with a given symbol- Specified by:
getOperatorsBySymbolin interfaceOperatorTableI- Parameters:
symbol- symbol used for operator- Returns:
- list of operators with a given symbol, empty list if none are found.
-
getOperatorsByName
Get the operator with a given name- Specified by:
getOperatorsByNamein interfaceOperatorTableI- Parameters:
name- unique name of operator- Returns:
- the operator or null if not found
-
getOperators
- Specified by:
getOperatorsin interfaceOperatorTableI
-
setPrecedenceTable
public final boolean setPrecedenceTable(int[][] precArray) Sets the precedence of all operators at one time. An array of arrays of key codes of operators is used to set the table operators with the same precedence are grouped together and listed from tighter binding to loose binding. For examplesetPrecedenceTable(new int[][] { { OP_NEGATE, OP_UPLUS, OP_NOT }, { OP_POWER }, { OP_MULTIPLY, OP_DIVIDE, OP_MOD, OP_DOT, OP_CROSS }, { OP_ADD, OP_SUBTRACT }, { OP_LT, OP_LE, OP_GT, OP_GE }, { OP_EQ, OP_NE }, { OP_AND }, { OP_OR }, { OP_ASSIGN }, });- Parameters:
precArray-- Returns:
- flag
-
setInverseOp
protected boolean setInverseOp(int key1, int key2) -
setBinaryInverseOp
protected boolean setBinaryInverseOp(int key1, int key2) -
setRootOp
protected boolean setRootOp(int key1, int key2) -
setDistributiveOver
protected boolean setDistributiveOver(int key1, int key2) -
setStandardOperatorRelations
protected void setStandardOperatorRelations()Sets up the standard relations between +,-,*,/ -
getNop
Description copied from interface:OperatorTableIGets the no-op operator- Specified by:
getNopin interfaceOperatorTableI
-
getAdd
Description copied from interface:OperatorTableIGets the operator used for addition- Specified by:
getAddin interfaceOperatorTableI
-
getSubtract
Description copied from interface:OperatorTableIGets the operator used for subtraction- Specified by:
getSubtractin interfaceOperatorTableI
-
getUMinus
Description copied from interface:OperatorTableIGets the operator used for unitary minus-x- Specified by:
getUMinusin interfaceOperatorTableI
-
getUPlus
Description copied from interface:OperatorTableIGets the operator used for unary addition+x- Specified by:
getUPlusin interfaceOperatorTableI
-
getMultiply
Description copied from interface:OperatorTableIGets the operator used for multiplication- Specified by:
getMultiplyin interfaceOperatorTableI
-
getDivide
Description copied from interface:OperatorTableIGets the operator used for division- Specified by:
getDividein interfaceOperatorTableI
-
getMod
Description copied from interface:OperatorTableIGets the operator used for modulus- Specified by:
getModin interfaceOperatorTableI
-
getUDivide
unary division i.e. 1/x or x^(-1) *- Specified by:
getUDividein interfaceOperatorTableI
-
getPower
Description copied from interface:OperatorTableIGets the operator used for powers- Specified by:
getPowerin interfaceOperatorTableI
-
getGT
Description copied from interface:OperatorTableIGets the operator used for greater-than- Specified by:
getGTin interfaceOperatorTableI
-
getLT
Description copied from interface:OperatorTableIGets the operator used for less-than- Specified by:
getLTin interfaceOperatorTableI
-
getEQ
Description copied from interface:OperatorTableIGets the operator used for equals- Specified by:
getEQin interfaceOperatorTableI
-
getLE
Description copied from interface:OperatorTableIGets the operator used for less-than or equals to- Specified by:
getLEin interfaceOperatorTableI
-
getGE
Description copied from interface:OperatorTableIGets the operator used for greater than or equals to- Specified by:
getGEin interfaceOperatorTableI
-
getNE
Description copied from interface:OperatorTableIGets the operator used for not equals- Specified by:
getNEin interfaceOperatorTableI
-
getAnd
Description copied from interface:OperatorTableIGets the operator used for logical AND- Specified by:
getAndin interfaceOperatorTableI
-
getOr
Description copied from interface:OperatorTableIGets the operator used for logical OR- Specified by:
getOrin interfaceOperatorTableI
-
getNot
Description copied from interface:OperatorTableIGets the operator used for logical NOT- Specified by:
getNotin interfaceOperatorTableI
-
getAssign
Description copied from interface:OperatorTableIGets the operator used for assignment- Specified by:
getAssignin interfaceOperatorTableI
-
getDot
Description copied from interface:OperatorTableIGets the operator used for the dot product- Specified by:
getDotin interfaceOperatorTableI
-
getCross
Description copied from interface:OperatorTableIGets the operator used for 3D cross product- Specified by:
getCrossin interfaceOperatorTableI
-
getList
Description copied from interface:OperatorTableIGets the operator used for creation of lists[1,2,3]- Specified by:
getListin interfaceOperatorTableI
-
getEle
Description copied from interface:OperatorTableIGets the operator used for getting and setting elements of a list- Specified by:
getElein interfaceOperatorTableI
-
getRange
Description copied from interface:OperatorTableIGets the operator used for specifying a range- Specified by:
getRangein interfaceOperatorTableI
-
toString
String rep operators ordered by precedence, one per line. -
getLightWeightInstance
Description copied from interface:JepComponentGets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstancein interfaceJepComponent- Returns:
- this
-
threadSafeMapCopy
-
shallowCopy
Description copied from interface:OperatorTableICreate a new version of this OperatorTable. Existing Operators are copied into new table. However, Operators whose pfmc's implement JepComponent are duplicated, this means the table could be used in multiple threads without problem.- Specified by:
shallowCopyin interfaceOperatorTableI- Returns:
- a new OperatorTable
-