public class OperatorRepository extends Object
OperatorRepository
class is the repository of all operators, functions, variables, and constants in the environment.// using lambda expression OperatorRepository.addFunction("si", 3, (ops) -> { return new Operand((ops[0].toDouble() * ops[1].toDouble() * ops[2].toDouble()) / 100.0); }); // using anonymous class OperatorRepository.addFunction("si", 3, new Function() { @Override public Operand evaluate(Operand ... ops) { return new Operand((ops[0].toDouble() * ops[1].toDouble() * ops[2].toDouble()) / 100.0); } } );
Modifier and Type | Field and Description |
---|---|
protected static Map<String,Operator.Properties> |
OPERATORS
A map of all operators, functions, variables, and constants supported.
|
protected static List<String> |
PREDEFINED_OPERATORS
A list of all predefined operators, functions, variables, and constants.
|
Modifier and Type | Method and Description |
---|---|
static void |
addFunction(String fName,
Function function)
Utility method to add user defined function with variable number of parameters to the environment.
Method names can consist of lowercase letters, uppercase letters, and digits. |
static void |
addFunction(String fName,
int params,
Function function)
Utility method to add user defined function to the environment.
Method names can consist of lowercase letters, uppercase letters, and digits. |
static List<String> |
getOperatorList()
Utility method to get list of all operator names currently supported by the environment.
The returned list is sorted lexicographically by operator names. |
static Operator.Properties |
getOperatorProperties(String value)
Utility method to get the properties of an operator.
|
static boolean |
isFunction(String op)
Utility method to determine if a string is a supported function.
|
static boolean |
isOperator(String op)
Utility method to determine if a string is a supported operator.
|
static boolean |
isVariableOrConstant(String op)
Utility method to determine if a string is a supported variable or constant.
|
static void |
removeFunction(String fName)
Utility method to remove user defined function from the environment.
Method names can consist of lowercase letters, uppercase letters, and digits. |
protected static final Map<String,Operator.Properties> OPERATORS
public static Operator.Properties getOperatorProperties(String value)
value
- The operator value as a stringpublic static boolean isOperator(String op)
op
- The string to checkpublic static boolean isFunction(String op)
op
- The string to checkpublic static boolean isVariableOrConstant(String op)
op
- The string to checkpublic static void addFunction(String fName, int params, Function function)
fName
- Function name - e.g. for function name 'myFunc', it will be called as myFunc(...)params
- Number of parametersfunction
- Function definitionpublic static void addFunction(String fName, Function function)
fName
- Function name - e.g. for function name 'myFunc', it will be called as myFunc(...)function
- Function definitionpublic static void removeFunction(String fName)
fName
- Function name - e.g. for function name 'myFunc', it will be called as myFunc(...)Copyright © 2019 Pratanu Mandal. All rights reserved.