Package com.singularsys.jep

# Class EmptyOperatorTable

java.lang.Object
com.singularsys.jep.EmptyOperatorTable

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

Direct Known Subclasses:
  `OperatorTable2`

public class EmptyOperatorTable extends Object implements OperatorTableI
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:
  - Serialized Form

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static interface`
  `EmptyOperatorTable.OperatorKey`
  All operators enums must implement this interface.

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  ``
  `EmptyOperatorTable()`
  Constructor with an empty map.
  `protected`
  `EmptyOperatorTable(Map<EmptyOperatorTable.OperatorKey,Operator> oldMap)`
  Constructor with a specified map.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Operator`
  `addOperator(EmptyOperatorTable.OperatorKey key, Operator op)`
  Add an operator with a given key.
  `Operator`
  `addOperator(EmptyOperatorTable.OperatorKey key, Operator op, Operator existingOp)`
  Add operator with the same precedence level as an existing operator.
  `Operator`
  `addOperator(Operator op, Operator existingOp)`
  Add operator with the same precedence level as an existing operator.
  `Operator`
  `appendOperator(EmptyOperatorTable.OperatorKey key, Operator op, Operator existingOp)`
  Add an operator with a new precedence level which is lower than the existing op.
  `Operator`
  `appendOperator(Operator op, Operator existingOp)`
  Add an operator with a new precedence level which is lower than the existing op.
  `Set<Map.Entry<EmptyOperatorTable.OperatorKey,Operator>>`
  `entrySet()`
  `Operator`
  `getAdd()`
  Returns 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
  `EmptyOperatorTable.OperatorKey`
  `getKey(Operator op)`
  Deprecated.
  Use `getKeys(Operator)` instead.
  `List<EmptyOperatorTable.OperatorKey>`
  `getKeys(Operator op)`
  Return all the keys associated with an operator.
  `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(EmptyOperatorTable.OperatorKey key)`
  Get operator by its key code.
  `Operator`
  `getOperatorByName(String name)`
  Get the first operator with a given name
  `protected Map<EmptyOperatorTable.OperatorKey,Operator>`
  `getOperatorMap()`
  `Collection<Operator>`
  `getOperators()`
  Return the full list of operators
  `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(EmptyOperatorTable.OperatorKey key, Operator op, Operator existingOp)`
  Add an operator with a new precedence level which is equal to the existing op.
  `Operator`
  `insertOperator(Operator op, Operator existingOp)`
  Add an operator with a new precedence level which is equal to the existing op.
  `Set<EmptyOperatorTable.OperatorKey>`
  `keySet()`
  `void`
  `removeOperator(EmptyOperatorTable.OperatorKey key)`
  Remove a give operator from the table
  `void`
  `removeOperator(Operator op)`
  Remove a give operator from the table, removes all entries with this value.
  `void`
  `replaceOperator(EmptyOperatorTable.OperatorKey key, Operator op)`
  Replace a give operator with a new one.
  `void`
  `replaceOperator(Operator oldOp, Operator op)`
  Replace a give operator with a new one.
  `protected boolean`
  `setBinaryInverseOp(EmptyOperatorTable.OperatorKey key1, EmptyOperatorTable.OperatorKey key2)`
  `protected boolean`
  `setDistributiveOver(EmptyOperatorTable.OperatorKey key1, EmptyOperatorTable.OperatorKey key2)`
  `protected void`
  `setGroupOperatorRelations(EmptyOperatorTable.OperatorKey root, EmptyOperatorTable.OperatorKey inv, EmptyOperatorTable.OperatorKey composite)`
  Sets relations of three operators.
  `protected void`
  `setGroupOperatorRelations(Operator root, Operator inv, Operator composite)`
  Sets relations of three operators.
  `protected boolean`
  `setInverseOp(EmptyOperatorTable.OperatorKey key1, EmptyOperatorTable.OperatorKey key2)`
  `final boolean`
  `setPrecedenceTable(EmptyOperatorTable.OperatorKey[][] precArray)`
  Sets the precedence of all operators at one time.
  `protected boolean`
  `setRootOp(EmptyOperatorTable.OperatorKey key1, EmptyOperatorTable.OperatorKey key2)`
  `protected void`
  `setStandardOperatorRelations()`
  Sets up the standard relations between +,-,*,/
  `OperatorTableI`
  `shallowCopy()`
  Create a new version of this OperatorTable.
  `protected Map<EmptyOperatorTable.OperatorKey,Operator>`
  `threadSafeMapCopy()`
  Creates a copy of the internal map used for operators.
  `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`

