Package com.singularsys.jep
Class OperatorTable
- java.lang.Object
-
- com.singularsys.jep.OperatorTable
-
- All Implemented Interfaces:
JepComponent
,OperatorTableI
,java.io.Serializable
- Direct Known Subclasses:
StandardOperatorTable
public class OperatorTable extends java.lang.Object implements OperatorTableI
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static int
baseNumOps
Number operators in this table.protected int
numOps
protected static int
OP_ADD
protected static int
OP_AND
protected static int
OP_ASSIGN
protected static int
OP_CROSS
protected static int
OP_DIVIDE
protected static int
OP_DOT
protected static int
OP_ELEMENT
protected static int
OP_EQ
protected static int
OP_GE
protected static int
OP_GT
protected static int
OP_LE
protected static int
OP_LIST
protected static int
OP_LT
protected static int
OP_MOD
protected static int
OP_MULTIPLY
protected static int
OP_NE
protected static int
OP_NEGATE
protected static int
OP_NOP
protected static int
OP_NOT
protected static int
OP_OR
protected static int
OP_POWER
protected static int
OP_RANGE
protected static int
OP_RECIP
unary division i.e. 1/x or x^(-1) *protected static int
OP_SUBTRACT
protected static int
OP_UPLUS
protected Operator[]
ops
-
Constructor Summary
Constructors Modifier Constructor Description OperatorTable()
protected
OperatorTable(Operator[] ops2)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Operator
addOperator(int key, Operator op)
Add a operator with a given key.Operator
addOperator(int key, Operator op, Operator existingOp)
Add operator with the same precedence level as an existing operator.Operator
addOperator(Operator op)
Add a operator with no key specified.Operator
addOperator(Operator op, Operator existingOp)
Add operator with the same precedence level as an existing operator.Operator
appendOperator(int key, Operator op, Operator existingOp)
Add an operator which a new precedence level which is higher than the existing opOperator
appendOperator(Operator op, Operator existingOp)
Add an operator which a new precedence level which is higher than the existing opOperator
getAdd()
Operator
getAnd()
Operator
getAssign()
Operator
getCross()
Operator
getDivide()
Operator
getDot()
Operator
getEle()
Operator
getEQ()
Operator
getGE()
Operator
getGT()
Operator
getLE()
JepComponent
getLightWeightInstance()
Gets a light-weight instance suitable for using in multiple threads.Operator
getList()
Operator
getLT()
Operator
getMod()
Operator
getMultiply()
Operator
getNE()
Operator
getNop()
Operator
getNot()
int
getNumOps()
Operator
getOperator(int key)
Get operator by its key code.java.util.Collection<Operator>
getOperators()
Operator
getOperatorsByName(java.lang.String name)
Get the operator with a given namejava.util.List<Operator>
getOperatorsBySymbol(java.lang.String symbol)
Gets all the operators with a given symbolOperator
getOr()
Operator
getPower()
Operator
getRange()
Operator
getSubtract()
Operator
getUDivide()
unary division i.e. 1/x or x^(-1) *Operator
getUMinus()
Operator
getUPlus()
void
init(Jep jep)
Initialize the component.Operator
insertOperator(int key, Operator op, Operator existingOp)
Add an operator with a new precedence level which is lower than the existing op.Operator
insertOperator(Operator op, Operator existingOp)
Add an operator which a new precedence level which is lower than the existing opvoid
removeOperator(Operator op)
Remove an operator from the table.Operator
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)
boolean
setPrecedenceTable(int[][] precArray)
Sets the precedence of all operators at one time.protected boolean
setRootOp(int key1, int key2)
protected void
setStandardOperatorRelations()
Sets up the standard relations between +,-,*,/OperatorTableI
shallowCopy()
Create a new version of this OperatorTable.protected Operator[]
threadSafeMapCopy(Operator[] ops2)
java.lang.String
toString()
String rep operators ordered by precedence, one per line.
-
-
-
Field Detail
-
ops
protected Operator[] ops
-
OP_NOP
protected static final int OP_NOP
- See Also:
- Constant Field Values
-
OP_ADD
protected static final int OP_ADD
- See Also:
- Constant Field Values
-
OP_SUBTRACT
protected static final int OP_SUBTRACT
- See Also:
- Constant Field Values
-
OP_NEGATE
protected static final int OP_NEGATE
- See Also:
- Constant Field Values
-
OP_UPLUS
protected static final int OP_UPLUS
- See Also:
- Constant Field Values
-
OP_MULTIPLY
protected static final int OP_MULTIPLY
- See Also:
- Constant Field Values
-
OP_DIVIDE
protected static final int OP_DIVIDE
- See Also:
- Constant Field Values
-
OP_MOD
protected static final int OP_MOD
- See Also:
- Constant Field Values
-
OP_RECIP
protected static final int OP_RECIP
unary division i.e. 1/x or x^(-1) *- See Also:
- Constant Field Values
-
OP_POWER
protected static final int OP_POWER
- See Also:
- Constant Field Values
-
OP_GT
protected static final int OP_GT
- See Also:
- Constant Field Values
-
OP_LT
protected static final int OP_LT
- See Also:
- Constant Field Values
-
OP_EQ
protected static final int OP_EQ
- See Also:
- Constant Field Values
-
OP_LE
protected static final int OP_LE
- See Also:
- Constant Field Values
-
OP_GE
protected static final int OP_GE
- See Also:
- Constant Field Values
-
OP_NE
protected static final int OP_NE
- See Also:
- Constant Field Values
-
OP_AND
protected static final int OP_AND
- See Also:
- Constant Field Values
-
OP_OR
protected static final int OP_OR
- See Also:
- Constant Field Values
-
OP_NOT
protected static final int OP_NOT
- See Also:
- Constant Field Values
-
OP_ASSIGN
protected static final int OP_ASSIGN
- See Also:
- Constant Field Values
-
OP_DOT
protected static final int OP_DOT
- See Also:
- Constant Field Values
-
OP_CROSS
protected static final int OP_CROSS
- See Also:
- Constant Field Values
-
OP_LIST
protected static final int OP_LIST
- See Also:
- Constant Field Values
-
OP_ELEMENT
protected static final int OP_ELEMENT
- See Also:
- Constant Field Values
-
OP_RANGE
protected static final int OP_RANGE
- See Also:
- Constant Field Values
-
baseNumOps
protected static final int baseNumOps
Number operators in this table. Can be used by subclasses- See Also:
- Constant Field Values
-
numOps
protected int numOps
-
-
Constructor Detail
-
OperatorTable
public OperatorTable()
-
OperatorTable
protected OperatorTable(Operator[] ops2)
-
-
Method Detail
-
init
public void init(Jep jep)
Description copied from interface:JepComponent
Initialize the component. This methods 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
public Operator addOperator(int key, Operator op)
Add a operator with a given key.- Parameters:
key
- integer key valueop
-- Returns:
- the operator op
-
addOperator
public Operator addOperator(Operator op)
Add a operator with no key specified.- Parameters:
op
-- Returns:
- the operator op
-
addOperator
public Operator addOperator(int key, Operator op, Operator existingOp)
Add operator with the same precedence level as an existing operator.- Parameters:
key
-op
-existingOp
-- Returns:
- the operator
-
addOperator
public Operator addOperator(Operator op, Operator existingOp)
Add operator with the same precedence level as an existing operator.- Parameters:
op
-existingOp
-- Returns:
- the operator
-
insertOperator
public Operator insertOperator(int 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
-
insertOperator
public Operator insertOperator(Operator op, Operator existingOp)
Add an operator which a new precedence level which is lower than the existing op- Parameters:
op
-existingOp
-- Returns:
- the operator
-
appendOperator
public Operator appendOperator(int key, Operator op, Operator existingOp)
Add an operator which a new precedence level which is higher than the existing op- Parameters:
key
-op
-existingOp
-- Returns:
- the operator
-
appendOperator
public Operator appendOperator(Operator op, Operator existingOp)
Add an operator which a new precedence level which is higher than the existing op- Parameters:
op
-existingOp
-- Returns:
- the operator
-
removeOperator
public void removeOperator(Operator op)
Remove an operator from the table.- Parameters:
op
- the operator to be removed
-
replaceOperator
public Operator replaceOperator(Operator oldOp, Operator op)
replace an existing operator by a new one.- Parameters:
oldOp
- the old operatorop
- the new operator- Returns:
- the new operator
-
getOperator
public Operator getOperator(int key)
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
public java.util.List<Operator> getOperatorsBySymbol(java.lang.String symbol)
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
public Operator getOperatorsByName(java.lang.String name)
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
public java.util.Collection<Operator> 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
public Operator getNop()
- Specified by:
getNop
in interfaceOperatorTableI
-
getAdd
public Operator getAdd()
- Specified by:
getAdd
in interfaceOperatorTableI
-
getSubtract
public Operator getSubtract()
- Specified by:
getSubtract
in interfaceOperatorTableI
-
getUMinus
public Operator getUMinus()
- Specified by:
getUMinus
in interfaceOperatorTableI
-
getUPlus
public Operator getUPlus()
- Specified by:
getUPlus
in interfaceOperatorTableI
-
getMultiply
public Operator getMultiply()
- Specified by:
getMultiply
in interfaceOperatorTableI
-
getDivide
public Operator getDivide()
- Specified by:
getDivide
in interfaceOperatorTableI
-
getMod
public Operator getMod()
- Specified by:
getMod
in interfaceOperatorTableI
-
getUDivide
public Operator getUDivide()
unary division i.e. 1/x or x^(-1) *- Specified by:
getUDivide
in interfaceOperatorTableI
-
getPower
public Operator getPower()
- Specified by:
getPower
in interfaceOperatorTableI
-
getGT
public Operator getGT()
- Specified by:
getGT
in interfaceOperatorTableI
-
getLT
public Operator getLT()
- Specified by:
getLT
in interfaceOperatorTableI
-
getEQ
public Operator getEQ()
- Specified by:
getEQ
in interfaceOperatorTableI
-
getLE
public Operator getLE()
- Specified by:
getLE
in interfaceOperatorTableI
-
getGE
public Operator getGE()
- Specified by:
getGE
in interfaceOperatorTableI
-
getNE
public Operator getNE()
- Specified by:
getNE
in interfaceOperatorTableI
-
getAnd
public Operator getAnd()
- Specified by:
getAnd
in interfaceOperatorTableI
-
getOr
public Operator getOr()
- Specified by:
getOr
in interfaceOperatorTableI
-
getNot
public Operator getNot()
- Specified by:
getNot
in interfaceOperatorTableI
-
getAssign
public Operator getAssign()
- Specified by:
getAssign
in interfaceOperatorTableI
-
getDot
public Operator getDot()
- Specified by:
getDot
in interfaceOperatorTableI
-
getCross
public Operator getCross()
- Specified by:
getCross
in interfaceOperatorTableI
-
getList
public Operator getList()
- Specified by:
getList
in interfaceOperatorTableI
-
getEle
public Operator getEle()
- Specified by:
getEle
in interfaceOperatorTableI
-
getRange
public Operator getRange()
- Specified by:
getRange
in interfaceOperatorTableI
-
toString
public java.lang.String toString()
String rep operators ordered by precedence, one per line.- Overrides:
toString
in classjava.lang.Object
-
getLightWeightInstance
public JepComponent getLightWeightInstance()
Description copied from interface:JepComponent
Gets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstance
in interfaceJepComponent
- Returns:
- this
-
shallowCopy
public OperatorTableI 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
-
-