public class DefaultEvaluator extends AbstractStandardStackEvaluator
standard operators with
common built-in types (i.e.: Booleans, Strings and
Numbers). 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."
The main class, to give it a spin.| Constructor and Description |
|---|
DefaultEvaluator() |
DefaultEvaluator(ExpressionParser parser) |
| Modifier and Type | Method and Description |
|---|---|
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. |
addAssign, andAssign, assign, divAssign, dotDivAssign, dotPowAssign, dotRightDivAssign, execute, leftShiftAssign, modAssign, mulAssign, orAssign, postDec, postInc, powAssign, preDec, preInc, rightDivAssign, rightShiftAssign, subAssign, unsignedRightShiftAssignevaluateevaluate, evaluate, get, set, setAll, valuepublic DefaultEvaluator()
public DefaultEvaluator(ExpressionParser parser)
public Object dot(Object a, Object b)
StandardEvaluatorOperators.DOT operator.public Object transpose(Object a)
StandardEvaluatorOperators.TRANSPOSE operator.public Object dotTranspose(Object a)
StandardEvaluatorOperators.DOT_TRANSPOSE operator.public Object pow(Object a, Object b)
StandardEvaluatorOperators.POW operator.public double pow(double a,
double b)
public BigInteger pow(BigInteger a, int b)
public BigDecimal pow(BigDecimal a, int b)
public Object dotPow(Object a, Object b)
StandardEvaluatorOperators.DOT_POW operator.public Object pos(Object a)
StandardEvaluatorOperators.POS operator.public int pos(int num)
public long pos(long num)
public float pos(float num)
public double pos(double num)
public Object neg(Object a)
StandardEvaluatorOperators.NEG operator.public int neg(int num)
public long neg(long num)
public float neg(float num)
public double neg(double num)
public BigInteger neg(BigInteger num)
public BigDecimal neg(BigDecimal num)
public Object complement(Object a)
StandardEvaluatorOperators.COMPLEMENT operator.public int complement(int a)
public long complement(long a)
public Object not(Object a)
StandardEvaluatorOperators.NOT operator.public boolean not(boolean a)
public Object mul(Object a, Object b)
StandardEvaluatorOperators.MUL operator.public int mul(int a,
int b)
public long mul(long a,
long b)
public float mul(float a,
float b)
public double mul(double a,
double b)
public BigInteger mul(BigInteger a, BigInteger b)
public BigDecimal mul(BigDecimal a, BigDecimal b)
public Object div(Object a, Object b)
StandardEvaluatorOperators.DIV operator.public int div(int a,
int b)
public long div(long a,
long b)
public float div(float a,
float b)
public double div(double a,
double b)
public BigInteger div(BigInteger a, BigInteger b)
public BigDecimal div(BigDecimal a, BigDecimal b)
public Object mod(Object a, Object b)
StandardEvaluatorOperators.MOD operator.public int mod(int a,
int b)
public long mod(long a,
long b)
public float mod(float a,
float b)
public double mod(double a,
double b)
public BigInteger mod(BigInteger a, BigInteger b)
public BigDecimal mod(BigDecimal a, BigDecimal b)
public Object rightDiv(Object a, Object b)
StandardEvaluatorOperators.RIGHT_DIV operator.public Object dotMul(Object a, Object b)
StandardEvaluatorOperators.DOT_MUL operator.public Object dotDiv(Object a, Object b)
StandardEvaluatorOperators.DOT_DIV operator.public Object dotRightDiv(Object a, Object b)
StandardEvaluatorOperators.DOT_RIGHT_DIV operator.public Object add(Object a, Object b)
StandardEvaluatorOperators.ADD operator.public int add(int a,
int b)
public long add(long a,
long b)
public float add(float a,
float b)
public double add(double a,
double b)
public BigInteger add(BigInteger a, BigInteger b)
public BigDecimal add(BigDecimal a, BigDecimal b)
public Object sub(Object a, Object b)
StandardEvaluatorOperators.SUB operator.public int sub(int a,
int b)
public long sub(long a,
long b)
public float sub(float a,
float b)
public double sub(double a,
double b)
public BigInteger sub(BigInteger a, BigInteger b)
public BigDecimal sub(BigDecimal a, BigDecimal b)
public Object leftShift(Object a, Object b)
StandardEvaluatorOperators.LEFT_SHIFT operator.public int leftShift(int a,
int b)
public long leftShift(long a,
long b)
public BigInteger leftShift(BigInteger a, int b)
public Object rightShift(Object a, Object b)
StandardEvaluatorOperators.RIGHT_SHIFT operator.public int rightShift(int a,
int b)
public long rightShift(long a,
long b)
public BigInteger rightShift(BigInteger a, int b)
public Object unsignedRightShift(Object a, Object b)
StandardEvaluatorOperators.UNSIGNED_RIGHT_SHIFT operator.public int unsignedRightShift(int a,
int b)
public long unsignedRightShift(long a,
long b)
public Object colon(Object a, Object b)
StandardEvaluatorOperators.COLON operator.public Object lessThan(Object a, Object b)
StandardEvaluatorOperators.LESS_THAN operator.public <T> boolean lessThan(Comparable<T> a, T b)
public Object greaterThan(Object a, Object b)
StandardEvaluatorOperators.GREATER_THAN operator.public <T> boolean greaterThan(Comparable<T> a, T b)
public Object lessThanOrEqual(Object a, Object b)
StandardEvaluatorOperators.LESS_THAN_OR_EQUAL operator.public <T> boolean lessThanOrEqual(Comparable<T> a, T b)
public Object greaterThanOrEqual(Object a, Object b)
StandardEvaluatorOperators.GREATER_THAN_OR_EQUAL operator.public <T> boolean greaterThanOrEqual(Comparable<T> a, T b)
public Object instanceOf(Object a, Object b)
StandardEvaluatorOperators.INSTANCEOF operator.public Object equal(Object a, Object b)
StandardEvaluatorOperators.EQUAL operator.public Object notEqual(Object a, Object b)
StandardEvaluatorOperators.NOT_EQUAL operator.public Object bitwiseAnd(Object a, Object b)
StandardEvaluatorOperators.BITWISE_AND operator.public int bitwiseAnd(int a,
int b)
public long bitwiseAnd(long a,
long b)
public BigInteger bitwiseAnd(BigInteger a, BigInteger b)
public Object bitwiseOr(Object a, Object b)
StandardEvaluatorOperators.BITWISE_OR operator.public int bitwiseOr(int a,
int b)
public long bitwiseOr(long a,
long b)
public BigInteger bitwiseOr(BigInteger a, BigInteger b)
public Object logicalAnd(Object a, Object b)
StandardEvaluatorOperators.LOGICAL_AND operator.public boolean logicalAnd(boolean a,
boolean b)
public Object logicalOr(Object a, Object b)
StandardEvaluatorOperators.LOGICAL_OR operator.public boolean logicalOr(boolean a,
boolean b)
Copyright © 2015 SciJava. All rights reserved.