Package net.objecthunter.exp4j.function
Class Function
java.lang.Object
net.objecthunter.exp4j.function.Function
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
FunctionExpresion
A class representing a Function which can be used in an expression
- See Also:
-
Constructor Summary
ConstructorDescriptionCreate a new Function with a given name that takes a single argumentCreate a new Function with a given name and number of argumentsCreate a new Function with a given name and number of arguments -
Method Summary
Modifier and TypeMethodDescriptionabstract double
apply
(double... args) Method that does the actual calculation of the function value given the argumentsgetName()
Get the name of the Functionint
Get the number of arguments for this functionboolean
Tells if a function is deterministic, in this scenario basically applies to functions that are not supposed to be simplified.static boolean
isValidFunctionName
(String name) Tells if a function name is valid in the context of the expression.
-
Constructor Details
-
Function
Create a new Function with a given name and number of arguments- Parameters:
name
- the name of the FunctionnumArguments
- the number of arguments the function takesdeterministic
-true
if the function is deterministic (i.e. can be simplified)false
otherwise
-
Function
Create a new Function with a given name and number of arguments- Parameters:
name
- the name of the FunctionnumArguments
- the number of arguments the function takes
-
Function
Create a new Function with a given name that takes a single argument- Parameters:
name
- the name of the Function
-
-
Method Details
-
isDeterministic
public boolean isDeterministic()Tells if a function is deterministic, in this scenario basically applies to functions that are not supposed to be simplified.- Returns:
true
if the function is to be simplified (deterministic) andfalse
otherwise
-
getName
Get the name of the Function- Returns:
- the name
-
getNumArguments
public int getNumArguments()Get the number of arguments for this function- Returns:
- the number of arguments
-
apply
public abstract double apply(double... args) Method that does the actual calculation of the function value given the arguments- Parameters:
args
- the set of arguments used for calculating the function- Returns:
- the result of the function evaluation
-
isValidFunctionName
Tells if a function name is valid in the context of the expression. This means that it's notnull
or empty, and it only containsASCII
chars,_
or digits.- Parameters:
name
- name to test- Returns:
true
if the function name can be used andfalse
otherwise
-