Class CustomOperator

  • public abstract class CustomOperatorextends Object
    This class is used to create custom operators for use in expressions
    The applyOperation(double[] values) will have to be implemented by users of this class.
           CustomOperator greaterEq = new CustomOperator(">=", true, 4, 2) {            double applyOperation(double[] values) {                if (values[0] >= values[1]){                        return 1d;                }else{                        return 0d;                }            }        };       Calculable calc = new ExpressionBuilder("1>=2").withOperation(greaterEq).build();       assertTrue(0d == calc.calculate()); 
    When constructing CustomOperator special attention has to be given to the precedence of the operation. see The precendence values for the builtin operators are as follows:
    Addition and Subtraction (+,-) have precedence 1
    Division Multiplication, and Modulo (/,*,%) have precedence 3
    Exponentiation (^) has precendence 5
    Unary minus and plus (+1,-1) have precedence 7

SCaVis 2.2 © jWork.ORG