org.scijava.sjep.eval
Class DefaultEvaluator

java.lang.Object
  extended by org.scijava.sjep.eval.AbstractEvaluator
      extended by org.scijava.sjep.eval.AbstractStackEvaluator
          extended by org.scijava.sjep.eval.AbstractStandardStackEvaluator
              extended by org.scijava.sjep.eval.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.sjep.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 Summary
DefaultEvaluator()
           
DefaultEvaluator(ExpressionParser parser)
           
 
Method Summary
 BigDecimal add(BigDecimal a, BigDecimal b)
           
 BigInteger add(BigInteger a, BigInteger b)
           
 double add(double a, double b)
           
 float add(float a, float b)
           
 int add(int a, int b)
           
 long add(long a, long b)
           
 Object add(Object a, Object b)
          Applies the Operators.ADD operator.
 String add(String a, String b)
           
 BigInteger bitwiseAnd(BigInteger a, BigInteger b)
           
 int bitwiseAnd(int a, int b)
           
 long bitwiseAnd(long a, long b)
           
 Object bitwiseAnd(Object a, Object b)
          Applies the Operators.BITWISE_AND operator.
 BigInteger bitwiseOr(BigInteger a, BigInteger b)
           
 int bitwiseOr(int a, int b)
           
 long bitwiseOr(long a, long b)
           
 Object bitwiseOr(Object a, Object b)
          Applies the Operators.BITWISE_OR operator.
 Object colon(Object a, Object b)
          Applies the Operators.COLON operator.
 int complement(int a)
           
 long complement(long a)
           
 Object complement(Object a)
          Applies the Operators.COMPLEMENT operator.
 BigDecimal div(BigDecimal a, BigDecimal b)
           
 BigInteger div(BigInteger a, BigInteger b)
           
 double div(double a, double b)
           
 float div(float a, float b)
           
 int div(int a, int b)
           
 long div(long a, long b)
           
 Object div(Object a, Object b)
          Applies the Operators.DIV operator.
 Object dot(Object a, Object b)
          Applies the Operators.DOT operator.
 Object dotDiv(Object a, Object b)
          Applies the Operators.DOT_DIV operator.
 Object dotMul(Object a, Object b)
          Applies the Operators.DOT_MUL operator.
 Object dotPow(Object a, Object b)
          Applies the Operators.DOT_POW operator.
 Object dotRightDiv(Object a, Object b)
          Applies the Operators.DOT_RIGHT_DIV operator.
 Object dotTranspose(Object a)
          Applies the Operators.DOT_TRANSPOSE operator.
 Object equal(Object a, Object b)
          Applies the Operators.EQUAL operator.
<T> boolean
greaterThan(Comparable<T> a, T b)
           
 Object greaterThan(Object a, Object b)
          Applies the Operators.GREATER_THAN operator.
<T> boolean
greaterThanOrEqual(Comparable<T> a, T b)
           
 Object greaterThanOrEqual(Object a, Object b)
          Applies the Operators.GREATER_THAN_OR_EQUAL operator.
 Object instanceOf(Object a, Object b)
          Applies the Operators.INSTANCEOF operator.
 BigInteger leftShift(BigInteger a, int b)
           
 int leftShift(int a, int b)
           
 long leftShift(long a, long b)
           
 Object leftShift(Object a, Object b)
          Applies the Operators.LEFT_SHIFT operator.
<T> boolean
lessThan(Comparable<T> a, T b)
           
 Object lessThan(Object a, Object b)
          Applies the Operators.LESS_THAN operator.
