Package net.objecthunter.exp4j
Class ExpressionBuilder
java.lang.Object
net.objecthunter.exp4j.ExpressionBuilder
Factory class for
Expression instances. This class is the main API entrypoint.
Users should create new Expression instances using this factory class.-
Constructor Summary
ConstructorsConstructorDescriptionExpressionBuilder(String expression) Create a new ExpressionBuilder instance and initialize it with a given expression string. -
Method Summary
Modifier and TypeMethodDescriptionbuild()Build theExpressioninstance using the custom operators and functions set.build(boolean simplify) Build theExpressioninstance using the custom operators and functions set.Removes all the built-in functionsAdd aFunctionimplementation available for use in the expression.Add multipleFunctionimplementations available for use in the expressionAdd multipleFunctionimplementations available for use in the expression.Add anOperatorwhich should be available for use in the expressionAdd multipleOperatorimplementations which should be available for use in the expressionAdd multipleOperatorimplementations which should be available for use in the expressiontoString()Add avariablethat must be used in the expression.
Note: the "must" part of that statement will change on future versions.Add multiplevariablesthat must be used in the expression.
Note: the "must" part of that statement will change on future versions.Add multiplevariablesthat must be used in the expression.
Note: the "must" part of that statement will change on future versions.
-
Constructor Details
-
ExpressionBuilder
Create a new ExpressionBuilder instance and initialize it with a given expression string.- Parameters:
expression- the expression to be parsed
-
-
Method Details
-
disableBuiltInFunctions
Removes all the built-in functions- Returns:
- the ExpressionBuilder instance
-
function
Add aFunctionimplementation available for use in the expression.- Parameters:
function- the customFunctionimplementation that should be available for use in the expression.- Returns:
- the ExpressionBuilder instance
-
functions
Add multipleFunctionimplementations available for use in the expression.- Parameters:
functions- the customFunctionimplementations- Returns:
- the ExpressionBuilder instance
-
functions
Add multipleFunctionimplementations available for use in the expression -
variables
Add multiplevariablesthat must be used in the expression.
Note: the "must" part of that statement will change on future versions.- Parameters:
variableNames- variables to use- Returns:
- the ExpressionBuilder instance
- Throws:
IllegalArgumentException- if the variable name contains spaces or operator characters
-
variables
Add multiplevariablesthat must be used in the expression.
Note: the "must" part of that statement will change on future versions.- Parameters:
variableNames- variables to use- Returns:
- the ExpressionBuilder instance
- Throws:
IllegalArgumentException- if the variable name contains spaces or operator characters
-
variable
Add avariablethat must be used in the expression.
Note: the "must" part of that statement will change on future versions.- Parameters:
variableName- variable to use- Returns:
- the ExpressionBuilder instance
- Throws:
IllegalArgumentException- if the variable name contains spaces or operator characters
-
operator
Add anOperatorwhich should be available for use in the expression- Parameters:
operator- the customOperatorto add- Returns:
- the ExpressionBuilder instance
-
operators
Add multipleOperatorimplementations which should be available for use in the expression- Parameters:
operators- the set of customOperatorimplementations to add- Returns:
- the ExpressionBuilder instance
-
operators
Add multipleOperatorimplementations which should be available for use in the expression -
build
Build theExpressioninstance using the custom operators and functions set.- Returns:
- an
Expressioninstance which can be used to evaluate the result of the expression
-
build
Build theExpressioninstance using the custom operators and functions set.- Parameters:
simplify-trueif you want to attempt to simplify constantsfalseotherwise- Returns:
- an
Expressioninstance which can be used to evaluate the result of the expression
-
toString
-