public interface IMathParser
You can create a parser using MathParserFactory.create(); This will return you a IMathParser. You can set the expression to parse using IMathParser.setExpression(String); And you can get the result using double IMathParser.getValue();
Modifier and Type | Method and Description |
---|---|
void |
createConstant(java.lang.String constName,
double constValue)
Creates a variable whose value is constant and cannot be changed.
|
void |
createDefaultFuncs()
createDefaultFuncs method creates some predefined functions in the parser's list of functions.
|
void |
createDefaultVars()
X, Y and PI variables are predefined and can be immediately used in the expression.
|
void |
createFunc(java.lang.String newFuncName,
IFunction funcAddr)
createFunc method creates a new function that takes n number of parameters in
the parser's list of functions.
|
void |
createVar(java.lang.String varName,
double varValue)
Same as setVariable(String, double);
|
void |
deleteAllFuncs()
DeleteAllFuncs method deletes all variables from the list of available functions.
|
void |
deleteAllVars()
DeleteAllVars method deletes all variables from the list of available variables.
|
void |
deleteFunc(java.lang.String funcName)
deleteFunc method deletes an existing function from the list of available functions.
|
void |
deleteVar(java.lang.String varName)
deleteVar method deletes an existing variable from the list of available variables.
|
double |
evaluate()
Evaluates the expression and returns the result of it.
|
void |
freeParseTree()
FreeParseTree can be explicitly called to free the resources taken by the
allocated Parse tree when an expression is parsed.
|
char |
getDecimalSeparator() |
java.lang.String |
getExpression()
Please see setExpression() method to read about Expression property.
|
char |
getFunctionParamSeparator() |
java.lang.String[] |
getFunctions()
Returns an array of functions declared for this parser.
|
java.util.Locale |
getLocale()
Returns the locale of this parser instance.
|
boolean |
getOptimizationOn()
Set OptimizationOn to let the bcParser component evaluate constant expressions
at parse time.
|
double |
getValue()
Value property (getValue() method) is an intuitive way of retrieving the value of the input expression.
|
double |
getVariable(java.lang.String varName)
Variable property is a way to set and get variable values.
|
IVariableResolver |
getVariableResolver() |
java.lang.String[] |
getVariables()
Returns the list of variables as an array of strings.
|
java.lang.String[] |
GetVariablesUsed()
Returns the list of variables used in the current expression as an array of Strings.
|
double |
getX()
X property represents the X variable used in the mathematical expression which
was input to be evaluated.
|
double |
getY()
Y property represents the Y variable used in the mathematical expression which
was input to be evaluated.
|
boolean |
isConstant(java.lang.String constName)
Returns true if a constant with the name 'constName' is defined.
|
boolean |
isFunction(java.lang.String funcName)
Returns true if a function with the name 'funcName' is present in the current functions list.
|
boolean |
isFuncUsed(java.lang.String funcName)
Returns true if a function with the name 'funcName' is used in the current expression.
|
boolean |
isLocaleSpecificDecimals()
Tells if expressions use locale specific decimal separator such as dot or comma.
|
boolean |
isVariable(java.lang.String varName)
Returns true if a variable with the name 'varName' is present in the current
variables list as a variable or constant.
|
boolean |
isVariableUsed(java.lang.String varName)
Returns true if a variable with the name 'varName' is used in the current expression.
|
void |
optimize()
Optimizes the parse tree by finding branches that evaluate to a constant and
replacing them with a leaf representing the constant.
|
void |
parse()
Parses the expression and forms a parse tree.
|
void |
setExpression(java.lang.String newVal)
Expression property represents the mathematical expression which is input to be evaluated by the user.
|
void |
setLocale(java.util.Locale l)
Sets the locale for the parser to use while constructing messages and
decising decimal separator if
isLocaleSpecificDecimals is true. |
void |
setLocaleSpecificDecimals(boolean useLocaleSpecificDecimals)
Tells the parser to support locale specific decimal separator such as dot(.) and comma(,)
depending on the locale set by setLocale.
|
void |
setOptimizationOn(boolean newVal)
Set OptimizationOn to let the bcParser component evaluate constant expressions
at parse time.
|
void |
setVariable(java.lang.String varName,
double newVal)
Variable property is a way to set and get variable values.
|
void |
setVariableResolver(IVariableResolver variableResolver)
Set the IVariableResolver for this parser instance.
|
void |
setX(double newVal)
X property represents the X variable used in the mathematical expression which
was input to be evaluated.
|
void |
setY(double newVal)
Y property represents the Y variable used in the mathematical expression which
was input to be evaluated.
|
java.lang.String getExpression()
void setExpression(java.lang.String newVal)
double getValue() throws java.lang.Exception
java.lang.Exception
double getVariable(java.lang.String varName) throws java.lang.Exception
java.lang.Exception
void setVariable(java.lang.String varName, double newVal) throws java.lang.Exception
java.lang.Exception
double getX() throws java.lang.Exception
java.lang.Exception
void setX(double newVal)
double getY() throws java.lang.Exception
java.lang.Exception
void setY(double newVal)
boolean getOptimizationOn()
void setOptimizationOn(boolean newVal)
IVariableResolver getVariableResolver()
IVariableResolver
void setVariableResolver(IVariableResolver variableResolver)
variableResolver
- - user defined IVariableResolver to use to return the values of undefined variables.IVariableResolver
double evaluate() throws java.lang.Exception
java.lang.Exception
void parse() throws java.lang.Exception
java.lang.Exception
void createVar(java.lang.String varName, double varValue) throws java.lang.Exception
java.lang.Exception
void createConstant(java.lang.String constName, double constValue) throws java.lang.Exception
constName
- constValue
- java.lang.Exception
void createFunc(java.lang.String newFuncName, IFunction funcAddr) throws java.lang.Exception
java.lang.Exception
void createDefaultFuncs() throws java.lang.Exception
java.lang.Exception
void createDefaultVars()
void deleteVar(java.lang.String varName)
void deleteFunc(java.lang.String funcName)
void deleteAllVars()
void deleteAllFuncs()
java.lang.String[] getVariables()
java.lang.String[] getFunctions()
void freeParseTree()
boolean isVariableUsed(java.lang.String varName) throws java.lang.Exception
java.lang.Exception
boolean isFuncUsed(java.lang.String funcName) throws java.lang.Exception
java.lang.Exception
java.lang.String[] GetVariablesUsed() throws java.lang.Exception
java.lang.Exception
boolean isVariable(java.lang.String varName)
boolean isConstant(java.lang.String constName)
boolean isFunction(java.lang.String funcName)
void optimize()
void setLocale(java.util.Locale l)
isLocaleSpecificDecimals
is true.
Parser holds a static pool of translated messages mapped for each locale.
When this method is called, it first checks to see if the resource bundle
is already loaded in this pool. If it is loaded, it re-uses that pool.
If it was not loaded before, it loads it, adds it to the pool and
sets the specific bundle for this instance of the parser to use.
This mechanism allows the parser instances in the same VM efficiently
use different locales independent of each other. For example, if you
instantiate 100 parsers to use US English locale and then another 200
to use Chineese, then the parser will load the two resource bundles
for once each and related instances will share the same ones.boolean isLocaleSpecificDecimals()
setLocale
dictates that comma is going to be decimal separator,
then function parameter separator is going to be colon (:). If decimal separator is dot (.), then
function parameter is comma (,)void setLocaleSpecificDecimals(boolean useLocaleSpecificDecimals)
useLocaleSpecificDecimals
- isLocaleSpecificDecimals
java.util.Locale getLocale()
char getDecimalSeparator()
isLocaleSpecificDecimals
and
getLocale
.char getFunctionParamSeparator()
getDecimalSeparator
is
dot (.) then the character for function parameter separator is comma (,). If comma is used
for decimal separator, then function parameter separator is colon (:).