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 String |
TYPE_DESC |
static int |
TYPE_ID
Function type id identifier
|
| Constructor and Description |
|---|
Function(String functionName,
FunctionExtension functionExtension)
Constructor for function definition based on
your own source code - this is via implementation
of FunctionExtension interface.
|
Function(String functionName,
FunctionExtensionVariadic functionExtensionVariadic)
Constructor for function definition based on
your own source code - this is via implementation
of FunctionExtensionVariadic interface.
|
Function(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(String functionName,
String functionExpressionString,
PrimitiveElement... elements)
Constructor - creates function from function name
and function expression string.
|
Function(String functionName,
String functionExpressionString,
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(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... parameters)
Calculates function value
|
boolean |
checkSyntax()
Checks function syntax
|
protected Function |
clone()
clone method
|
void |
defineArgument(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(String... argumentsNames)
Enables to define the arguments (associated with
the function expression) based on the given arguments names.
|
void |
defineConstant(String constantName,
double constantValue)
Enables to define the constant (associated with
the function 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 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(String argumentName)
Gets argument from the function expression.
|
int |
getArgumentIndex(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(String constantName)
Gets constant associated with the function expression.
|
int |
getConstantIndex(String constantName)
Gets constant index associated with the function expression.
|
int |
getConstantsNumber()
Gets number of constants associated with the function expression.
|
String |
getDescription()
Gets function description
|
String |
getErrorMessage()
Returns error message after checking the syntax.
|
Function |
getFunction(int functionIndex)
Gets function associated with the function expression.
|
Function |
getFunction(String functionName)
Gets function associated with the function expression.
|
int |
getFunctionBodyType()
Returns function body type:
BODY_RUNTIME BODY_EXTENDED |
String |
getFunctionExpressionString()
Gets function expression string
|
int |
getFunctionIndex(String functionName)
Gets index of function associated with the function expression.
|
String |
getFunctionName()
Gets function name.
|
int |
getFunctionsNumber()
Gets number of functions associated with the function expression.
|
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(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(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(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(String description)
Sets function description.
|
void |
setFunction(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)".
|
void |
setFunctionName(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
|
getMyTypeIdpublic 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 String TYPE_DESC
public static final int BODY_RUNTIME
getFunctionBodyType(),
Constant Field Valuespublic static final int BODY_EXTENDED
public Function(String functionName, String functionExpressionString, PrimitiveElement... elements)
functionName - the function namefunctionExpressionString - the function expression stringelements - Optional elements list (variadic - comma separated) of types: Argument, Constant, FunctionPrimitiveElement,
Expressionpublic Function(String functionName, String functionExpressionString, String... argumentsNames)
functionName - the function namefunctionExpressionString - the function expression stringargumentsNames - the arguments names (variadic parameters)
comma separated listExpressionpublic Function(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, FunctionPrimitiveElementpublic Function(String functionName, FunctionExtension functionExtension)
functionName - Function namefunctionExtension - Your own source codepublic Function(String functionName, FunctionExtensionVariadic functionExtensionVariadic)
functionName - Function namefunctionExtensionVariadic - Your own source codepublic void setFunction(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, FunctionPrimitiveElementpublic void setDescription(String description)
description - the function descriptionpublic String getDescription()
public String getFunctionName()
public String getFunctionExpressionString()
public void setFunctionName(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_EXTENDEDBODY_RUNTIME BODY_EXTENDEDpublic boolean checkSyntax()
public String getErrorMessage()
public double calculate()
public double calculate(double... parameters)
parameters - 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 PrimitiveElementPrimitiveElementpublic void removeDefinitions(PrimitiveElement... elements)
elements - Elements list (variadic), where Argument, Constant, Function
extend the same class PrimitiveElementPrimitiveElementpublic void addArguments(Argument... arguments)
arguments - the arguments list
(comma separated list)Argument,
RecursiveArgumentpublic void defineArguments(String... argumentsNames)
argumentsNames - the arguments names (variadic)
comma separated listArgument,
RecursiveArgumentpublic void defineArgument(String argumentName, double argumentValue)
argumentName - the argument nameargumentValue - the the argument valueArgument,
RecursiveArgumentpublic int getArgumentIndex(String argumentName)
argumentName - the argument nameArgument,
RecursiveArgumentpublic Argument getArgument(String argumentName)
argumentName - the argument nameArgument,
RecursiveArgumentpublic Argument getArgument(int argumentIndex)
argumentIndex - the argument indexArgument,
RecursiveArgumentpublic int getParametersNumber()
Argument,
RecursiveArgumentpublic void setParametersNumber(int parametersNumber)
parametersNumber - the number of function parameters (default = number of arguments
(less number might be specified).public String getParameterName(int parameterIndex)
parameterIndex - Parameter index between 0 and n-1public int getArgumentsNumber()
Argument,
RecursiveArgumentpublic void removeArguments(String... argumentsNames)
argumentsNames - the arguments names
(variadic parameters) comma separated
listArgument,
RecursiveArgumentpublic void removeArguments(Argument... arguments)
arguments - the arguments (variadic parameters)
comma separated listArgument,
RecursiveArgumentpublic void removeAllArguments()
Argument,
RecursiveArgumentpublic void addConstants(Constant... constants)
constants - the constants
(comma separated list)Constantpublic void addConstants(List<Constant> constantsList)
constantsList - the list of constantsConstantpublic void defineConstant(String constantName, double constantValue)
constantName - the constant nameconstantValue - the constant valueConstantpublic int getConstantIndex(String constantName)
constantName - the constant nameConstantpublic Constant getConstant(String constantName)
constantName - the constant nameConstantpublic Constant getConstant(int constantIndex)
constantIndex - the constant indexConstantpublic int getConstantsNumber()
Constantpublic void removeConstants(String... constantsNames)
constantsNames - the constants names (variadic parameters)
comma separated listConstantpublic void removeConstants(Constant... constants)
constants - the constants (variadic parameters)
comma separated listConstantpublic void removeAllConstants()
Constantpublic void addFunctions(Function... functions)
functions - the functions
(variadic parameters) comma separated listFunctionpublic void defineFunction(String functionName, String functionExpressionString, String... argumentsNames)
functionName - the function namefunctionExpressionString - the expression stringargumentsNames - the function arguments names
(variadic parameters)
comma separated listFunctionpublic int getFunctionIndex(String functionName)
functionName - the function nameFunctionpublic Function getFunction(String functionName)
functionName - the function nameFunctionpublic Function getFunction(int functionIndex)
functionIndex - the function indexFunctionpublic int getFunctionsNumber()
Functionpublic void removeFunctions(String... functionsNames)
functionsNames - the functions names (variadic parameters)
comma separated listFunctionpublic void removeFunctions(Function... functions)
functions - the functions (variadic parameters)
comma separated list.Functionpublic void removeAllFunctions()
Functionpublic void setVerboseMode()
public void setSilentMode()
public boolean getVerboseMode()
public boolean getRecursiveMode()
public double getComputingTime()
Copyright © 2020 MathParser.org. All rights reserved.