public class Expression
extends java.lang.Object
Class provides easy way to define multivariate arithmetic expression.
Argument
,
RecursiveArgument
,
Constant
,
Function
Modifier and Type | Field and Description |
---|---|
static boolean |
NO_SYNTAX_ERRORS
Status of the Expression syntax
|
static boolean |
SYNTAX_ERROR_OR_STATUS_UNKNOWN |
Constructor and Description |
---|
Expression(PrimitiveElement... elements)
Default constructor - empty expression
|
Expression(java.lang.String expressionString,
PrimitiveElement... elements)
Constructor - creates new expression from expression string.
|
Modifier and Type | Method and Description |
---|---|
void |
addArguments(Argument... arguments)
Adds arguments (variadic) to the expression definition.
|
void |
addConstants(Constant... constants)
Adds constants (variadic parameters) to the expression definition.
|
void |
addConstants(java.util.List<Constant> constantsList)
Adds constants to the expression definition.
|
void |
addDefinitions(PrimitiveElement... elements)
Adds user defined elements (such as: Arguments, Constants, Functions)
to the expressions.
|
void |
addFunctions(Function... functions)
Adds functions (variadic parameters) to the expression definition.
|
double |
calculate()
Calculates the expression value
|
boolean |
checkLexSyntax()
Checks syntax of the expression string.
|
boolean |
checkSyntax()
Checks syntax of the expression string.
|
void |
clearDescription()
Clears expression description
|
void |
clearExpressionString()
Clears expression string
|
void |
defineArgument(java.lang.String argumentName,
double argumentValue)
Enables to define the argument (associated with the expression)
based on the argument name and the argument value.
|
void |
defineArguments(java.lang.String... argumentsNames)
Enables to define the arguments (associated with
the expression) based on the given arguments names.
|
void |
defineConstant(java.lang.String constantName,
double constantValue)
Enables to define the constant (associated with
the expression) based on the constant name and
constant value.
|
void |
defineFunction(java.lang.String functionName,
java.lang.String functionExpressionString,
java.lang.String... argumentsNames)
Enables to define the function (associated with
the expression) based on the function name,
function expression string and arguments names (variadic parameters).
|
Argument |
getArgument(int argumentIndex)
Gets argument from the expression.
|
Argument |
getArgument(java.lang.String argumentName)
Gets argument from the expression.
|
int |
getArgumentIndex(java.lang.String argumentName)
Gets argument index from the expression.
|
int |
getArgumentsNumber()
Gets number of arguments associated with the expression.
|
double |
getArgumentValue(java.lang.String argumentName)
Gets argument vale.
|
double |
getComputingTime()
Gets computing time.
|
Constant |
getConstant(int constantIndex)
Gets constant associated with the expression.
|
Constant |
getConstant(java.lang.String constantName)
Gets constant associated with the expression.
|
int |
getConstantIndex(java.lang.String constantName)
Gets constant index associated with the expression.
|
int |
getConstantsNumber()
Gets number of constants associated with the expression.
|
java.util.List<Token> |
getCopyOfInitialTokens()
Tokenizes expression string and returns tokens list,
including: string, type, level.
|
java.lang.String |
getDescription()
Gets expression description.
|
java.lang.String |
getErrorMessage()
Method return error message after
calling checkSyntax() method or
calculate().
|
java.lang.String |
getExpressionString()
Returns expression string
|
Function |
getFunction(int functionIndex)
Gets function associated with the expression.
|
Function |
getFunction(java.lang.String functionName)
Gets function associated with the expression.
|
int |
getFunctionIndex(java.lang.String functionName)
Gets index of function associated with the expression.
|
int |
getFunctionsNumber()
Gets number of functions associated with the expression.
|
java.lang.String |
getHelp()
Gets help content.
|
java.lang.String |
getHelp(java.lang.String word)
Searching help content.
|
java.util.List<KeyWord> |
getKeyWords()
Returns list of key words known to the parser
|
java.util.List<KeyWord> |
getKeyWords(java.lang.String query)
Returns list of key words known to the parser
|
java.lang.String[] |
getMissingUserDefinedArguments()
Returns missing user defined arguments names, i.e.
|
java.lang.String[] |
getMissingUserDefinedFunctions()
Returns missing user defined functions names, i.e.
|
boolean |
getRecursiveMode()
Gets recursive mode status
|
boolean |
getSyntaxStatus()
Gets syntax status of the expression.
|
boolean |
getVerboseMode()
Returns verbose mode status.
|
void |
removeAllArguments()
Removes all arguments associated with the expression.
|
void |
removeAllConstants()
Removes all constants
associated with the expression
|
void |
removeAllFunctions()
Removes all functions
associated with the expression.
|
void |
removeArguments(Argument... arguments)
Removes first occurrences of the arguments
associated with the expression.
|
void |
removeArguments(java.lang.String... argumentsNames)
Removes first occurrences of the arguments
associated with the expression.
|
void |
removeConstants(Constant... constants)
Removes first occurrences of the constants
associated with the expression
|
void |
removeConstants(java.lang.String... constantsNames)
Removes first occurrences of the constants
associated with the expression.
|
void |
removeDefinitions(PrimitiveElement... elements)
Removes user defined elements (such as: Arguments, Constants, Functions)
to the expressions.
|
void |
removeFunctions(Function... functions)
Removes first occurrences of the functions
associated with the expression.
|
void |
removeFunctions(java.lang.String... functionsNames)
Removes first occurrences of the functions
associated with the expression.
|
void |
setArgumentValue(java.lang.String argumentName,
double argumentValue)
Sets argument value.
|
void |
setDescription(java.lang.String description)
Sets expression description.
|
void |
setExpressionString(java.lang.String expressionString)
Sets (modifies expression) expression string.
|
void |
setSilentMode()
Disables verbose mode (default silent mode).
|
void |
setVerboseMode()
Enables verbose mode.
|
public static final boolean NO_SYNTAX_ERRORS
public static final boolean SYNTAX_ERROR_OR_STATUS_UNKNOWN
public Expression(PrimitiveElement... elements)
elements
- Optional elements list (variadic - comma separated) of types: Argument, Constant, FunctionPrimitiveElement
public Expression(java.lang.String expressionString, PrimitiveElement... elements)
expressionString
- definition of the expressionelements
- Optional elements list (variadic - comma separated) of types: Argument, Constant, FunctionPrimitiveElement
public java.lang.String getErrorMessage()
public boolean getSyntaxStatus()
public void setExpressionString(java.lang.String expressionString)
expressionString
- the expression stringpublic java.lang.String getExpressionString()
public void clearExpressionString()
public void setDescription(java.lang.String description)
description
- the description stringpublic java.lang.String getDescription()
public void clearDescription()
public void setVerboseMode()
public void setSilentMode()
public boolean getVerboseMode()
public boolean getRecursiveMode()
public double getComputingTime()
public void addDefinitions(PrimitiveElement... elements)
elements
- Elements list (variadic), where Argument, Constant, Function
extend the same class PrimitiveElementPrimitiveElement
public void removeDefinitions(PrimitiveElement... elements)
elements
- Elements list (variadic), where Argument, Constant, Function
extend the same class PrimitiveElementPrimitiveElement
public void addArguments(Argument... arguments)
arguments
- the arguments list
(comma separated list)Argument
,
RecursiveArgument
public void defineArguments(java.lang.String... argumentsNames)
argumentsNames
- the arguments names (variadic)
comma separated listArgument
,
RecursiveArgument
public void defineArgument(java.lang.String argumentName, double argumentValue)
argumentName
- the argument nameargumentValue
- the the argument valueArgument
,
RecursiveArgument
public int getArgumentIndex(java.lang.String argumentName)
argumentName
- the argument nameArgument
,
RecursiveArgument
public Argument getArgument(java.lang.String argumentName)
argumentName
- the argument nameArgument
,
RecursiveArgument
public Argument getArgument(int argumentIndex)
argumentIndex
- the argument indexArgument
,
RecursiveArgument
public int getArgumentsNumber()
Argument
,
RecursiveArgument
public void setArgumentValue(java.lang.String argumentName, double argumentValue)
argumentName
- the argument nameargumentValue
- the argument valuepublic double getArgumentValue(java.lang.String argumentName)
argumentName
- the argument namepublic void removeArguments(java.lang.String... argumentsNames)
argumentsNames
- the arguments names
(variadic parameters) comma separated
listArgument
,
RecursiveArgument
public void removeArguments(Argument... arguments)
arguments
- the arguments (variadic parameters)
comma separated listArgument
,
RecursiveArgument
public void removeAllArguments()
Argument
,
RecursiveArgument
public void addConstants(Constant... constants)
constants
- the constants
(comma separated list)Constant
public void addConstants(java.util.List<Constant> constantsList)
constantsList
- the list of constantsConstant
public void defineConstant(java.lang.String constantName, double constantValue)
constantName
- the constant nameconstantValue
- the constant valueConstant
public int getConstantIndex(java.lang.String constantName)
constantName
- the constant nameConstant
public Constant getConstant(java.lang.String constantName)
constantName
- the constant nameConstant
public Constant getConstant(int constantIndex)
constantIndex
- the constant indexConstant
public int getConstantsNumber()
Constant
public void removeConstants(java.lang.String... constantsNames)
constantsNames
- the constants names (variadic parameters)
comma separated listConstant
public void removeConstants(Constant... constants)
constants
- the constants (variadic parameters)
comma separated listConstant
public void removeAllConstants()
Constant
public void addFunctions(Function... functions)
functions
- the functions
(variadic parameters) comma separated listFunction
public void defineFunction(java.lang.String functionName, java.lang.String functionExpressionString, java.lang.String... argumentsNames)
functionName
- the function namefunctionExpressionString
- the expression stringargumentsNames
- the function arguments names
(variadic parameters)
comma separated listFunction
public int getFunctionIndex(java.lang.String functionName)
functionName
- the function nameFunction
public Function getFunction(java.lang.String functionName)
functionName
- the function nameFunction
public Function getFunction(int functionIndex)
functionIndex
- the function indexFunction
public int getFunctionsNumber()
Function
public void removeFunctions(java.lang.String... functionsNames)
functionsNames
- the functions names (variadic parameters)
comma separated listFunction
public void removeFunctions(Function... functions)
functions
- the functions (variadic parameters)
comma separated list.Function
public void removeAllFunctions()
Function
public boolean checkLexSyntax()
public boolean checkSyntax()
public double calculate()
public java.util.List<Token> getCopyOfInitialTokens()
Token
,
mXparser.consolePrintTokens(List)
public java.lang.String[] getMissingUserDefinedArguments()
public java.lang.String[] getMissingUserDefinedFunctions()
public java.lang.String getHelp()
public java.lang.String getHelp(java.lang.String word)
word
- searching key wordpublic java.util.List<KeyWord> getKeyWords()
KeyWord
,
KeyWord.wordTypeId
,
getHelp()
public java.util.List<KeyWord> getKeyWords(java.lang.String query)
query
- Give any string to filter list of key words against this string.
User more precise syntax: str=tokenString, desc=tokenDescription,
syn=TokenSyntax, sin=tokenSince, wid=wordId, tid=wordTypeId
to narrow the result.KeyWord
,
KeyWord.wordTypeId
,
getHelp(String)