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
ConstructorDescriptionExpressionBuilder
(String expression) Create a new ExpressionBuilder instance and initialize it with a given expression string. -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Build theExpression
instance using the custom operators and functions set.build
(boolean simplify) Build theExpression
instance using the custom operators and functions set.Removes all the built-in functionsAdd aFunction
implementation available for use in the expression.Add multipleFunction
implementations available for use in the expressionAdd multipleFunction
implementations available for use in the expression.Add anOperator
which should be available for use in the expressionAdd multipleOperator
implementations which should be available for use in the expressionAdd multipleOperator
implementations which should be available for use in the expressiontoString()
Add avariable
that must be used in the expression.
Note: the "must" part of that statement will change on future versions.Add multiplevariables
that must be used in the expression.
Note: the "must" part of that statement will change on future versions.Add multiplevariables
that 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 aFunction
implementation available for use in the expression.- Parameters:
function
- the customFunction
implementation that should be available for use in the expression.- Returns:
- the ExpressionBuilder instance
-
functions
Add multipleFunction
implementations available for use in the expression.- Parameters:
functions
- the customFunction
implementations- Returns:
- the ExpressionBuilder instance
-
functions
Add multipleFunction
implementations available for use in the expression -
variables
Add multiplevariables
that 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 multiplevariables
that 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 avariable
that 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 anOperator
which should be available for use in the expression- Parameters:
operator
- the customOperator
to add- Returns:
- the ExpressionBuilder instance
-
operators
Add multipleOperator
implementations which should be available for use in the expression- Parameters:
operators
- the set of customOperator
implementations to add- Returns:
- the ExpressionBuilder instance
-
operators
Add multipleOperator
implementations which should be available for use in the expression -
build
Build theExpression
instance using the custom operators and functions set.- Returns:
- an
Expression
instance which can be used to evaluate the result of the expression
-
build
Build theExpression
instance using the custom operators and functions set.- Parameters:
simplify
-true
if you want to attempt to simplify constantsfalse
otherwise- Returns:
- an
Expression
instance which can be used to evaluate the result of the expression
-
toString
-