Class DefaultEvaluator
- java.lang.Object
-
- org.scijava.parse.eval.AbstractEvaluator
-
- org.scijava.parse.eval.AbstractStackEvaluator
-
- org.scijava.parse.eval.AbstractStandardStackEvaluator
-
- org.scijava.parse.eval.DefaultEvaluator
-
- All Implemented Interfaces:
Evaluator
,StackEvaluator
,StandardEvaluator
public class DefaultEvaluator extends AbstractStandardStackEvaluator
An expression evaluator for moststandard operators
with common built-in types (i.e.:Boolean
s,String
s andNumber
s).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 Summary
Constructors Constructor Description DefaultEvaluator()
DefaultEvaluator(ExpressionParser parser)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
add(double a, double b)
float
add(float a, float b)
int
add(int a, int b)
long
add(long a, long b)
java.lang.Object
add(java.lang.Object a, java.lang.Object b)
Applies theOperators.ADD
operator.java.lang.String
add(java.lang.String a, java.lang.String b)
java.math.BigDecimal
add(java.math.BigDecimal a, java.math.BigDecimal b)
java.math.BigInteger
add(java.math.BigInteger a, java.math.BigInteger b)
int
bitwiseAnd(int a, int b)
long
bitwiseAnd(long a, long b)
java.lang.Object
bitwiseAnd(java.lang.Object a, java.lang.Object b)
Applies theOperators.BITWISE_AND
operator.java.math.BigInteger
bitwiseAnd(java.math.BigInteger a, java.math.BigInteger b)
int
bitwiseOr(int a, int b)
long
bitwiseOr(long a, long b)
java.lang.Object
bitwiseOr(java.lang.Object a, java.lang.Object b)
Applies theOperators.BITWISE_OR
operator.java.math.BigInteger
bitwiseOr(java.math.BigInteger a, java.math.BigInteger b)
java.lang.Object
braces(java.lang.Object[] args)
Applies theOperators.BRACES
operator.java.lang.Object
brackets(java.lang.Object[] args)
Applies theOperators.BRACKETS
operator.java.lang.Object
colon(java.lang.Object a, java.lang.Object b)
Applies theOperators.COLON
operator.int
complement(int a)
long
complement(long a)
java.lang.Object
complement(java.lang.Object a)
Applies theOperators.COMPLEMENT
operator.double
div(double a, double b)
float
div(float a, float b)
int
div(int a, int b)
long
div(long a, long b)
java.lang.Object
div(java.lang.Object a, java.lang.Object b)
Applies theOperators.DIV
operator.java.math.BigDecimal
div(java.math.BigDecimal a, java.math.BigDecimal b)
java.math.BigInteger
div(java.math.BigInteger a, java.math.BigInteger b)
java.lang.Object
dot(java.lang.Object a, java.lang.Object b)
Applies theOperators.DOT
operator.java.lang.Object
dotDiv(java.lang.Object a, java.lang.Object b)
Applies theOperators.DOT_DIV
operator.java.lang.Object
dotMul(java.lang.Object a, java.lang.Object b)
Applies theOperators.DOT_MUL
operator.java.lang.Object
dotPow(java.lang.Object a, java.lang.Object b)
Applies theOperators.DOT_POW
operator.java.lang.Object
dotRightDiv(java.lang.Object a, java.lang.Object b)
Applies theOperators.DOT_RIGHT_DIV
operator.java.lang.Object
dotTranspose(java.lang.Object a)
Applies theOperators.DOT_TRANSPOSE
operator.java.lang.Object
equal(java.lang.Object a, java.lang.Object b)
Applies theOperators.EQUAL
operator.java.lang.Object
function(java.lang.Object a, java.lang.Object b)
Applies theFunction
operator.<T> boolean
greaterThan(java.lang.Comparable<T> a, T b)
java.lang.Object
greaterThan(java.lang.Object a, java.lang.Object b)
Applies theOperators.GREATER_THAN
operator.<T> boolean
greaterThanOrEqual(java.lang.Comparable<T> a, T b)
java.lang.Object
greaterThanOrEqual(java.lang.Object a, java.lang.Object b)
Applies theOperators.GREATER_THAN_OR_EQUAL
operator.java.lang.Object
instanceOf(java.lang.Object a, java.lang.Object b)
Applies theOperators.INSTANCEOF
operator.int
leftShift(int a, int b)
long
leftShift(long a, long b)
java.lang.Object
leftShift(java.lang.Object a, java.lang.Object b)
Applies theOperators.LEFT_SHIFT
operator.java.math.BigInteger
leftShift(java.math.BigInteger a, int b)
<T> boolean
lessThan(java.lang.Comparable<T> a, T b)
java.lang.Object
lessThan(java.lang.Object a, java.lang.Object b)
Applies theOperators.LESS_THAN
operator.<T> boolean
lessThanOrEqual(java.lang.Comparable<T> a, T b)
java.lang.Object
lessThanOrEqual(java.lang.Object a, java.lang.Object b)
Applies theOperators.LESS_THAN_OR_EQUAL
operator.boolean
logicalAnd(boolean a, boolean b)
java.lang.Object
logicalAnd(java.lang.Object a, java.lang.Object b)
Applies theOperators.LOGICAL_AND
operator.boolean
logicalOr(boolean a, boolean b)
java.lang.Object
logicalOr(java.lang.Object a, java.lang.Object b)
Applies theOperators.LOGICAL_OR
operator.double
mod(double a, double b)
float
mod(float a, float b)
int
mod(int a, int b)
long
mod(long a, long b)
java.lang.Object
mod(java.lang.Object a, java.lang.Object b)
Applies theOperators.MOD
operator.java.math.BigDecimal
mod(java.math.BigDecimal a, java.math.BigDecimal b)
java.math.BigInteger
mod(java.math.BigInteger a, java.math.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)
java.lang.Object
mul(java.lang.Object a, java.lang.Object b)
Applies theOperators.MUL
operator.java.math.BigDecimal
mul(java.math.BigDecimal a, java.math.BigDecimal b)
java.math.BigInteger
mul(java.math.BigInteger a, java.math.BigInteger b)
double
neg(double num)
float
neg(float num)
int
neg(int num)
long
neg(long num)
java.lang.Object
neg(java.lang.Object a)
Applies theOperators.NEG
operator.java.math.BigDecimal
neg(java.math.BigDecimal num)
java.math.BigInteger
neg(java.math.BigInteger num)
boolean
not(boolean a)
java.lang.Object
not(java.lang.Object a)
Applies theOperators.NOT
operator.java.lang.Object
notEqual(java.lang.Object a, java.lang.Object b)
Applies theOperators.NOT_EQUAL
operator.java.lang.Object
parens(java.lang.Object[] args)
Applies theOperators.PARENS
operator.double
pos(double num)
float
pos(float num)
int
pos(int num)
long
pos(long num)
java.lang.Object
pos(java.lang.Object a)
Applies theOperators.POS
operator.double
pow(double a, double b)
java.lang.Object
pow(java.lang.Object a, java.lang.Object b)
Applies theOperators.POW
operator.java.math.BigDecimal
pow(java.math.BigDecimal a, int b)
java.math.BigInteger
pow(java.math.BigInteger a, int b)
java.lang.Object
rightDiv(java.lang.Object a, java.lang.Object b)
Applies theOperators.RIGHT_DIV
operator.int
rightShift(int a, int b)
long
rightShift(long a, long b)
java.lang.Object
rightShift(java.lang.Object a, java.lang.Object b)
Applies theOperators.RIGHT_SHIFT
operator.java.math.BigInteger
rightShift(java.math.BigInteger a, int 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)
java.lang.Object
sub(java.lang.Object a, java.lang.Object b)
Applies theOperators.SUB
operator.java.math.BigDecimal
sub(java.math.BigDecimal a, java.math.BigDecimal b)
java.math.BigInteger
sub(java.math.BigInteger a, java.math.BigInteger b)
java.lang.Object
transpose(java.lang.Object a)
Applies theOperators.TRANSPOSE
operator.int
unsignedRightShift(int a, int b)
long
unsignedRightShift(long a, long b)
java.lang.Object
unsignedRightShift(java.lang.Object a, java.lang.Object b)
Applies theOperators.UNSIGNED_RIGHT_SHIFT
operator.-
Methods inherited from class org.scijava.parse.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.parse.eval.AbstractStackEvaluator
evaluate
-
Methods inherited from class org.scijava.parse.eval.AbstractEvaluator
evaluate, evaluate, get, getParser, isStrict, set, setAll, setStrict, value
-
-
-
-
Constructor Detail
-
DefaultEvaluator
public DefaultEvaluator()
-
DefaultEvaluator
public DefaultEvaluator(ExpressionParser parser)
-
-
Method Detail
-
function
public java.lang.Object function(java.lang.Object a, java.lang.Object b)
Description copied from interface:StandardEvaluator
Applies theFunction
operator.
-
dot
public java.lang.Object dot(java.lang.Object a, java.lang.Object b)
Description copied from interface:StandardEvaluator
Applies theOperators.DOT
operator.
-
parens
public java.lang.Object parens(java.lang.Object[] args)
Description copied from interface:StandardEvaluator
Applies theOperators.PARENS
operator.
-
brackets
public java.lang.Object brackets(java.lang.Object[] args)
Description copied from interface:StandardEvaluator
Applies theOperators.BRACKETS
operator.
-
braces
public java.lang.Object braces(java.lang.Object[] args)
Description copied from interface:StandardEvaluator
Applies theOperators.BRACES
operator.
-
transpose
public java.lang.Object transpose(java.lang.Object a)
Description copied from interface:StandardEvaluator
Applies theOperators.TRANSPOSE
operator.
-
dotTranspose
public java.lang.Object dotTranspose(java.lang.Object a)
Description copied from interface:StandardEvaluator
Applies theOperators.DOT_TRANSPOSE
operator.
-
pow
public java.lang.Object pow(java.lang.Object a, java.lang.Object b)
Description copied from interface:StandardEvaluator
Applies theOperators.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 theOperators.DOT_POW
operator.
-
pos
public java.lang.Object pos(java.lang.Object a)
Description copied from interface:StandardEvaluator
Applies theOperators.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 java.lang.Object neg(java.lang.Object a)
Description copied from interface:StandardEvaluator
Applies theOperators.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 java.math.BigInteger neg(java.math.BigInteger num)
-
neg
public java.math.BigDecimal neg(java.math.BigDecimal num)
-
complement
public java.lang.Object complement(java.lang.Object a)
Description copied from interface:StandardEvaluator
Applies theOperators.COMPLEMENT
operator.
-
complement
public int complement(int a)
-
complement
public long complement(long a)
-
not
public java.lang.Object not(java.lang.Object a)
Description copied from interface:StandardEvaluator
Applies theOperators.NOT
operator.
-
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 theOperators.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 theOperators.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 theOperators.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 theOperators.RIGHT_DIV
operator.
-
dotMul
public java.lang.Object dotMul(java.lang.Object a, java.lang.Object b)
Description copied from interface:StandardEvaluator
Applies theOperators.DOT_MUL
operator.
-
dotDiv
public java.lang.Object dotDiv(java.lang.Object a, java.lang.Object b)
Description copied from interface:StandardEvaluator
Applies theOperators.DOT_DIV
operator.
-
dotRightDiv
public java.lang.Object dotRightDiv(java.lang.Object a, java.lang.Object b)
Description copied from interface:StandardEvaluator
Applies theOperators.DOT_RIGHT_DIV
operator.
-
add
public java.lang.Object add(java.lang.Object a, java.lang.Object b)
Description copied from interface:StandardEvaluator
Applies theOperators.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 theOperators.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 theOperators.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 theOperators.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 java.lang.Object unsignedRightShift(java.lang.Object a, java.lang.Object b)
Description copied from interface:StandardEvaluator
Applies theOperators.UNSIGNED_RIGHT_SHIFT
operator.
-
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 theOperators.COLON
operator.
-
lessThan
public java.lang.Object lessThan(java.lang.Object a, java.lang.Object b)
Description copied from interface:StandardEvaluator
Applies theOperators.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 theOperators.GREATER_THAN
operator.
-
greaterThan
public <T> boolean greaterThan(java.lang.Comparable<T> a, T b)
-
lessThanOrEqual
public java.lang.Object lessThanOrEqual(java.lang.Object a, java.lang.Object b)
Description copied from interface:StandardEvaluator
Applies theOperators.LESS_THAN_OR_EQUAL
operator.
-
lessThanOrEqual
public <T> boolean lessThanOrEqual(java.lang.Comparable<T> a, T b)
-
greaterThanOrEqual
public java.lang.Object greaterThanOrEqual(java.lang.Object a, java.lang.Object b)
Description copied from interface:StandardEvaluator
Applies theOperators.GREATER_THAN_OR_EQUAL
operator.
-
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 theOperators.INSTANCEOF
operator.
-
equal
public java.lang.Object equal(java.lang.Object a, java.lang.Object b)
Description copied from interface:StandardEvaluator
Applies theOperators.EQUAL
operator.
-
notEqual
public java.lang.Object notEqual(java.lang.Object a, java.lang.Object b)
Description copied from interface:StandardEvaluator
Applies theOperators.NOT_EQUAL
operator.
-
bitwiseAnd
public java.lang.Object bitwiseAnd(java.lang.Object a, java.lang.Object b)
Description copied from interface:StandardEvaluator
Applies theOperators.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 theOperators.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 theOperators.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 theOperators.LOGICAL_OR
operator.
-
logicalOr
public boolean logicalOr(boolean a, boolean b)
-
-