Class DefaultEvaluator

  • All Implemented Interfaces:
    Evaluator, StackEvaluator, StandardEvaluator

    public class DefaultEvaluator
    extends AbstractStandardStackEvaluator
    An expression evaluator for most standard operators with common built-in types (i.e.: Booleans, Strings and Numbers).

    Caveats

    This class is a big bag of case logic for various operators and types. Looking at it, you might think: "It sure would be nice to modularize this, with each operation in its own class, with properly declared types, and called dynamically at runtime as appropriate."

    "Great idea!" I would reply. Then I would suggest you have a look at the SciJava Ops and ImageJ Ops projects, which do exactly that in an extensible way.

    Or maybe you are thinking: "This can't possibly work as well as awesome JVM-based scripting languages like Jython and Groovy..."

    To which I would reply: "You are absolutely right! This class is mostly just a demonstration of an extensible, working evaluator built using the org.scijava.parse.eval package. If your use case is only concerned with feature-rich evaluation of standard types, then building on top of a scripting language might make more sense."

    Author:
    Curtis Rueden
    See Also:
    The main class, to give it a spin.
    • Constructor Detail

      • DefaultEvaluator

        public DefaultEvaluator()
    • Method Detail

      • function

        public java.lang.Object function​(java.lang.Object a,
                                         java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Function operator.
      • dot

        public java.lang.Object dot​(java.lang.Object a,
                                    java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.DOT operator.
      • pow

        public java.lang.Object pow​(java.lang.Object a,
                                    java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.POW operator.
      • pow

        public double pow​(double a,
                          double b)
      • pow

        public java.math.BigInteger pow​(java.math.BigInteger a,
                                        int b)
      • pow

        public java.math.BigDecimal pow​(java.math.BigDecimal a,
                                        int b)
      • dotPow

        public java.lang.Object dotPow​(java.lang.Object a,
                                       java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.DOT_POW operator.
      • pos

        public int pos​(int num)
      • pos

        public long pos​(long num)
      • pos

        public float pos​(float num)
      • pos

        public double pos​(double num)
      • neg

        public int neg​(int num)
      • neg

        public long neg​(long num)
      • neg

        public float neg​(float num)
      • neg

        public double neg​(double num)
      • neg

        public java.math.BigInteger neg​(java.math.BigInteger num)
      • neg

        public java.math.BigDecimal neg​(java.math.BigDecimal num)
      • complement

        public int complement​(int a)
      • complement

        public long complement​(long a)
      • not

        public boolean not​(boolean a)
      • mul

        public java.lang.Object mul​(java.lang.Object a,
                                    java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.MUL operator.
      • mul

        public int mul​(int a,
                       int b)
      • mul

        public long mul​(long a,
                        long b)
      • mul

        public float mul​(float a,
                         float b)
      • mul

        public double mul​(double a,
                          double b)
      • mul

        public java.math.BigInteger mul​(java.math.BigInteger a,
                                        java.math.BigInteger b)
      • mul

        public java.math.BigDecimal mul​(java.math.BigDecimal a,
                                        java.math.BigDecimal b)
      • div

        public java.lang.Object div​(java.lang.Object a,
                                    java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.DIV operator.
      • div

        public int div​(int a,
                       int b)
      • div

        public long div​(long a,
                        long b)
      • div

        public float div​(float a,
                         float b)
      • div

        public double div​(double a,
                          double b)
      • div

        public java.math.BigInteger div​(java.math.BigInteger a,
                                        java.math.BigInteger b)
      • div

        public java.math.BigDecimal div​(java.math.BigDecimal a,
                                        java.math.BigDecimal b)
      • mod

        public java.lang.Object mod​(java.lang.Object a,
                                    java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.MOD operator.
      • mod

        public int mod​(int a,
                       int b)
      • mod

        public long mod​(long a,
                        long b)
      • mod

        public float mod​(float a,
                         float b)
      • mod

        public double mod​(double a,
                          double b)
      • mod

        public java.math.BigInteger mod​(java.math.BigInteger a,
                                        java.math.BigInteger b)
      • mod

        public java.math.BigDecimal mod​(java.math.BigDecimal a,
                                        java.math.BigDecimal b)
      • rightDiv

        public java.lang.Object rightDiv​(java.lang.Object a,
                                         java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.RIGHT_DIV operator.
      • dotMul

        public java.lang.Object dotMul​(java.lang.Object a,
                                       java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.DOT_MUL operator.
      • dotDiv

        public java.lang.Object dotDiv​(java.lang.Object a,
                                       java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.DOT_DIV operator.
      • add

        public java.lang.Object add​(java.lang.Object a,
                                    java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.ADD operator.
      • add

        public java.lang.String add​(java.lang.String a,
                                    java.lang.String b)
      • add

        public int add​(int a,
                       int b)
      • add

        public long add​(long a,
                        long b)
      • add

        public float add​(float a,
                         float b)
      • add

        public double add​(double a,
                          double b)
      • add

        public java.math.BigInteger add​(java.math.BigInteger a,
                                        java.math.BigInteger b)
      • add

        public java.math.BigDecimal add​(java.math.BigDecimal a,
                                        java.math.BigDecimal b)
      • sub

        public java.lang.Object sub​(java.lang.Object a,
                                    java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.SUB operator.
      • sub

        public int sub​(int a,
                       int b)
      • sub

        public long sub​(long a,
                        long b)
      • sub

        public float sub​(float a,
                         float b)
      • sub

        public double sub​(double a,
                          double b)
      • sub

        public java.math.BigInteger sub​(java.math.BigInteger a,
                                        java.math.BigInteger b)
      • sub

        public java.math.BigDecimal sub​(java.math.BigDecimal a,
                                        java.math.BigDecimal b)
      • leftShift

        public java.lang.Object leftShift​(java.lang.Object a,
                                          java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.LEFT_SHIFT operator.
      • leftShift

        public int leftShift​(int a,
                             int b)
      • leftShift

        public long leftShift​(long a,
                              long b)
      • leftShift

        public java.math.BigInteger leftShift​(java.math.BigInteger a,
                                              int b)
      • rightShift

        public java.lang.Object rightShift​(java.lang.Object a,
                                           java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.RIGHT_SHIFT operator.
      • rightShift

        public int rightShift​(int a,
                              int b)
      • rightShift

        public long rightShift​(long a,
                               long b)
      • rightShift

        public java.math.BigInteger rightShift​(java.math.BigInteger a,
                                               int b)
      • unsignedRightShift

        public int unsignedRightShift​(int a,
                                      int b)
      • unsignedRightShift

        public long unsignedRightShift​(long a,
                                       long b)
      • colon

        public java.lang.Object colon​(java.lang.Object a,
                                      java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.COLON operator.
      • lessThan

        public java.lang.Object lessThan​(java.lang.Object a,
                                         java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.LESS_THAN operator.
      • lessThan

        public <T> boolean lessThan​(java.lang.Comparable<T> a,
                                    T b)
      • greaterThan

        public java.lang.Object greaterThan​(java.lang.Object a,
                                            java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.GREATER_THAN operator.
      • greaterThan

        public <T> boolean greaterThan​(java.lang.Comparable<T> a,
                                       T b)
      • lessThanOrEqual

        public <T> boolean lessThanOrEqual​(java.lang.Comparable<T> a,
                                           T b)
      • greaterThanOrEqual

        public <T> boolean greaterThanOrEqual​(java.lang.Comparable<T> a,
                                              T b)
      • instanceOf

        public java.lang.Object instanceOf​(java.lang.Object a,
                                           java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.INSTANCEOF operator.
      • equal

        public java.lang.Object equal​(java.lang.Object a,
                                      java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.EQUAL operator.
      • notEqual

        public java.lang.Object notEqual​(java.lang.Object a,
                                         java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.NOT_EQUAL operator.
      • bitwiseAnd

        public java.lang.Object bitwiseAnd​(java.lang.Object a,
                                           java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.BITWISE_AND operator.
      • bitwiseAnd

        public int bitwiseAnd​(int a,
                              int b)
      • bitwiseAnd

        public long bitwiseAnd​(long a,
                               long b)
      • bitwiseAnd

        public java.math.BigInteger bitwiseAnd​(java.math.BigInteger a,
                                               java.math.BigInteger b)
      • bitwiseOr

        public java.lang.Object bitwiseOr​(java.lang.Object a,
                                          java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.BITWISE_OR operator.
      • bitwiseOr

        public int bitwiseOr​(int a,
                             int b)
      • bitwiseOr

        public long bitwiseOr​(long a,
                              long b)
      • bitwiseOr

        public java.math.BigInteger bitwiseOr​(java.math.BigInteger a,
                                              java.math.BigInteger b)
      • logicalAnd

        public java.lang.Object logicalAnd​(java.lang.Object a,
                                           java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.LOGICAL_AND operator.
      • logicalAnd

        public boolean logicalAnd​(boolean a,
                                  boolean b)
      • logicalOr

        public java.lang.Object logicalOr​(java.lang.Object a,
                                          java.lang.Object b)
        Description copied from interface: StandardEvaluator
        Applies the Operators.LOGICAL_OR operator.
      • logicalOr

        public boolean logicalOr​(boolean a,
                                 boolean b)