Package com.singularsys.jep
Class EmptyOperatorTable
java.lang.Object
com.singularsys.jep.EmptyOperatorTable
- All Implemented Interfaces:
JepComponent,OperatorTableI,Serializable
- Direct Known Subclasses:
OperatorTable2
A base class for operator tables, this class has no pre-defined operators.
For most cases its subclass
OperatorTable2 should be used which has
the standard set of operators.
This class has a sub-interface OperatorKey which is used to
index operators, enums using this are defined in OperatorTable2.
- Since:
- 3.4
- Author:
- Richard Morris
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAll operators enums must implement this interface. -
Constructor Summary
ConstructorsModifierConstructorDescriptionConstructor with an empty map.protectedConstructor with a specified map. -
Method Summary
Modifier and TypeMethodDescriptionAdd an operator with a given key.addOperator(EmptyOperatorTable.OperatorKey key, Operator op, Operator existingOp) Add operator with the same precedence level as an existing operator.addOperator(Operator op, Operator existingOp) Add operator with the same precedence level as an existing operator.appendOperator(EmptyOperatorTable.OperatorKey key, Operator op, Operator existingOp) Add an operator with a new precedence level which is lower than the existing op.appendOperator(Operator op, Operator existingOp) Add an operator with a new precedence level which is lower than the existing op.entrySet()getAdd()Returns the operator used for addition.getAnd()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-thanGets the key associated with a specific operatorgetLE()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 NOTintGet operator by its key code.protected Map<EmptyOperatorTable.OperatorKey,Operator> Return the full list of operatorsgetOperatorsByName(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(EmptyOperatorTable.OperatorKey key, Operator op, Operator existingOp) Add an operator with a new precedence level which is equal to the existing op.insertOperator(Operator op, Operator existingOp) Add an operator with a new precedence level which is equal to the existing op.keySet()voidRemove a give operator from the tablevoidRemove a give operator from the tablevoidReplace a give operator with a new one.voidreplaceOperator(Operator oldOp, Operator op) Replace a give operator with a new one.protected booleanprotected booleanprotected voidsetGroupOperatorRelations(EmptyOperatorTable.OperatorKey root, EmptyOperatorTable.OperatorKey inv, EmptyOperatorTable.OperatorKey composite) Sets relations of three operators.protected voidsetGroupOperatorRelations(Operator root, Operator inv, Operator composite) Sets relations of three operators.protected booleanfinal booleansetPrecedenceTable(EmptyOperatorTable.OperatorKey[][] precArray) Sets the precedence of all operators at one time.protected booleanprotected voidSets up the standard relations between +,-,*,/Create a new version of this OperatorTable.protected Map<EmptyOperatorTable.OperatorKey,Operator> Creates a copy of the internal map used for operators.toString()String rep operators ordered by precedence, one per line.
-
Constructor Details
-
EmptyOperatorTable
public EmptyOperatorTable()Constructor with an empty map. -
EmptyOperatorTable
Constructor with a specified map. Subclasses should define similar constructors to allow theshallowCopy()to work.- Parameters:
oldMap- map with existing set of functions- Since:
- 4.0
-
-
Method Details
-
getAdd
Returns the operator used for addition.- Specified by:
getAddin interfaceOperatorTableI
-
getAnd
Description copied from interface:OperatorTableIGets the operator used for logical AND- Specified by:
getAndin interfaceOperatorTableI
-
getAssign
Description copied from interface:OperatorTableIGets the operator used for assignment- Specified by:
getAssignin interfaceOperatorTableI
-
getCross
Description copied from interface:OperatorTableIGets the operator used for 3D cross product- Specified by:
getCrossin interfaceOperatorTableI
-
getDivide
Description copied from interface:OperatorTableIGets the operator used for division- Specified by:
getDividein interfaceOperatorTableI
-
getDot
Description copied from interface:OperatorTableIGets the operator used for the dot product- Specified by:
getDotin interfaceOperatorTableI
-
getEQ
Description copied from interface:OperatorTableIGets the operator used for equals- Specified by:
getEQin interfaceOperatorTableI
-
getEle
Description copied from interface:OperatorTableIGets the operator used for getting and setting elements of a list- Specified by:
getElein interfaceOperatorTableI
-
getGE
Description copied from interface:OperatorTableIGets the operator used for greater than or equals to- Specified by:
getGEin interfaceOperatorTableI
-
getGT
Description copied from interface:OperatorTableIGets the operator used for greater-than- Specified by:
getGTin interfaceOperatorTableI
-
getLE
Description copied from interface:OperatorTableIGets the operator used for less-than or equals to- Specified by:
getLEin interfaceOperatorTableI
-
getLT
Description copied from interface:OperatorTableIGets the operator used for less-than- Specified by:
getLTin interfaceOperatorTableI
-
getList
Description copied from interface:OperatorTableIGets the operator used for creation of lists[1,2,3]- Specified by:
getListin interfaceOperatorTableI
-
getMod
Description copied from interface:OperatorTableIGets the operator used for modulus- Specified by:
getModin interfaceOperatorTableI
-
getMultiply
Description copied from interface:OperatorTableIGets the operator used for multiplication- Specified by:
getMultiplyin interfaceOperatorTableI
-
getNE
Description copied from interface:OperatorTableIGets the operator used for not equals- Specified by:
getNEin interfaceOperatorTableI
-
getNop
Description copied from interface:OperatorTableIGets the no-op operator- Specified by:
getNopin interfaceOperatorTableI
-
getNot
Description copied from interface:OperatorTableIGets the operator used for logical NOT- Specified by:
getNotin interfaceOperatorTableI
-
getOr
Description copied from interface:OperatorTableIGets the operator used for logical OR- Specified by:
getOrin interfaceOperatorTableI
-
getPower
Description copied from interface:OperatorTableIGets the operator used for powers- Specified by:
getPowerin interfaceOperatorTableI
-
getRange
Description copied from interface:OperatorTableIGets the operator used for specifying a range- Specified by:
getRangein interfaceOperatorTableI
-
getSubtract
Description copied from interface:OperatorTableIGets the operator used for subtraction- Specified by:
getSubtractin interfaceOperatorTableI
-
getUDivide
Description copied from interface:OperatorTableIunary division i.e. 1/x or x^(-1) *- Specified by:
getUDividein 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
-
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
-
getNumOps
public int getNumOps() -
addOperator
Add an operator with a given key. The precedence will need to be set bysetPrecedenceTable(OperatorKey[][]).- Parameters:
key- key value used to identify the operatorop- operator- Returns:
- the operator op
-
addOperator
Add operator with the same precedence level as an existing operator.- Parameters:
key- unique key used to identify the operator.op- the new operatorexistingOp- and existing operator, the precedence of this operator will be the same as the existing operator.- Returns:
- the operator
-
addOperator
Add operator with the same precedence level as an existing operator. The key will be automatically generated, and it can be recovered usinggetKey(Operator).- Parameters:
op- the new operatorexistingOp- and existing operator, the precedence of this operator will be the same as the existing operator.- Returns:
- the operator
-
insertOperator
public Operator insertOperator(EmptyOperatorTable.OperatorKey key, Operator op, Operator existingOp) Add an operator with a new precedence level which is equal to the existing op. Increments the precedence of the existing operator all operators with a greater or equal precedence by one.- Parameters:
key- a key used to identify the operatorop-existingOp-- Returns:
- the operator
-
insertOperator
Add an operator with a new precedence level which is equal to the existing op. Increments the precedence of the existing operator all operators with a greater or equal precedence by one. The key will be automatically generated, and it can be recovered usinggetKey(Operator).- Parameters:
op-existingOp-- Returns:
- the operator
-
appendOperator
public Operator appendOperator(EmptyOperatorTable.OperatorKey key, Operator op, Operator existingOp) 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
-
appendOperator
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. The key will be automatically generated, and it can be recovered usinggetKey(Operator).- Parameters:
op- Operator to addexistingOp- operator to copy precedence from- Returns:
- the operator
-
getKey
Gets the key associated with a specific operator- Parameters:
op-- Returns:
- the key, null if op is not in the table
-
removeOperator
Remove a give operator from the table- Parameters:
op-
-
removeOperator
Remove a give operator from the table- Parameters:
key-
-
replaceOperator
Replace a give operator with a new one. The new operator will have the same precedence as the old one- Parameters:
oldOp- the operator to be replacedop- the new operator
-
replaceOperator
Replace a give operator with a new one. The new operator will have the same precedence as the old one- Parameters:
key- the key for the operatorop- 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
Return the full list of operators- Specified by:
getOperatorsin interfaceOperatorTableI
-
entrySet
-
getOperatorMap
-
keySet
-
setPrecedenceTable
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 OperatorKey[][] { { POWER }, { NEG, UPLUS, NOT }, { MUL, DIV, MOD, DOT, CROSS }, { ADD, SU }, { LT, LE, GT, GE }, { EQ, NE }, { AND }, { OR }, { ASSIGN }, });- Parameters:
precArray-- Returns:
- flag
-
setInverseOp
protected boolean setInverseOp(EmptyOperatorTable.OperatorKey key1, EmptyOperatorTable.OperatorKey key2) -
setBinaryInverseOp
protected boolean setBinaryInverseOp(EmptyOperatorTable.OperatorKey key1, EmptyOperatorTable.OperatorKey key2) -
setRootOp
protected boolean setRootOp(EmptyOperatorTable.OperatorKey key1, EmptyOperatorTable.OperatorKey key2) -
setDistributiveOver
protected boolean setDistributiveOver(EmptyOperatorTable.OperatorKey key1, EmptyOperatorTable.OperatorKey key2) -
setGroupOperatorRelations
Sets relations of three operators. A mathematical group has three related operators the root operatorx+y, the inverseuminus z, and compositex-y = x+(uminus y)- Parameters:
root- the root operator i.e. ADDinv- the inverse operator i.e. UMINUScomposite- the composite operator i.e. SUBTRACT
-
setGroupOperatorRelations
protected void setGroupOperatorRelations(EmptyOperatorTable.OperatorKey root, EmptyOperatorTable.OperatorKey inv, EmptyOperatorTable.OperatorKey composite) Sets relations of three operators. A mathematical group has three related operators the root operatorx+y, the inverseuminus z, and compositex-y = x+(uminus y)- Parameters:
root- the root operator i.e. ADDinv- the inverse operator i.e. UMINUScomposite- the composite operator i.e. SUBTRACT
-
setStandardOperatorRelations
protected void setStandardOperatorRelations()Sets up the standard relations between +,-,*,/ -
toString
String rep operators ordered by precedence, one per line. -
shallowCopy
Create a new version of this OperatorTable. Operators are copied into new table. However, Operators whose pfmc implement JepComponent are duplicated. This means the table could be used in a separate thread without problem. Subclasses should override with method to return a table of the correct type, a typical implementation would be@Override public OperatorTableI shallowCopy() { Map<OperatorKey, Operator> map = this.threadSafeMapCopy(); return new MyOperatorTable(map); }using thethreadSafeMapCopy()method to return a copy of the map of operators and a constructor taking this map which uses theEmptyOperatorTable(Map)constructor.- Specified by:
shallowCopyin interfaceOperatorTableI- Returns:
- a new Table
-
getLightWeightInstance
Description copied from interface:JepComponentGets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstancein interfaceJepComponent- Returns:
- this
-
threadSafeMapCopy
Creates a copy of the internal map used for operators. Most operators are simply copied to the new table. However, Operators whose pfmc's implement JepComponent are duplicated, this means the table could be used in multiple threads without problem.- Returns:
- a new map with one entry for each operator in the current table.
-