|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jwo.utils.expression.MathEvaluator
public final class MathEvaluator
Evaluates a mathematical expression stored in an postfix stack (created using
MathParser
). Can handle basic arithmetic (e.g. +,-,*), trig mathematical
operators (e.g. cos, sin, ln), constants (e.g. pi, e), random number generators (e.g.
rand, gauss), statistical operators (e.g. min, max, percentile), colour operators (e.g.
red, rgb), focal operators (e.g. row, col, easting, northing) and string operators
(e.g. &, compare, substring). For a full list of operators and functions that are
handled see MathOperator
.
Can also substitute variables z1,z2,x and y with numbers defined by the constructor or
the relevant evaluate() method. Alternatively, can handle 'evaluate-time' variable and
function substitutions by passing a reference to the class handling the substitution
(which must implement the Substitutable interface).
Modified from original code described at
www.devx.com/premier/mgznarch/javapro/2001/05may01/ps0105/ps0105.asp.
MathOperator
Field Summary | |
---|---|
static int |
EXPR_NUMERIC
Indicates expression returns a numeric value. |
static int |
EXPR_OTHER
Indicates expression an undefined type. |
static int |
EXPR_SPATIAL
Indicates expression returns a spatial object. |
static int |
EXPR_STRING
Indicates expression returns a text string. |
static int |
EXPR_VARIABLE
Indicates expression returns variable name. |
static String |
HELP_ID
Indicates that a help message has been requested. |
Constructor Summary | |
---|---|
MathEvaluator()
Creates an evaluator with no shortcut variables. |
|
MathEvaluator(double[] z)
Deprecated. This constructor is maintained for backward compatibility only and should not be used with the preferred more general variable substitution mechanism via the Substitutable interface. |
Method Summary | |
---|---|
Object |
evaluate(Stack operations)
Evaluates the given expression stack using (if required), the stored variable substitutions. |
double |
evaluate(Stack operations,
double z1,
double z2,
double x,
double y)
Deprecated. This method is maintained for backward compatibility only and should not be used with the preferred more general variable substitution mechanism via the Substitutable interface and calling the addVariable()
method of MathParser() . |
int |
getExpressionType()
Reports the type of value returned by the last evaluation. |
static String |
getExpressionTypeAsText(int expressionType)
Reports the given expression type as text. |
boolean |
isHelpRequested()
Reports whether the last evaluation was a request for a help message. |
boolean |
isInvalid()
Reports whether the last evaluation produced an invalid result. |
void |
setSubstitutor(Substitutable substitutor)
Sets the variable substitutor to considered by the evaluator. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String HELP_ID
public static final int EXPR_OTHER
public static final int EXPR_STRING
public static final int EXPR_VARIABLE
public static final int EXPR_NUMERIC
public static final int EXPR_SPATIAL
Constructor Detail |
---|
public MathEvaluator()
Substitutable
interface.
public MathEvaluator(double[] z)
Substitutable
interface.
z
- List of variables for substitution. Expressions
that use variables should name them z1,z2, x and y.Method Detail |
---|
public void setSubstitutor(Substitutable substitutor)
substitutor
- Class handling the substitution of variables.public Object evaluate(Stack operations)
Double
object. If it is a text it will be stored
in a String
object). To find For other return types, call the returned object's
getClass()
method.
operations
- Expression stack containing postfixed expression.
String
(isString()>/code>
is true
) or a Double
(isString()>/code> is
false
).
public double evaluate(Stack operations, double z1, double z2, double x, double y)
Substitutable
interface and calling the addVariable()
method of MathParser()
.
operations
- Expression stack containing postfixed expression.z1
- Value of z1 to substitute.z2
- Value of z2 to substitute.x
- Value of x to substitute.y
- Value of y to substitute.
public boolean isInvalid()
public boolean isHelpRequested()
public int getExpressionType()
EXPR_NUMERIC
,
EXPR_STRING
, EXPR_SPATIAL
or EXPR_OTHER
.public static String getExpressionTypeAsText(int expressionType)
getExpressionType()
.
expressionType
- Expression type to evaluate.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |