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
Modifier and TypeFieldDescriptionprotected static final int
Number operators in this table.protected int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
unary division i.e.protected static final int
protected static final int
protected Operator[]
-
Constructor Summary
-
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 NOTint
getOperator
(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-x
getUPlus()
Gets the operator used for unary addition+x
void
Initialize 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 opvoid
Remove an operator from the table.replaceOperator
(Operator oldOp, Operator op) replace an existing operator by a new one.protected boolean
setBinaryInverseOp
(int key1, int key2) protected boolean
setDistributiveOver
(int key1, int key2) protected boolean
setInverseOp
(int key1, int key2) protected void
setNumOps
(int size) final boolean
setPrecedenceTable
(int[][] precArray) Sets the precedence of all operators at one time.protected boolean
setRootOp
(int key1, int key2) protected void
Sets 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:JepComponent
Initialize 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:
init
in 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:
getOperatorsBySymbol
in 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:
getOperatorsByName
in interfaceOperatorTableI
- Parameters:
name
- unique name of operator- Returns:
- the operator or null if not found
-
getOperators
- Specified by:
getOperators
in 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:OperatorTableI
Gets the no-op operator- Specified by:
getNop
in interfaceOperatorTableI
-
getAdd
Description copied from interface:OperatorTableI
Gets the operator used for addition- Specified by:
getAdd
in interfaceOperatorTableI
-
getSubtract
Description copied from interface:OperatorTableI
Gets the operator used for subtraction- Specified by:
getSubtract
in interfaceOperatorTableI
-
getUMinus
Description copied from interface:OperatorTableI
Gets the operator used for unitary minus-x
- Specified by:
getUMinus
in interfaceOperatorTableI
-
getUPlus
Description copied from interface:OperatorTableI
Gets the operator used for unary addition+x
- Specified by:
getUPlus
in interfaceOperatorTableI
-
getMultiply
Description copied from interface:OperatorTableI
Gets the operator used for multiplication- Specified by:
getMultiply
in interfaceOperatorTableI
-
getDivide
Description copied from interface:OperatorTableI
Gets the operator used for division- Specified by:
getDivide
in interfaceOperatorTableI
-
getMod
Description copied from interface:OperatorTableI
Gets the operator used for modulus- Specified by:
getMod
in interfaceOperatorTableI
-
getUDivide
unary division i.e. 1/x or x^(-1) *- Specified by:
getUDivide
in interfaceOperatorTableI
-
getPower
Description copied from interface:OperatorTableI
Gets the operator used for powers- Specified by:
getPower
in interfaceOperatorTableI
-
getGT
Description copied from interface:OperatorTableI
Gets the operator used for greater-than- Specified by:
getGT
in interfaceOperatorTableI
-
getLT
Description copied from interface:OperatorTableI
Gets the operator used for less-than- Specified by:
getLT
in interfaceOperatorTableI
-
getEQ
Description copied from interface:OperatorTableI
Gets the operator used for equals- Specified by:
getEQ
in interfaceOperatorTableI
-
getLE
Description copied from interface:OperatorTableI
Gets the operator used for less-than or equals to- Specified by:
getLE
in interfaceOperatorTableI
-
getGE
Description copied from interface:OperatorTableI
Gets the operator used for greater than or equals to- Specified by:
getGE
in interfaceOperatorTableI
-
getNE
Description copied from interface:OperatorTableI
Gets the operator used for not equals- Specified by:
getNE
in interfaceOperatorTableI
-
getAnd
Description copied from interface:OperatorTableI
Gets the operator used for logical AND- Specified by:
getAnd
in interfaceOperatorTableI
-
getOr
Description copied from interface:OperatorTableI
Gets the operator used for logical OR- Specified by:
getOr
in interfaceOperatorTableI
-
getNot
Description copied from interface:OperatorTableI
Gets the operator used for logical NOT- Specified by:
getNot
in interfaceOperatorTableI
-
getAssign
Description copied from interface:OperatorTableI
Gets the operator used for assignment- Specified by:
getAssign
in interfaceOperatorTableI
-
getDot
Description copied from interface:OperatorTableI
Gets the operator used for the dot product- Specified by:
getDot
in interfaceOperatorTableI
-
getCross
Description copied from interface:OperatorTableI
Gets the operator used for 3D cross product- Specified by:
getCross
in interfaceOperatorTableI
-
getList
Description copied from interface:OperatorTableI
Gets the operator used for creation of lists[1,2,3]
- Specified by:
getList
in interfaceOperatorTableI
-
getEle
Description copied from interface:OperatorTableI
Gets the operator used for getting and setting elements of a list- Specified by:
getEle
in interfaceOperatorTableI
-
getRange
Description copied from interface:OperatorTableI
Gets the operator used for specifying a range- Specified by:
getRange
in interfaceOperatorTableI
-
toString
String rep operators ordered by precedence, one per line. -
getLightWeightInstance
Description copied from interface:JepComponent
Gets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstance
in interfaceJepComponent
- Returns:
- this
-
threadSafeMapCopy
-
shallowCopy
Description copied from interface:OperatorTableI
Create 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:
shallowCopy
in interfaceOperatorTableI
- Returns:
- a new OperatorTable
-