public class Function extends PrimitiveElement
When creating a function you should avoid names reserved as parser keywords, in general words known in mathematical language as function names, operators (for example: sin, cos, +, -, pi, e, etc...). Please be informed that after associating the constant 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.
RecursiveArgument
,
Expression
,
Argument
,
Constant
,
FunctionExtension
Modifier and Type | Field and Description |
---|---|
static int |
BODY_EXTENDED
Function with body based on the extended code.
|
static int |
BODY_RUNTIME
Function with body based on the expression string.
|
static boolean |
NO_SYNTAX_ERRORS
No syntax errors in the function.
|
static int |
NOT_FOUND
When function was not found
|
static boolean |
SYNTAX_ERROR_OR_STATUS_UNKNOWN
Syntax error in the function or syntax status unknown.
|
static java.lang.String |
TYPE_DESC |
static int |
TYPE_ID
Function type id identifier
|
Constructor and Description |
---|
Function(java.lang.String functionName,
FunctionExtension functionExtension)
Constructor for function definition based on
your own source code - this is via implementation
of FunctionExtension interface.
|
Function(java.lang.String functionDefinitionString,
PrimitiveElement... elements)
Constructor for function definition in natural math language,
for instance providing on string "f(x,y) = sin(x) + cos(x)"
is enough to define function "f" with parameters "x and y"
and function body "sin(x) + cos(x)".
|
Function(java.lang.String functionName,
java.lang.String functionExpressionString,
PrimitiveElement... elements)
Constructor - creates function from function name
and function expression string.
|
Function(java.lang.String functionName,
java.lang.String functionExpressionString,
java.lang.String... argumentsNames)
Constructor - creates function from function name,
function expression string and argument names.
|
Modifier and Type | Method and Description |
---|---|
void |
addArguments(Argument... arguments)
Adds arguments (variadic) to the function expression definition.
|
void |
addConstants(Constant... constants)
Adds constants (variadic parameters) to the function expression definition.
|
void |
addConstants(java.util.List<Constant> constantsList)
Adds constants to the function expression definition.
|
void |
addDefinitions(PrimitiveElement... elements)
Adds user defined elements (such as: Arguments, Constants, Functions)
to the function expressions.
|
void |
addFunctions(Function... functions)
Adds functions (variadic parameters) to the function expression definition.
|
double |
calculate()
Calculates function value
|
double |
calculate(Argument... arguments)
Calculates function value
|
double |
calculate(double... params)
Calculates function value
|
boolean |
checkSyntax()
Checks function syntax
|
void |
defineArgument(java.lang.String argumentName,
double argumentValue)
Enables to define the argument (associated with the function expression)
based on the argument name and the argument value.
|
void |
defineArguments(java.lang.String... argumentsNames)
Enables to define the arguments (associated with
the function expression) based on the given arguments names.
|
void |
defineConstant(java.lang.String constantName,
double constantValue)
Enables to define the constant (associated with
the function 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 function expression) based on the function name,
function expression string and arguments names (variadic parameters).
|
Argument |
getArgument(int argumentIndex)
Gets argument from the function expression.
|
Argument |
getArgument(java.lang.String argumentName)
Gets argument from the function expression.
|
int |
getArgumentIndex(java.lang.String argumentName)
Gets argument index from the function expression.
|
int |
getArgumentsNumber()
Gets number of arguments associated with the function expression.
|
double |
getComputingTime()
Gets computing time
|
Constant |
getConstant(int constantIndex)
Gets constant associated with the function expression.
|
Constant |
getConstant(java.lang.String constantName)
Gets constant associated with the function expression.
|
int |
getConstantIndex(java.lang.String constantName)
Gets constant index associated with the function expression.
|
int |
getConstantsNumber()
Gets number of constants associated with the function expression.
|
java.lang.String |
getDescription()
Gets function description
|
java.lang.String |
getErrorMessage()
Returns error message after checking the syntax.
|
Function |
getFunction(int functionIndex)
Gets function associated with the function expression.
|
Function |
getFunction(java.lang.String functionName)
Gets function associated with the function expression.
|
int |
getFunctionBodyType()
Returns function body type:
BODY_RUNTIME BODY_EXTENDED |
java.lang.String |
getFunctionExpressionString()
Gets function expression string
|
int |
getFunctionIndex(java.lang.String functionName)
Gets index of function associated with the function expression.
|
java.lang.String |
getFunctionName()
Gets function name.
|
int |
getFunctionsNumber()
Gets number of functions associated with the function expression.
|
java.lang.String |
getParameterName(int parameterIndex)
Gets user defined function parameter name
|
int |
getParametersNumber()
Gets number of parameters associated with the function expression.
|
boolean |
getRecursiveMode()
Gets recursive mode status
|
boolean |
getVerboseMode()
Returns verbose mode status
|
void |
removeAllArguments()
Removes all arguments associated with the function expression.
|
void |
removeAllConstants()
Removes all constants
associated with the function expression
|
void |
removeAllFunctions()
Removes all functions
associated with the function expression.
|
void |
removeArguments(Argument... arguments)
Removes first occurrences of the arguments
associated with the function expression.
|
void |
removeArguments(java.lang.String... argumentsNames)
Removes first occurrences of the arguments
associated with the function expression.
|
void |
removeConstants(Constant... constants)
Removes first occurrences of the constants
associated with the function expression
|
void |
removeConstants(java.lang.String... constantsNames)
Removes first occurrences of the constants
associated with the function expression.
|
void |
removeDefinitions(PrimitiveElement... elements)
Removes user defined elements (such as: Arguments, Constants, Functions)
from the function expressions.
|
void |
removeFunctions(Function... functions)
Removes first occurrences of the functions
associated with the function expression.
|
void |
removeFunctions(java.lang.String... functionsNames)
Removes first occurrences of the functions
associated with the function expression.
|
void |
setArgumentValue(int argumentIndex,
double argumentValue)
Sets value of function argument (function parameter).
|
void |
setDescription(java.lang.String description)
Sets function description.
|
void |
setFunctionName(java.lang.String functionName)
Sets function name.
|
void |
setParametersNumber(int parametersNumber)
Set parameters number.
|
void |
setSilentMode()
Disables function verbose mode (sets default silent mode)
|
void |
setVerboseMode()
Enables verbose function mode
|
getMyTypeId
public static final boolean NO_SYNTAX_ERRORS
public static final boolean SYNTAX_ERROR_OR_STATUS_UNKNOWN
public static final int NOT_FOUND
public static final int TYPE_ID
public static final java.lang.String TYPE_DESC
public static final int BODY_RUNTIME
getFunctionBodyType()
,
Constant Field Valuespublic static final int BODY_EXTENDED
public Function(java.lang.String functionName, java.lang.String functionExpressionString, PrimitiveElement... elements)
functionName
- the function namefunctionExpressionString
- the function expression stringelements
- Optional elements list (variadic - comma separated) of types: Argument, Constant, FunctionPrimitiveElement
,
Expression
public Function(java.lang.String functionName, java.lang.String functionExpressionString, java.lang.String... argumentsNames)
functionName
- the function namefunctionExpressionString
- the function expression stringargumentsNames
- the arguments names (variadic parameters)
comma separated listExpression
public Function(java.lang.String functionDefinitionString, PrimitiveElement... elements)
functionDefinitionString
- Function definition in the form
of one String, ie "f(x,y) = sin(x) + cos(x)"elements
- Optional elements list (variadic - comma separated)
of types: Argument, Constant, FunctionPrimitiveElement
public Function(java.lang.String functionName, FunctionExtension functionExtension)
functionName
- Function namefunctionExtension
- Your own source codepublic void setDescription(java.lang.String description)
description
- the function descriptionpublic java.lang.String getDescription()
public java.lang.String getFunctionName()
public java.lang.String getFunctionExpressionString()
public void setFunctionName(java.lang.String functionName)
functionName
- the function namepublic void setArgumentValue(int argumentIndex, double argumentValue)
argumentIndex
- the argument index (in accordance to
arguments declaration sequence)argumentValue
- the argument valuepublic int getFunctionBodyType()
BODY_RUNTIME
BODY_EXTENDED
BODY_RUNTIME
BODY_EXTENDED
public boolean checkSyntax()
public java.lang.String getErrorMessage()
public double calculate()
public double calculate(double... params)
params
- the function parameters values (as doubles)public double calculate(Argument... arguments)
arguments
- function parameters (as Arguments)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 getParametersNumber()
Argument
,
RecursiveArgument
public void setParametersNumber(int parametersNumber)
parametersNumber
- the number of function parameters (default = number of arguments
(less number might be specified).public java.lang.String getParameterName(int parameterIndex)
parameterIndex
- Parameter index between 0 and n-1public int getArgumentsNumber()
Argument
,
RecursiveArgument
public 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 void setVerboseMode()
public void setSilentMode()
public boolean getVerboseMode()
public boolean getRecursiveMode()
public double getComputingTime()