Package org.mariuszgromada.math.mxparser
Class Argument
java.lang.Object
org.mariuszgromada.math.mxparser.PrimitiveElement
org.mariuszgromada.math.mxparser.Argument
- Direct Known Subclasses:
RecursiveArgument
Argument class enables to declare the argument
(variable) which can be used in further processing
(in expressions, functions and dependent / recursive arguments).
For example:
For example:
- 'x' - argument in expression 'sin(x)'
- 'x' and 'y' - arguments in expression 'sin(x)+cos(y)'.
- 'x=2*t' - dependent argument (dependent from 't') in expression 'cos(x)'
Using Argument class you can define two argument types:
- free argument - when value of argument 'x' is directly given by a number (for example 'x=5')
- dependent argument - when value of argument 'x' is given by expression (for example: 'x=2*a+b' - argument 'x' depends from argument/constant 'a' and argument/constant 'b' or any other possible option like function, etc...)
When creating an argument you should avoid names reserved as parser keywords, in general words known in mathematical language as function names, operators (for example: sin, cos, +, -, etc...). Please be informed that after associating the argument with the expression, function or dependent/recursive argument its name will be recognized by the parser as reserved key word. It means that it could not be the same as any other key word known by the parser for this particular expression. Parser is case sensitive.
- Version:
- 4.4.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
Double.NaN as initial value of the argument.static final int
Argument with body based on the extended code.static final int
Argument with body based on the value or expression string.static final int
Type indicator for dependent argument.static final int
Type indicator for free argument.protected Argument
Index argument.static final boolean
No syntax errors in the dependent argument definition.static final int
When argument was not not foundstatic final int
Type indicator for recursive argument.static final boolean
Syntax error in the dependent argument definition.static final String
static final int
Argument type id for the definition of key words known by the parser. -
Constructor Summary
ConstructorsConstructorDescriptionArgument
(String argumentDefinitionString, boolean forceDependent, PrimitiveElement... elements) Default constructor - creates argument based on the argument definition string.Constructor - creates free argument.Argument
(String argumentName, String argumentExpressionString, PrimitiveElement... elements) Constructor - creates dependent argument(with hidden argument expression).Argument
(String argumentName, ArgumentExtension argumentExtension) Constructor for argument definition based on your own source code - this is via implementation of ArgumentExtension interface.Argument
(String argumentDefinitionString, PrimitiveElement... elements) Default constructor - creates argument based on the argument definition string. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addArguments
(Argument... arguments) Adds arguments (variadic) to the argument expression definition.void
addConstants
(List<Constant> constantsList) Adds constants to the argument expression definition.void
addConstants
(Constant... constants) Adds constants (variadic parameters) to the argument expression definition.void
addDefinitions
(PrimitiveElement... elements) Adds user defined elements (such as: Arguments, Constants, Functions) to the argument expressions.void
addFunctions
(Function... functions) Adds functions (variadic parameters) to the argument expression definition.boolean
Checks argument syntaxclone()
Creates cloned object of the this argument.''void
defineArgument
(String argumentName, double argumentValue) Enables to define the argument (associated with the argument expression) based on the argument name and the argument value.void
defineArguments
(String... argumentsNames) Enables to define the arguments (associated with the argument expression) based on the given arguments names.void
defineConstant
(String constantName, double constantValue) Enables to define the constant (associated with the argument expression) based on the constant name and constant value.void
defineFunction
(String functionName, String functionExpressionString, String... argumentsNames) Enables to define the function (associated with the argument expression) based on the function name, function expression string and arguments names (variadic parameters).getArgument
(int argumentIndex) Gets argument from the argument expression.getArgument
(String argumentName) Gets argument from the argument expression.int
Returns argument body type:BODY_RUNTIME
BODY_EXTENDED
Gets argument expression stringint
getArgumentIndex
(String argumentName) Gets argument index from the argument expression.Gets argument nameint
Gets number of arguments associated with the argument expression.int
Gets argument typedouble
Gets argument value.double
Gets computing timegetConstant
(int constantIndex) Gets constant associated with the argument expression.getConstant
(String constantName) Gets constant associated with the argument expression.int
getConstantIndex
(String constantName) Gets constant index associated with the argument expression.int
Gets number of constants associated with the argument expression.Gets argument description.Returns error message after checking the syntaxgetFunction
(int functionIndex) Gets function associated with the argument expression.getFunction
(String functionName) Gets function associated with the argument expression.int
getFunctionIndex
(String functionName) Gets index of function associated with the argument expression.int
Gets number of functions associated with the argument expression.boolean
Gets recursive mode statusboolean
Returns verbose mode statusvoid
Removes all arguments associated with the argument expression.void
Removes all constants associated with the argument expressionvoid
Removes all functions associated with the argument expression.void
removeArguments
(String... argumentsNames) Removes first occurrences of the arguments associated with the argument expression.void
removeArguments
(Argument... arguments) Removes first occurrences of the arguments associated with the argument expression.void
removeConstants
(String... constantsNames) Removes first occurrences of the constants associated with the argument expression.void
removeConstants
(Constant... constants) Removes first occurrences of the constants associated with the argument expressionvoid
removeDefinitions
(PrimitiveElement... elements) Removes user defined elements (such as: Arguments, Constants, Functions) from the argument expressions.void
removeFunctions
(String... functionsNames) Removes first occurrences of the functions associated with the argument expression.void
removeFunctions
(Function... functions) Removes first occurrences of the functions associated with the argument expression.void
setArgumentExpressionString
(String argumentExpressionString) Sets argument expression string.void
setArgumentName
(String argumentName) Sets (modifies) argument name.void
setArgumentValue
(double argumentValue) Sets argument value, if DEPENDENT_ARGUMENT then argument type is set to FREE_ARGUMENT.void
setDescription
(String description) Sets argument description.void
Disables argument verbose mode (sets default silent mode)void
Enables argument verbose modeMethods inherited from class org.mariuszgromada.math.mxparser.PrimitiveElement
getMyTypeId
-
Field Details
-
NO_SYNTAX_ERRORS
public static final boolean NO_SYNTAX_ERRORSNo syntax errors in the dependent argument definition.- See Also:
-
SYNTAX_ERROR_OR_STATUS_UNKNOWN
public static final boolean SYNTAX_ERROR_OR_STATUS_UNKNOWNSyntax error in the dependent argument definition.- See Also:
-
ARGUMENT_INITIAL_VALUE
public static final double ARGUMENT_INITIAL_VALUEDouble.NaN as initial value of the argument.- See Also:
-
NOT_FOUND
public static final int NOT_FOUNDWhen argument was not not found- See Also:
-
FREE_ARGUMENT
public static final int FREE_ARGUMENTType indicator for free argument.- See Also:
-
DEPENDENT_ARGUMENT
public static final int DEPENDENT_ARGUMENTType indicator for dependent argument.- See Also:
-
RECURSIVE_ARGUMENT
public static final int RECURSIVE_ARGUMENTType indicator for recursive argument.- See Also:
-
TYPE_ID
public static final int TYPE_IDArgument type id for the definition of key words known by the parser.- See Also:
-
TYPE_DESC
- See Also:
-
BODY_RUNTIME
public static final int BODY_RUNTIMEArgument with body based on the value or expression string.- See Also:
-
BODY_EXTENDED
public static final int BODY_EXTENDEDArgument with body based on the extended code. -
n
Index argument.- See Also:
-
-
Constructor Details
-
Argument
Default constructor - creates argument based on the argument definition string.- Parameters:
argumentDefinitionString
- Argument definition string, i.e.:- 'x' - only argument name
- 'x=5' - argument name and argument value
- 'x=2*5' - argument name and argument value given as simple expression
- 'x=2*y' - argument name and argument expression (dependent argument 'x' on argument 'y')
elements
- Optional parameters (comma separated) such as Arguments, Constants, Functions
-
Argument
public Argument(String argumentDefinitionString, boolean forceDependent, PrimitiveElement... elements) Default constructor - creates argument based on the argument definition string.- Parameters:
argumentDefinitionString
- Argument definition string, i.e.:- 'x' - only argument name
- 'x=5' - argument name and argument value
- 'x=2*5' - argument name and argument value given as simple expression
- 'x=2*y' - argument name and argument expression (dependent argument 'x' on argument 'y')
forceDependent
- If true parser will try to create dependent argumentelements
- Optional parameters (comma separated) such as Arguments, Constants, Functions
-
Argument
Constructor - creates free argument.- Parameters:
argumentName
- the argument nameargumentValue
- the argument value
-
Argument
Constructor for argument definition based on your own source code - this is via implementation of ArgumentExtension interface.- Parameters:
argumentName
- Argument nameargumentExtension
- Your own source code
-
Argument
Constructor - creates dependent argument(with hidden argument expression).- Parameters:
argumentName
- the argument nameargumentExpressionString
- the argument expression stringelements
- Optional parameters (comma separated) such as Arguments, Constants, Functions- See Also:
-
-
Method Details
-
setDescription
Sets argument description.- Parameters:
description
- the argument description.
-
getDescription
Gets argument description.- Returns:
- The argument description string.
-
setVerboseMode
public void setVerboseMode()Enables argument verbose mode -
setSilentMode
public void setSilentMode()Disables argument verbose mode (sets default silent mode) -
getVerboseMode
public boolean getVerboseMode()Returns verbose mode status- Returns:
- true if verbose mode is on, otherwise returns false.
-
getRecursiveMode
public boolean getRecursiveMode()Gets recursive mode status- Returns:
- true if recursive mode is enabled, otherwise returns false
-
getComputingTime
public double getComputingTime()Gets computing time- Returns:
- Computing time in seconds.
-
setArgumentName
Sets (modifies) argument name. Each expression / function / dependent argument associated with this argument will be marked as modified (requires new syntax checking).- Parameters:
argumentName
- the argument name
-
setArgumentExpressionString
Sets argument expression string. Each expression / function / dependent argument associated with this argument will be marked as modified (requires new syntax checking). If BODY_EXTENDED argument then BODY_RUNTIME is set.- Parameters:
argumentExpressionString
- the argument expression string- See Also:
-
getArgumentName
Gets argument name- Returns:
- the argument name as string
-
getArgumentExpressionString
Gets argument expression string- Returns:
- the argument expression string
-
getArgumentType
public int getArgumentType()Gets argument type- Returns:
- Argument type: Argument.FREE_ARGUMENT, Argument.DEPENDENT_ARGUMENT, Argument.RECURSIVE_ARGUMENT
-
setArgumentValue
public void setArgumentValue(double argumentValue) Sets argument value, if DEPENDENT_ARGUMENT then argument type is set to FREE_ARGUMENT. If BODY_EXTENDED argument the BODY_RUNTIME argument is set.- Parameters:
argumentValue
- the value of argument
-
getArgumentBodyType
public int getArgumentBodyType()Returns argument body type:BODY_RUNTIME
BODY_EXTENDED
- Returns:
- Returns argument body type:
BODY_RUNTIME
BODY_EXTENDED
-
checkSyntax
public boolean checkSyntax()Checks argument syntax- Returns:
- syntax status: Argument.NO_SYNTAX_ERRORS, Argument.SYNTAX_ERROR_OR_STATUS_UNKNOWN
-
getErrorMessage
Returns error message after checking the syntax- Returns:
- Error message as string.
-
getArgumentValue
public double getArgumentValue()Gets argument value.- Returns:
- direct argument value for free argument, otherwise returns calculated argument value based on the argument expression.
-
addDefinitions
Adds user defined elements (such as: Arguments, Constants, Functions) to the argument expressions.- Parameters:
elements
- Elements list (variadic - comma separated) of types: Argument, Constant, Function- See Also:
-
removeDefinitions
Removes user defined elements (such as: Arguments, Constants, Functions) from the argument expressions.- Parameters:
elements
- Elements list (variadic - comma separated) of types: Argument, Constant, Function- See Also:
-
addArguments
Adds arguments (variadic) to the argument expression definition.- Parameters:
arguments
- the arguments list (comma separated list)- See Also:
-
defineArguments
Enables to define the arguments (associated with the argument expression) based on the given arguments names.- Parameters:
argumentsNames
- the arguments names (variadic) comma separated list- See Also:
-
defineArgument
Enables to define the argument (associated with the argument expression) based on the argument name and the argument value.- Parameters:
argumentName
- the argument nameargumentValue
- the the argument value- See Also:
-
getArgumentIndex
Gets argument index from the argument expression.- Parameters:
argumentName
- the argument name- Returns:
- The argument index if the argument name was found, otherwise returns Argument.NOT_FOUND
- See Also:
-
getArgument
Gets argument from the argument expression.- Parameters:
argumentName
- the argument name- Returns:
- The argument if the argument name was found, otherwise returns null.
- See Also:
-
getArgument
Gets argument from the argument expression.- Parameters:
argumentIndex
- the argument index- Returns:
- Argument if the argument index is between 0 and the last available argument index (getArgumentsNumber()-1), otherwise returns null.
- See Also:
-
getArgumentsNumber
public int getArgumentsNumber()Gets number of arguments associated with the argument expression.- Returns:
- The number of arguments (int >= 0)
- See Also:
-
removeArguments
Removes first occurrences of the arguments associated with the argument expression.- Parameters:
argumentsNames
- the arguments names (variadic parameters) comma separated list- See Also:
-
removeArguments
Removes first occurrences of the arguments associated with the argument expression.- Parameters:
arguments
- the arguments (variadic parameters) comma separated list- See Also:
-
removeAllArguments
public void removeAllArguments()Removes all arguments associated with the argument expression.- See Also:
-
addConstants
Adds constants (variadic parameters) to the argument expression definition.- Parameters:
constants
- the constants (comma separated list)- See Also:
-
addConstants
Adds constants to the argument expression definition.- Parameters:
constantsList
- the list of constants- See Also:
-
defineConstant
Enables to define the constant (associated with the argument expression) based on the constant name and constant value.- Parameters:
constantName
- the constant nameconstantValue
- the constant value- See Also:
-
getConstantIndex
Gets constant index associated with the argument expression.- Parameters:
constantName
- the constant name- Returns:
- Constant index if constant name was found, otherwise return Constant.NOT_FOUND.
- See Also:
-
getConstant
Gets constant associated with the argument expression.- Parameters:
constantName
- the constant name- Returns:
- Constant if constant name was found, otherwise return null.
- See Also:
-
getConstant
Gets constant associated with the argument expression.- Parameters:
constantIndex
- the constant index- Returns:
- Constant if the constantIndex is between 0 and the last available constant index (getConstantsNumber() - 1), otherwise it returns null.
- See Also:
-
getConstantsNumber
public int getConstantsNumber()Gets number of constants associated with the argument expression.- Returns:
- number of constants (int >= 0)
- See Also:
-
removeConstants
Removes first occurrences of the constants associated with the argument expression.- Parameters:
constantsNames
- the constants names (variadic parameters) comma separated list- See Also:
-
removeConstants
Removes first occurrences of the constants associated with the argument expression- Parameters:
constants
- the constants (variadic parameters) comma separated list- See Also:
-
removeAllConstants
public void removeAllConstants()Removes all constants associated with the argument expression- See Also:
-
addFunctions
Adds functions (variadic parameters) to the argument expression definition.- Parameters:
functions
- the functions (variadic parameters) comma separated list- See Also:
-
defineFunction
public void defineFunction(String functionName, String functionExpressionString, String... argumentsNames) Enables to define the function (associated with the argument expression) based on the function name, function expression string and arguments names (variadic parameters).- Parameters:
functionName
- the function namefunctionExpressionString
- the expression stringargumentsNames
- the function arguments names (variadic parameters) comma separated list- See Also:
-
getFunctionIndex
Gets index of function associated with the argument expression.- Parameters:
functionName
- the function name- Returns:
- Function index if function name was found, otherwise returns Function.NOT_FOUND
- See Also:
-
getFunction
Gets function associated with the argument expression.- Parameters:
functionName
- the function name- Returns:
- Function if function name was found, otherwise returns null.
- See Also:
-
getFunction
Gets function associated with the argument expression.- Parameters:
functionIndex
- the function index- Returns:
- Function if function index is between 0 and the last available function index (getFunctionsNumber()-1), otherwise returns null.
- See Also:
-
getFunctionsNumber
public int getFunctionsNumber()Gets number of functions associated with the argument expression.- Returns:
- number of functions (int >= 0)
- See Also:
-
removeFunctions
Removes first occurrences of the functions associated with the argument expression.- Parameters:
functionsNames
- the functions names (variadic parameters) comma separated list- See Also:
-
removeFunctions
Removes first occurrences of the functions associated with the argument expression.- Parameters:
functions
- the functions (variadic parameters) comma separated list.- See Also:
-
removeAllFunctions
public void removeAllFunctions()Removes all functions associated with the argument expression.- See Also:
-
clone
Creates cloned object of the this argument.''
-