- ## Constructor Details

  - ### EmptyOperatorTable

    public EmptyOperatorTable()
    Constructor with an empty map.

  - ### EmptyOperatorTable

    protected EmptyOperatorTable(Map<EmptyOperatorTable.OperatorKey,Operator> oldMap)
    Constructor with a specified map. Subclasses should define similar constructors to allow the `shallowCopy()` to work.
    Parameters:
      `oldMap` - map with existing set of functions
    Since:
      4.0

- ## Method Details

  - ### getAdd

    public Operator getAdd()
    Returns the operator used for addition.
    Specified by:
      `getAdd` 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`

  - ### getAssign

    public Operator getAssign()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for assignment
    Specified by:
      `getAssign` 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`

  - ### getDivide

    public Operator getDivide()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for division
    Specified by:
      `getDivide` 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`

  - ### getEQ

    public Operator getEQ()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for equals
    Specified by:
      `getEQ` 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`

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

  - ### getGT

    public Operator getGT()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for greater-than
    Specified by:
      `getGT` 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`

  - ### getLT

    public Operator getLT()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for less-than
    Specified by:
      `getLT` 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`

  - ### getMod

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

  - ### getMultiply

    public Operator getMultiply()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for multiplication
    Specified by:
      `getMultiply` 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`

  - ### getNop

    public Operator getNop()
    Description copied from interface: `OperatorTableI`
    Gets the no-op operator
    Specified by:
      `getNop` 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`

  - ### getOr

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

  - ### getPower

    public Operator getPower()
    Description copied from interface: `OperatorTableI`
    Gets the operator used for powers
    Specified by:
      `getPower` 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`

  - ### getSubtract

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

  - ### getUDivide

    public Operator getUDivide()
    Description copied from interface: `OperatorTableI`
    unary division i.e. 1/x or x^(-1) *
    Specified by:
      `getUDivide` 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`

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

  - ### getNumOps

    public int getNumOps()

  - ### addOperator

    public Operator addOperator(EmptyOperatorTable.OperatorKey key, Operator op)
    Add an operator with a given key. The precedence will need to be set by `setPrecedenceTable(OperatorKey[][])`.
    Parameters:
      `key` - key value used to identify the operator
      `op` - operator
    Returns:
      the operator op

  - ### addOperator

    public Operator addOperator(EmptyOperatorTable.OperatorKey key, Operator op, Operator existingOp)
    Add operator with the same precedence level as an existing operator.
    Parameters:
      `key` - unique key used to identify the operator.
      `op` - the new operator
      `existingOp` - and existing operator, the precedence of this operator will be the same as the existing operator.
    Returns:
      the operator

  - ### addOperator

    public Operator addOperator(Operator op, Operator existingOp)
    Add operator with the same precedence level as an existing operator. The key will be automatically generated, and it can be recovered using `getKey(Operator)`.
    Parameters:
      `op` - the new operator
      `existingOp` - 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 operator
      `op` -
      `existingOp` -
    Returns:
      the operator

  - ### insertOperator

    public Operator insertOperator(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. The key will be automatically generated, and it can be recovered using `getKey(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

    public Operator appendOperator(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. The key will be automatically generated, and it can be recovered using `getKey(Operator)`.
    Parameters:
      `op` - Operator to add
      `existingOp` - operator to copy precedence from
    Returns:
      the operator

  - ### getKey

    @Deprecated(since="Jep 4.1") public EmptyOperatorTable.OperatorKey getKey(Operator op)
    Deprecated.
    Use `getKeys(Operator)` instead.
    Gets the key associated with a specific operator. Deprecated since Jep 4.1 as it is possible, but not recommended to have multiple keys with the same operator.
    Parameters:
      `op` -
    Returns:
      the key, null if op is not in the table

  - ### getKeys

    public List<EmptyOperatorTable.OperatorKey> getKeys(Operator op)
    Return all the keys associated with an operator. This should normally be a list with a single item, so this method can be used to test for miss-configuration.
    Parameters:
      `op` - the Operator to search for
    Returns:
      a list of keys, typically with a single item.
    Since:
      Jep 4.1

  - ### removeOperator

    public void removeOperator(Operator op)
    Remove a give operator from the table, removes all entries with this value.
    Parameters:
      `op` -

  - ### removeOperator

    public void removeOperator(EmptyOperatorTable.OperatorKey key)
    Remove a give operator from the table
    Parameters:
      `key` -

  - ### replaceOperator

    public void replaceOperator(Operator oldOp, Operator op)
    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 replaced
      `op` - the new operator
    Throws:
      `JepRuntimeException` - if more than one key is found for the old operator

  - ### replaceOperator

    public void replaceOperator(EmptyOperatorTable.OperatorKey key, Operator op)
    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 operator
      `op` - the new operator

  - ### getOperator

    public Operator getOperator(EmptyOperatorTable.OperatorKey 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.

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

  - ### getOperatorsByName

    @Deprecated(since="Jep 4.1") public Operator getOperatorsByName(String name)
    Deprecated.
    Use `getOperatorByName(String)` or `getAllOperatorsByName(String)`
    Description copied from interface: `OperatorTableI`
    Get the operator with a given name. Deprecated since 4.1, use `OperatorTableI.getOperatorByName(String)` instead, as this method name is misleading, as it returns only one operator.
    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 first 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
    Since:
      Jep 4.1

  - ### getOperators

    public Collection<Operator> getOperators()
    Return the full list of operators
    Specified by:
      `getOperators` in interface `OperatorTableI`

  - ### entrySet

    public Set<Map.Entry<EmptyOperatorTable.OperatorKey,Operator>> entrySet()

  - ### getOperatorMap

    protected Map<EmptyOperatorTable.OperatorKey,Operator> getOperatorMap()

  - ### keySet

    public Set<EmptyOperatorTable.OperatorKey> keySet()

  - ### setPrecedenceTable

    public final boolean setPrecedenceTable(EmptyOperatorTable.OperatorKey[][] 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 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

    protected void setGroupOperatorRelations(Operator root, Operator inv, Operator composite)
    Sets relations of three operators. A mathematical group has three related operators the root operator `x+y`, the inverse `uminus z`, and composite `x-y = x+(uminus y)`
    Parameters:
      `root` - the root operator i.e. ADD
      `inv` - the inverse operator i.e. UMINUS
      `composite` - 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 operator `x+y`, the inverse `uminus z`, and composite `x-y = x+(uminus y)`
    Parameters:
      `root` - the root operator i.e. ADD
      `inv` - the inverse operator i.e. UMINUS
      `composite` - the composite operator i.e. SUBTRACT

  - ### setStandardOperatorRelations

    protected void setStandardOperatorRelations()
    Sets up the standard relations between +,-,*,/

  - ### toString

    public String toString()
    String rep operators ordered by precedence, one per line.
    Overrides:
      `toString` in class `Object`

  - ### shallowCopy

    public OperatorTableI 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 the `threadSafeMapCopy()` method to return a copy of the map of operators and a constructor taking this map which uses the `EmptyOperatorTable(Map)` constructor.
    Specified by:
      `shallowCopy` in interface `OperatorTableI`
    Returns:
      a new Table

  - ### 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 Map<EmptyOperatorTable.OperatorKey,Operator> 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.