Class OperatorTable

    • 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 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 a operator with a given key.
        Parameters:
        key - integer key value
        op -
        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 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 java.util.List<Operator> getOperatorsBySymbol​(java.lang.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

        public Operator getOperatorsByName​(java.lang.String name)
        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
      • 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 +,-,*,/
      • toString

        public java.lang.String toString()
        String rep operators ordered by precedence, one per line.
        Overrides:
        toString in class java.lang.Object
      • 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