|
Framework Professional Edition Package |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sourceforge.jeval.Evaluator
public class Evaluator
This class is used to evaluate mathematical, string, Boolean and functional
expressions. It is the main entry point into the JEval API.
The following types of expressions are supported:
| Field Summary | |
|---|---|
static java.lang.Double |
BOOLEAN_FALSE_DOUBLE_VALUE
|
static java.lang.String |
BOOLEAN_FALSE_STR
|
static java.lang.Double |
BOOLEAN_TRUE_DOUBLE_VALUE
|
static java.lang.String |
BOOLEAN_TRUE_STR
|
| Constructor Summary | |
|---|---|
Evaluator()
The default constructor. |
|
Evaluator(char quoteCharacter,
boolean loadMathVariables,
boolean loadMathFunctions,
boolean loadStringFunctions)
The main constructor for Evaluator. |
|
| Method Summary | |
|---|---|
void |
clearFunctions()
Removes all of the functions at one time. |
void |
clearVariables()
Removes all of the variables at one time. |
java.lang.String |
evaluate()
This method evaluates mathematical, boolean or functional expressions. |
java.lang.String |
evaluate(boolean keepQuotes,
boolean wrapStringFunctionResults)
This method evaluates mathematical, boolean or functional expressions. |
java.lang.String |
evaluate(java.lang.String expression)
This method evaluates mathematical, boolean or functional expressions. |
java.lang.String |
evaluate(java.lang.String expression,
boolean keepQuotes,
boolean wrapStringFunctionResults)
This method evaluates mathematical, boolean or functional expressions. |
boolean |
getBooleanResult(java.lang.String expression)
This method is a simple wrapper around the evaluate(String) method. |
net.sourceforge.jeval.function.Function |
getFunction(java.lang.String functionName)
Returns a funtion from the list of functions. |
double |
getNumberResult(java.lang.String expression)
This method is a simple wrapper around the evaluate(String) method. |
char |
getQuoteCharacter()
Returns the current quote character in use. |
java.lang.String |
getVariable(java.lang.String variableName)
Returns the value for a variable in the list of variables. |
protected boolean |
isExpressionBoolean(java.lang.String expressionString)
Determines if the string represents a valid boolean value. |
protected boolean |
isExpressionString(java.lang.String expressionString)
Determines if the string represents a valid expression string or not. |
void |
isValidName(java.lang.String name)
This method verifies if a function or variable name is valid or not. |
void |
parse(java.lang.String expression)
This method parses a mathematical, boolean or functional expressions. |
void |
putFunction(net.sourceforge.jeval.function.Function function)
Adds a function to the list of functions to use when evaluating expressions. |
void |
putVariable(java.lang.String variableName,
java.lang.String variableValue)
Adds or replaces a variable to the list of variables to use when evaluating expressions. |
void |
removeFunction(java.lang.String functionName)
Removes the function from the list of functions to use when evaluating expressions. |
void |
removeVaraible(java.lang.String variableName)
Removes the variable from the list of variables to use when evaluating expressions. |
java.lang.String |
replaceVariables(java.lang.String expression)
Replaces the variables in the expression with the values of the variables for this instance of the evaluator. |
void |
setQuoteCharacter(char quoteCharacter)
Sets the quote character to use when evaluating expressions. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String BOOLEAN_TRUE_STR
public static final java.lang.String BOOLEAN_FALSE_STR
public static final java.lang.Double BOOLEAN_TRUE_DOUBLE_VALUE
public static final java.lang.Double BOOLEAN_FALSE_DOUBLE_VALUE
| Constructor Detail |
|---|
public Evaluator()
public Evaluator(char quoteCharacter,
boolean loadMathVariables,
boolean loadMathFunctions,
boolean loadStringFunctions)
quoteCharacter - The quote character to use when evaluating expression.loadMathVariables - Indicates if the standard Math variables should be loaded or
not.loadMathFunctions - Indicates if the standard Math functions should be loaded or
not.loadStringFunctions - Indicates if the standard String functions should be loaded or
not.
java.lang.IllegalArgumentException - Thrown when the quote character is not a valid quote
character.| Method Detail |
|---|
public char getQuoteCharacter()
public void setQuoteCharacter(char quoteCharacter)
quoteCharacter - The quote character to use when evaluating expressions.
java.lang.IllegalArgumentException - Thrown when the quote character is not a valid quote
character.public void putFunction(net.sourceforge.jeval.function.Function function)
function - The function being added.
java.lang.IllegalArgumentException - Thrown when the function name is not valid or the function
name is already in use.public net.sourceforge.jeval.function.Function getFunction(java.lang.String functionName)
functionName - The name of the function to retrieve the value for.
public void removeFunction(java.lang.String functionName)
functionName - The name of the function to remove.public void clearFunctions()
public void putVariable(java.lang.String variableName,
java.lang.String variableValue)
variableName - The name of the variable being set.variableValue - The value for the variable being set.public java.lang.String getVariable(java.lang.String variableName)
variableName - The name of the variable to retrieve the value for.
public void removeVaraible(java.lang.String variableName)
variableName - The name of the variable to remove.public void clearVariables()
public java.lang.String evaluate(java.lang.String expression)
throws EvaluationException
expression - The expression to evaluate.
EvaluateException - Thrown when an error is found while evaluating the
expression.
EvaluationException
public java.lang.String evaluate()
throws EvaluationException
EvaluateException - Thrown when an error is found while evaluating the
expression.
EvaluationException
public java.lang.String evaluate(java.lang.String expression,
boolean keepQuotes,
boolean wrapStringFunctionResults)
throws EvaluationException
expression - The expression to evaluate.keepQuotes - Indicates if the the quotes should be kept in the result or
not. This is only for string expression that are enclosed in
quotes prior to being evaluated.wrapStringFunctionResults - Indicates if the results from functions that return strings
should be wrapped in quotes. The quote character used will be
whatever is the current quote character for this object.
EvaluateException - Thrown when an error is found while evaluating the
expression.
EvaluationException
public java.lang.String evaluate(boolean keepQuotes,
boolean wrapStringFunctionResults)
throws EvaluationException
keepQuotes - Indicates if the the quotes should be kept in the result or
not. This is only for string expressions that are enclosed in
quotes prior to being evaluated.wrapStringFunctionResults - Indicates if the results from functions that return strings
should be wrapped in quotes. The quote character used will be
whatever is the current quote character for this object.
EvaluateException - Thrown when an error is found while evaluating the
expression.
EvaluationException
public boolean getBooleanResult(java.lang.String expression)
throws EvaluationException
expression - The expression to evaluate.
EvaluateException - Thrown when an error is found while evaluating the
expression. It is also thrown if the result is not able to
be converted to a boolean value.
EvaluationException
public double getNumberResult(java.lang.String expression)
throws EvaluationException
expression - The expression to evaluate.
EvaluateException - Thrown when an error is found while evaluating the
expression. It is also thrown if the result is not able to
be converted to a double value.
EvaluationException
public void parse(java.lang.String expression)
throws EvaluationException
expression - The expression to evaluate.
EvaluateException - Thrown when an error is found while evaluating the
expression.
EvaluationException
protected boolean isExpressionString(java.lang.String expressionString)
throws EvaluationException
expressionString - The string being evaluated.
EvaluationExceptionprotected boolean isExpressionBoolean(java.lang.String expressionString)
expressionString - The string being evaluated.
public void isValidName(java.lang.String name)
throws java.lang.IllegalArgumentException
name - The function or variable name being validated.
java.lang.IllegalArgumentException - Thrown if the name is invalid.
public java.lang.String replaceVariables(java.lang.String expression)
throws EvaluationException
expression - The expression being processed.
EvaluateException - Thrown is an error is encoutnered while processing the
expression.
EvaluationException
|
Framework Professional Edition Package |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||