Package com.singularsys.jep

# Class OperatorTable

java.lang.Object
com.singularsys.jep.OperatorTable

All Implemented Interfaces:
  `JepComponent`, `OperatorTableI`, `Serializable`

Direct Known Subclasses:
  `StandardOperatorTable`

public class OperatorTable extends Object implements OperatorTableI
Base class for the older style Operator table. Superseded by `OperatorTable2`

See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected static final int`
  `baseNumOps`
  Number operators in this table.
  `protected int`
  `numOps`
  `protected static final int`
  `OP_ADD`
  `protected static final int`
  `OP_AND`
  `protected static final int`
  `OP_ASSIGN`
  `protected static final int`
  `OP_CROSS`
  `protected static final int`
  `OP_DIVIDE`
  `protected static final int`
  `OP_DOT`
  `protected static final int`
  `OP_ELEMENT`
  `protected static final int`
  `OP_EQ`
  `protected static final int`
  `OP_GE`
  `protected static final int`
  `OP_GT`
  `protected static final int`
  `OP_LE`
  `protected static final int`
  `OP_LIST`
  `protected static final int`
  `OP_LT`
  `protected static final int`
  `OP_MOD`
  `protected static final int`
  `OP_MULTIPLY`
  `protected static final int`
  `OP_NE`
  `protected static final int`
  `OP_NEGATE`
  `protected static final int`
  `OP_NOP`
  `protected static final int`
  `OP_NOT`
  `protected static final int`
  `OP_OR`
  `protected static final int`
  `OP_POWER`
  `protected static final int`
  `OP_RANGE`
  `protected static final int`
  `OP_RECIP`
  unary division i.e. 1/x or x^(-1) *
  `protected static final int`
  `OP_SUBTRACT`
  `protected static final int`
  `OP_UPLUS`
  `protected Operator[]`
  `ops`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  ``
  `OperatorTable()`
  `protected`
  `OperatorTable(Operator[] ops2)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Operator`
  `addOperator(int key, Operator op)`
  Add an 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 an 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 op
  `Operator`
  `appendOperator(Operator op, Operator existingOp)`
  Add an operator which a new precedence level which is higher than the existing op
  `Operator`
  `getAdd()`
  Gets the operator used for addition
  `List<Operator>`
  `getAllOperatorsByName(String name)`
  Get all operators with a given name.
  `Operator`
  `getAnd()`
  Gets the operator used for logical AND
  `Operator`
  `getAssign()`
  Gets the operator used for assignment
  `Operator`
  `getCross()`
  Gets the operator used for 3D cross product
  `Operator`
  `getDivide()`
  Gets the operator used for division
  `Operator`
  `getDot()`
  Gets the operator used for the dot product
  `Operator`
  `getEle()`
  Gets the operator used for getting and setting elements of a list
  `Operator`
  `getEQ()`
  Gets the operator used for equals
  `Operator`
  `getGE()`
  Gets the operator used for greater than or equals to
  `Operator`
  `getGT()`
  Gets the operator used for greater-than
  `Operator`
  `getLE()`
  Gets the operator used for less-than or equals to
  `JepComponent`
  `getLightWeightInstance()`
  Gets a light-weight instance suitable for using in multiple threads.
  `Operator`
  `getList()`
  Gets the operator used for creation of lists `[1,2,3]`
  `Operator`
  `getLT()`
  Gets the operator used for less-than
  `Operator`
  `getMod()`
  Gets the operator used for modulus
  `Operator`
  `getMultiply()`
  Gets the operator used for multiplication
  `Operator`
  `getNE()`
  Gets the operator used for not equals
  `Operator`
  `getNop()`
  Gets the no-op operator
  `Operator`
  `getNot()`
  Gets the operator used for logical NOT
  `int`
  `getNumOps()`
  `Operator`
  `getOperator(int key)`
  Get operator by its key code.
  `Operator`
  `getOperatorByName(String name)`
  Get the operator with a given name
  `Collection<Operator>`
  `getOperators()`
  `Operator`
  `getOperatorsByName(String name)`
  Deprecated.
  Use `getOperatorByName(String)` or `getAllOperatorsByName(String)`
  `List<Operator>`
  `getOperatorsBySymbol(String symbol)`
  Gets all the operators with a given symbol
  `Operator`
  `getOr()`
  Gets the operator used for logical OR
  `Operator`
  `getPower()`
  Gets the operator used for powers
  `Operator`
  `getRange()`
  Gets the operator used for specifying a range
  `Operator`
  `getSubtract()`
  Gets the operator used for subtraction
  `Operator`
  `getUDivide()`
  unary division i.e. 1/x or x^(-1) *
  `Operator`
  `getUMinus()`
  Gets the operator used for unitary minus `-x`
  `Operator`
  `getUPlus()`
  Gets the operator used for unary addition `+x`
  `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 op
  `void`
  `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)`
  `final 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)`
  `String`
  `toString()`
  String rep operators ordered by precedence, one per line.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### 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 Details

  - ### OperatorTable

    public OperatorTable()

  - ### OperatorTable

    protected OperatorTable(Operator[] ops2)

- ## Method Details

  - ### init

    public void init(Jep jep)
    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 interface `JepComponent`
    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 an operator with a given key.
    Parameters:
      `key` - integer key value
      `op` -
    Returns:
      the operator op

  - ### addOperator

    public Operator addOperator(Operator op)
    Add an 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 operator
      `op` - 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 List<Operator> getOperatorsBySymbol(String symbol)
    Gets all the operators with a given symbol
    Specified by:
      `getOperatorsBySymbol` in interface `OperatorTableI`
    Parameters:
      `symbol` - symbol used for operator
    Returns:
      list of operators with a given symbol, empty list if none are found.

  - ### getOperatorsByName

    @Deprecated public Operator getOperatorsByName(String name)
    Deprecated.
    Use `getOperatorByName(String)` or `getAllOperatorsByName(String)`
    Get the operator with a given name
    Specified by:
      `getOperatorsByName` in interface `OperatorTableI`
    Parameters:
      `name` - unique name of operator
    Returns:
      the operator or null if not found

  - ### getOperatorByName

    public Operator getOperatorByName(String name)
    Get the operator with a given name
    Specified by:
      `getOperatorByName` in interface `OperatorTableI`
    Parameters:
      `name` - unique name of operator
    Returns:
      the operator or null if not found

  - ### getOperators

    public Collection<Operator> getOperators()
    Specified by:
      `getOperators` in interface `OperatorTableI`

  - ### 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 example

         setPrecedenceTable(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 +,-,*,/.
    - Unary addition: inverse is negation
    - Binary addition: inverse is subtraction
    - subtraction: root operator is addition, inverse is negation
    - Negation, unary subtraction: root operator is addition, binary inverse is subtraction
    - Unary multiplication: inverse is reciprocal
    - Binary multiplication: inverse is division
    - division: root operator is multiplication, inverse is reciprocal
    - reciprocal, unary division: root operator is multiplication, binary inverse is division addition is distributive over multiplication
    - addition is distributive over division
    - negation is distributive over addition

  - ### getNop

    public Operator getNop()
    Description copied from interface: `OperatorTableI`
    Gets the no-op operator
    Specified by:
      `getNop` in interface `OperatorTableI`

  - ### getAdd

    public Operator getAdd()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for addition
    Specified by:
      `getAdd` in interface `OperatorTableI`

  - ### getSubtract

    public Operator getSubtract()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for subtraction
    Specified by:
      `getSubtract` in interface `OperatorTableI`

  - ### getUMinus

    public Operator getUMinus()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for unitary minus `-x`
    Specified by:
      `getUMinus` in interface `OperatorTableI`

  - ### getUPlus

    public Operator getUPlus()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for unary addition `+x`
    Specified by:
      `getUPlus` in interface `OperatorTableI`

  - ### getMultiply

    public Operator getMultiply()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for multiplication
    Specified by:
      `getMultiply` in interface `OperatorTableI`

  - ### getDivide

    public Operator getDivide()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for division
    Specified by:
      `getDivide` in interface `OperatorTableI`

  - ### getMod

    public Operator getMod()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for modulus
    Specified by:
      `getMod` in interface `OperatorTableI`

  - ### getUDivide

    public Operator getUDivide()
    unary division i.e. 1/x or x^(-1) *
    Specified by:
      `getUDivide` in interface `OperatorTableI`

  - ### getPower

    public Operator getPower()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for powers
    Specified by:
      `getPower` in interface `OperatorTableI`

  - ### getGT

    public Operator getGT()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for greater-than
    Specified by:
      `getGT` in interface `OperatorTableI`

  - ### getLT

    public Operator getLT()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for less-than
    Specified by:
      `getLT` in interface `OperatorTableI`

  - ### getEQ

    public Operator getEQ()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for equals
    Specified by:
      `getEQ` in interface `OperatorTableI`

  - ### getLE

    public Operator getLE()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for less-than or equals to
    Specified by:
      `getLE` in interface `OperatorTableI`

  - ### getGE

    public Operator getGE()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for greater than or equals to
    Specified by:
      `getGE` in interface `OperatorTableI`

  - ### getNE

    public Operator getNE()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for not equals
    Specified by:
      `getNE` in interface `OperatorTableI`

  - ### getAnd

    public Operator getAnd()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for logical AND
    Specified by:
      `getAnd` in interface `OperatorTableI`

  - ### getOr

    public Operator getOr()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for logical OR
    Specified by:
      `getOr` in interface `OperatorTableI`

  - ### getNot

    public Operator getNot()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for logical NOT
    Specified by:
      `getNot` in interface `OperatorTableI`

  - ### getAssign

    public Operator getAssign()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for assignment
    Specified by:
      `getAssign` in interface `OperatorTableI`

  - ### getDot

    public Operator getDot()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for the dot product
    Specified by:
      `getDot` in interface `OperatorTableI`

  - ### getCross

    public Operator getCross()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for 3D cross product
    Specified by:
      `getCross` in interface `OperatorTableI`

  - ### getList

    public Operator getList()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for creation of lists `[1,2,3]`
    Specified by:
      `getList` in interface `OperatorTableI`

  - ### getEle

    public Operator getEle()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for getting and setting elements of a list
    Specified by:
      `getEle` in interface `OperatorTableI`

  - ### getRange

    public Operator getRange()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for specifying a range
    Specified by:
      `getRange` in interface `OperatorTableI`

  - ### toString

    public String toString()
    String rep operators ordered by precedence, one per line.
    Overrides:
      `toString` in class `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 interface `JepComponent`
    Returns:
      this

  - ### threadSafeMapCopy

    protected Operator[] threadSafeMapCopy(Operator[] ops2)

  - ### 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 interface `OperatorTableI`
    Returns:
      a new OperatorTable

  - ### getAllOperatorsByName

    public List<Operator> getAllOperatorsByName(String name)
    Description copied from interface: `OperatorTableI`
    Get all operators with a given name.
    Specified by:
      `getAllOperatorsByName` in interface `OperatorTableI`
    Parameters:
      `name` - unique name of operator
    Returns:
      the operator or null if not found