<T> boolean
lessThanOrEqual(Comparable<T> a, T b)
           
 Object lessThanOrEqual(Object a, Object b)
          Applies the Operators.LESS_THAN_OR_EQUAL operator.
 boolean logicalAnd(boolean a, boolean b)
           
 Object logicalAnd(Object a, Object b)
          Applies the Operators.LOGICAL_AND operator.
 boolean logicalOr(boolean a, boolean b)
           
 Object logicalOr(Object a, Object b)
          Applies the Operators.LOGICAL_OR operator.
 BigDecimal mod(BigDecimal a, BigDecimal b)
           
 BigInteger mod(BigInteger a, BigInteger b)
           
 double mod(double a, double b)
           
 float mod(float a, float b)
           
 int mod(int a, int b)
           
 long mod(long a, long b)
           
 Object mod(Object a, Object b)
          Applies the Operators.MOD operator.
 BigDecimal mul(BigDecimal a, BigDecimal b)
           
 BigInteger mul(BigInteger a, BigInteger b)
           
 double mul(double a, double b)
           
 float mul(float a, float b)
           
 int mul(int a, int b)
           
 long mul(long a, long b)
           
 Object mul(Object a, Object b)
          Applies the Operators.MUL operator.
 BigDecimal neg(BigDecimal num)
           
 BigInteger neg(BigInteger num)
           
 double neg(double num)
           
 float neg(float num)
           
 int neg(int num)
           
 long neg(long num)
           
 Object neg(Object a)
          Applies the Operators.NEG operator.
 boolean not(boolean a)
           
 Object not(Object a)
          Applies the Operators.NOT operator.
 Object notEqual(Object a, Object b)
          Applies the Operators.NOT_EQUAL operator.
 double pos(double num)
           
 float pos(float num)
           
 int pos(int num)
           
 long pos(long num)
           
 Object pos(Object a)
          Applies the Operators.POS operator.
 BigDecimal pow(BigDecimal a, int b)
           
 BigInteger pow(BigInteger a, int b)
           
 double pow(double a, double b)
           
 Object pow(Object a, Object b)
          Applies the Operators.POW operator.
 Object rightDiv(Object a, Object b)
          Applies the Operators.RIGHT_DIV operator.
 BigInteger rightShift(BigInteger a, int b)
           
 int rightShift(int a, int b)
           
 long rightShift(long a, long b)
           
 Object rightShift(Object a, Object b)
          Applies the Operators.RIGHT_SHIFT operator.
 BigDecimal sub(BigDecimal a, BigDecimal b)
           
 BigInteger sub(BigInteger a, BigInteger b)
           
 double sub(double a, double b)
           
 float sub(float a, float b)
           
 int sub(int a, int b)
           
 long sub(long a, long b)
           
 Object sub(Object a, Object b)
          Applies the Operators.SUB operator.
 Object transpose(Object a)
          Applies the Operators.TRANSPOSE operator.
 int unsignedRightShift(int a, int b)
           
 long unsignedRightShift(long a, long b)
           
 Object unsignedRightShift(Object a, Object b)
          Applies the Operators.UNSIGNED_RIGHT_SHIFT operator.
 
Methods inherited from class org.scijava.sjep.eval.AbstractStandardStackEvaluator
addAssign, andAssign, assign, divAssign, dotDivAssign, dotPowAssign, dotRightDivAssign, execute, leftShiftAssign, modAssign, mulAssign, orAssign, postDec, postInc, powAssign, preDec, preInc, rightDivAssign, rightShiftAssign, subAssign, unsignedRightShiftAssign
 
Methods inherited from class org.scijava.sjep.eval.AbstractStackEvaluator
evaluate
 
Methods inherited from class org.scijava.sjep.eval.AbstractEvaluator
evaluate, evaluate, get, set, setAll, value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.scijava.sjep.eval.Evaluator
evaluate, evaluate, evaluate, get, set, setAll, value
 

Constructor Detail

DefaultEvaluator

public DefaultEvaluator()

DefaultEvaluator

public DefaultEvaluator(ExpressionParser parser)
Method Detail

dot

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


transpose

public Object transpose(Object a)
Description copied from interface: StandardEvaluator
Applies the Operators.TRANSPOSE operator.


dotTranspose

public Object dotTranspose(Object a)
Description copied from interface: StandardEvaluator
Applies the Operators.DOT_TRANSPOSE operator.


pow

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


pow

public double pow(double a,
                  double b)

pow

public BigInteger pow(BigInteger a,
                      int b)

