Class AbstractStandardEvaluator
- All Implemented Interfaces:
Evaluator
,StandardEvaluator
- Direct Known Subclasses:
DefaultStackEvaluator
,DefaultTreeEvaluator
StandardEvaluator
implementations on common
built-in types: Boolean
s, String
s and Number
s.
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.parsington.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
-
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptiondouble
add
(double a, double b) float
add
(float a, float b) int
add
(int a, int b) long
add
(long a, long b) Applies theOperators.ADD
operator.add
(BigDecimal a, BigDecimal b) add
(BigInteger a, BigInteger b) int
bitwiseAnd
(int a, int b) long
bitwiseAnd
(long a, long b) bitwiseAnd
(Object a, Object b) Applies theOperators.BITWISE_AND
operator.bitwiseAnd
(BigInteger a, BigInteger b) int
bitwiseOr
(int a, int b) long
bitwiseOr
(long a, long b) Applies theOperators.BITWISE_OR
operator.bitwiseOr
(BigInteger a, BigInteger b) Applies theOperators.BRACES
operator.Applies theOperators.BRACKETS
operator.Applies theOperators.COLON
operator.int
complement
(int a) long
complement
(long a) complement
(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) Applies theOperators.DIV
operator.div
(BigDecimal a, BigDecimal b) div
(BigInteger a, BigInteger b) Applies theOperators.DOT
operator.Applies theOperators.DOT_DIV
operator.Applies theOperators.DOT_MUL
operator.Applies theOperators.DOT_POW
operator.dotRightDiv
(Object a, Object b) Applies theOperators.DOT_RIGHT_DIV
operator.Applies theOperators.DOT_TRANSPOSE
operator.Applies theOperators.EQUAL
operator.Applies theFunction
operator.<T> boolean
greaterThan
(Comparable<T> a, T b) greaterThan
(Object a, Object b) Applies theOperators.GREATER_THAN
operator.<T> boolean
greaterThanOrEqual
(Comparable<T> a, T b) greaterThanOrEqual
(Object a, Object b) Applies theOperators.GREATER_THAN_OR_EQUAL
operator.instanceOf
(Object a, Object b) Applies theOperators.INSTANCEOF
operator.int
leftShift
(int a, int b) long
leftShift
(long a, long b) Applies theOperators.LEFT_SHIFT
operator.leftShift
(BigInteger a, int b) <T> boolean
lessThan
(Comparable<T> a, T b) Applies theOperators.LESS_THAN
operator.<T> boolean
lessThanOrEqual
(Comparable<T> a, T b) lessThanOrEqual
(Object a, Object b) Applies theOperators.LESS_THAN_OR_EQUAL
operator.boolean
logicalAnd
(boolean a, boolean b) logicalAnd
(Object a, Object b) Applies theOperators.LOGICAL_AND
operator.boolean
logicalOr
(boolean a, boolean 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) Applies theOperators.MOD
operator.mod
(BigDecimal a, BigDecimal b) mod
(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) Applies theOperators.MUL
operator.mul
(BigDecimal a, BigDecimal b) mul
(BigInteger a, BigInteger b) double
neg
(double num) float
neg
(float num) int
neg
(int num) long
neg
(long num) Applies theOperators.NEG
operator.neg
(BigDecimal num) neg
(BigInteger num) boolean
not
(boolean a) Applies theOperators.NOT
operator.Applies theOperators.NOT_EQUAL
operator.Applies theOperators.PARENS
operator.double
pos
(double num) float
pos
(float num) int
pos
(int num) long
pos
(long num) Applies theOperators.POS
operator.double
pow
(double a, double b) Applies theOperators.POW
operator.pow
(BigDecimal a, int b) pow
(BigInteger a, int b) Applies theOperators.QUESTION
operator.Applies theOperators.RIGHT_DIV
operator.int
rightShift
(int a, int b) long
rightShift
(long a, long b) rightShift
(Object a, Object b) Applies theOperators.RIGHT_SHIFT
operator.rightShift
(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) Applies theOperators.SUB
operator.sub
(BigDecimal a, BigDecimal b) sub
(BigInteger a, BigInteger b) Applies theOperators.TRANSPOSE
operator.int
unsignedRightShift
(int a, int b) long
unsignedRightShift
(long a, long b) unsignedRightShift
(Object a, Object b) Applies theOperators.UNSIGNED_RIGHT_SHIFT
operator.Methods inherited from class org.scijava.parsington.eval.AbstractEvaluator
get, getParser, isStrict, set, setAll, setStrict
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.scijava.parsington.eval.Evaluator
evaluate, evaluate, evaluate, get, get, getParser, isStrict, set, set, setAll, setStrict, value, var
Methods inherited from interface org.scijava.parsington.eval.StandardEvaluator
addAssign, andAssign, assign, divAssign, dotDivAssign, dotPowAssign, dotRightDivAssign, execute, leftShiftAssign, modAssign, mulAssign, orAssign, postDec, postInc, powAssign, preDec, preInc, rightDivAssign, rightShiftAssign, subAssign, unsignedRightShiftAssign
-
Constructor Details
-
AbstractStandardEvaluator
public AbstractStandardEvaluator() -
AbstractStandardEvaluator
-
-
Method Details
-
function
Description copied from interface:StandardEvaluator
Applies theFunction
operator.- Specified by:
function
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
dot
Description copied from interface:StandardEvaluator
Applies theOperators.DOT
operator.- Specified by:
dot
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
parens
Description copied from interface:StandardEvaluator
Applies theOperators.PARENS
operator.- Specified by:
parens
in interfaceStandardEvaluator
- Parameters:
args
- The arguments.- Returns:
- The result of the operation.
-
brackets
Description copied from interface:StandardEvaluator
Applies theOperators.BRACKETS
operator.- Specified by:
brackets
in interfaceStandardEvaluator
- Parameters:
args
- The arguments.- Returns:
- The result of the operation.
-
braces
Description copied from interface:StandardEvaluator
Applies theOperators.BRACES
operator.- Specified by:
braces
in interfaceStandardEvaluator
- Parameters:
args
- The arguments.- Returns:
- The result of the operation.
-
transpose
Description copied from interface:StandardEvaluator
Applies theOperators.TRANSPOSE
operator.- Specified by:
transpose
in interfaceStandardEvaluator
- Parameters:
a
- The argument.- Returns:
- The result of the operation.
-
dotTranspose
Description copied from interface:StandardEvaluator
Applies theOperators.DOT_TRANSPOSE
operator.- Specified by:
dotTranspose
in interfaceStandardEvaluator
- Parameters:
a
- The argument.- Returns:
- The result of the operation.
-
pow
Description copied from interface:StandardEvaluator
Applies theOperators.POW
operator.- Specified by:
pow
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
pow
public double pow(double a, double b) -
pow
-
pow
-
dotPow
Description copied from interface:StandardEvaluator
Applies theOperators.DOT_POW
operator.- Specified by:
dotPow
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
pos
Description copied from interface:StandardEvaluator
Applies theOperators.POS
operator.- Specified by:
pos
in interfaceStandardEvaluator
- Parameters:
a
- The argument.- Returns:
- The result of the operation.
-
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
Description copied from interface:StandardEvaluator
Applies theOperators.NEG
operator.- Specified by:
neg
in interfaceStandardEvaluator
- Parameters:
a
- The argument.- Returns:
- The result of the operation.
-
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
-
neg
-
complement
Description copied from interface:StandardEvaluator
Applies theOperators.COMPLEMENT
operator.- Specified by:
complement
in interfaceStandardEvaluator
- Parameters:
a
- The argument.- Returns:
- The result of the operation.
-
complement
public int complement(int a) -
complement
public long complement(long a) -
not
Description copied from interface:StandardEvaluator
Applies theOperators.NOT
operator.- Specified by:
not
in interfaceStandardEvaluator
- Parameters:
a
- The argument.- Returns:
- The result of the operation.
-
not
public boolean not(boolean a) -
mul
Description copied from interface:StandardEvaluator
Applies theOperators.MUL
operator.- Specified by:
mul
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
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
-
mul
-
div
Description copied from interface:StandardEvaluator
Applies theOperators.DIV
operator.- Specified by:
div
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
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
-
div
-
mod
Description copied from interface:StandardEvaluator
Applies theOperators.MOD
operator.- Specified by:
mod
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
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
-
mod
-
rightDiv
Description copied from interface:StandardEvaluator
Applies theOperators.RIGHT_DIV
operator.- Specified by:
rightDiv
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
dotMul
Description copied from interface:StandardEvaluator
Applies theOperators.DOT_MUL
operator.- Specified by:
dotMul
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
dotDiv
Description copied from interface:StandardEvaluator
Applies theOperators.DOT_DIV
operator.- Specified by:
dotDiv
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
dotRightDiv
Description copied from interface:StandardEvaluator
Applies theOperators.DOT_RIGHT_DIV
operator.- Specified by:
dotRightDiv
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
add
Description copied from interface:StandardEvaluator
Applies theOperators.ADD
operator.- Specified by:
add
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
add
-
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
-
add
-
sub
Description copied from interface:StandardEvaluator
Applies theOperators.SUB
operator.- Specified by:
sub
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
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
-
sub
-
leftShift
Description copied from interface:StandardEvaluator
Applies theOperators.LEFT_SHIFT
operator.- Specified by:
leftShift
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
leftShift
public int leftShift(int a, int b) -
leftShift
public long leftShift(long a, long b) -
leftShift
-
rightShift
Description copied from interface:StandardEvaluator
Applies theOperators.RIGHT_SHIFT
operator.- Specified by:
rightShift
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
rightShift
public int rightShift(int a, int b) -
rightShift
public long rightShift(long a, long b) -
rightShift
-
unsignedRightShift
Description copied from interface:StandardEvaluator
Applies theOperators.UNSIGNED_RIGHT_SHIFT
operator.- Specified by:
unsignedRightShift
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
unsignedRightShift
public int unsignedRightShift(int a, int b) -
unsignedRightShift
public long unsignedRightShift(long a, long b) -
lessThan
Description copied from interface:StandardEvaluator
Applies theOperators.LESS_THAN
operator.- Specified by:
lessThan
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
lessThan
-
greaterThan
Description copied from interface:StandardEvaluator
Applies theOperators.GREATER_THAN
operator.- Specified by:
greaterThan
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
greaterThan
-
lessThanOrEqual
Description copied from interface:StandardEvaluator
Applies theOperators.LESS_THAN_OR_EQUAL
operator.- Specified by:
lessThanOrEqual
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
lessThanOrEqual
-
greaterThanOrEqual
Description copied from interface:StandardEvaluator
Applies theOperators.GREATER_THAN_OR_EQUAL
operator.- Specified by:
greaterThanOrEqual
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
greaterThanOrEqual
-
instanceOf
Description copied from interface:StandardEvaluator
Applies theOperators.INSTANCEOF
operator.- Specified by:
instanceOf
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
equal
Description copied from interface:StandardEvaluator
Applies theOperators.EQUAL
operator.- Specified by:
equal
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
notEqual
Description copied from interface:StandardEvaluator
Applies theOperators.NOT_EQUAL
operator.- Specified by:
notEqual
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
bitwiseAnd
Description copied from interface:StandardEvaluator
Applies theOperators.BITWISE_AND
operator.- Specified by:
bitwiseAnd
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
bitwiseAnd
public int bitwiseAnd(int a, int b) -
bitwiseAnd
public long bitwiseAnd(long a, long b) -
bitwiseAnd
-
bitwiseOr
Description copied from interface:StandardEvaluator
Applies theOperators.BITWISE_OR
operator.- Specified by:
bitwiseOr
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
bitwiseOr
public int bitwiseOr(int a, int b) -
bitwiseOr
public long bitwiseOr(long a, long b) -
bitwiseOr
-
logicalAnd
Description copied from interface:StandardEvaluator
Applies theOperators.LOGICAL_AND
operator.- Specified by:
logicalAnd
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
logicalAnd
public boolean logicalAnd(boolean a, boolean b) -
logicalOr
Description copied from interface:StandardEvaluator
Applies theOperators.LOGICAL_OR
operator.- Specified by:
logicalOr
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
logicalOr
public boolean logicalOr(boolean a, boolean b) -
question
Description copied from interface:StandardEvaluator
Applies theOperators.QUESTION
operator.- Specified by:
question
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-
colon
Description copied from interface:StandardEvaluator
Applies theOperators.COLON
operator.- Specified by:
colon
in interfaceStandardEvaluator
- Parameters:
a
- The first argument.b
- The second argument.- Returns:
- The result of the operation.
-