pow

public BigDecimal pow(BigDecimal a,
                      int b)

dotPow

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


pos

public Object pos(Object a)
Description copied from interface: StandardEvaluator
Applies the Operators.POS 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 Object neg(Object a)
Description copied from interface: StandardEvaluator
Applies the Operators.NEG operator.


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 BigInteger neg(BigInteger num)

neg

public BigDecimal neg(BigDecimal num)

complement

public Object complement(Object a)
Description copied from interface: StandardEvaluator
Applies the Operators.COMPLEMENT operator.


complement

public int complement(int a)

complement

public long complement(long a)

not

public Object not(Object a)
Description copied from interface: StandardEvaluator
Applies the Operators.NOT operator.


not

public boolean not(boolean a)

mul

public Object mul(Object a,
                  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 BigInteger mul(BigInteger a,
                      BigInteger b)

mul

public BigDecimal mul(BigDecimal a,
                      BigDecimal b)

div

public Object div(Object a,
                  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 BigInteger div(BigInteger a,
                      BigInteger b)

div

public BigDecimal div(BigDecimal a,
                      BigDecimal b)

mod

public Object mod(Object a,
                  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 BigInteger mod(BigInteger a,
                      BigInteger b)

mod

public BigDecimal mod(BigDecimal a,
                      BigDecimal b)

rightDiv

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


dotMul

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


dotDiv

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


dotRightDiv

public Object dotRightDiv(Object a,
                          Object b)
Description copied from interface: StandardEvaluator
Applies the Operators.DOT_RIGHT_DIV operator.


add

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


add

public String add(String a,
                  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 BigInteger add(BigInteger a,
                      BigInteger b)

add

public BigDecimal add(BigDecimal a,
                      BigDecimal b)

sub

public Object sub(Object a,
                  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 BigInteger sub(BigInteger a,
                      BigInteger b)

sub

public BigDecimal sub(BigDecimal a,
                      BigDecimal b)

leftShift

public Object leftShift(Object a,
                        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 BigInteger leftShift(BigInteger a,
                            int b)

rightShift

public Object rightShift(Object a,
                         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 BigInteger rightShift(BigInteger a,
                             int b)

unsignedRightShift

public Object unsignedRightShift(Object a,
                                 Object b)
Description copied from interface: StandardEvaluator
Applies the Operators.UNSIGNED_RIGHT_SHIFT operator.


unsignedRightShift

public int unsignedRightShift(int a,
                              int b)

unsignedRightShift

public long unsignedRightShift(long a,
                               long b)

colon

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


lessThan

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


lessThan

public <T> boolean lessThan(Comparable<T> a,
                            T b)

greaterThan

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


greaterThan

public <T> boolean greaterThan(Comparable<T> a,
                               T b)

lessThanOrEqual

public Object lessThanOrEqual(Object a,
                              Object b)
Description copied from interface: StandardEvaluator
Applies the Operators.LESS_THAN_OR_EQUAL operator.


lessThanOrEqual

public <T> boolean lessThanOrEqual(Comparable<T> a,
                                   T b)

greaterThanOrEqual

public Object greaterThanOrEqual(Object a,
                                 Object b)
Description copied from interface: StandardEvaluator
Applies the Operators.GREATER_THAN_OR_EQUAL operator.


greaterThanOrEqual

public <T> boolean greaterThanOrEqual(Comparable<T> a,
                                      T b)

instanceOf

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


equal

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


notEqual

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


bitwiseAnd

public Object bitwiseAnd(Object a,
                         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 BigInteger bitwiseAnd(BigInteger a,
                             BigInteger b)

bitwiseOr

public Object bitwiseOr(Object a,
                        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 BigInteger bitwiseOr(BigInteger a,
                            BigInteger b)

logicalAnd

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


logicalAnd

public boolean logicalAnd(boolean a,
                          boolean b)

logicalOr

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


logicalOr

public boolean logicalOr(boolean a,
                         boolean b)


Copyright © 2015 SciJava. All rights reserved.