Class ExpressionBuilder


  • public class ExpressionBuilder
    extends java.lang.Object
    Factory class for Expression instances. This class is the main API entrypoint. Users should create new Expression instances using this factory class.
    • Constructor Detail

      • ExpressionBuilder

        public ExpressionBuilder​(java.lang.String expression)
        Create a new ExpressionBuilder instance and initialize it with a given expression string.
        Parameters:
        expression - the expression to be parsed
    • Method Detail

      • disableBuiltInFunctions

        public ExpressionBuilder disableBuiltInFunctions()
        Removes all of the built-in functions
        Returns:
        the ExpressionBuilder instance
      • function

        public ExpressionBuilder function​(Function function)
        Add a Function implementation available for use in the expression.
        Parameters:
        function - the custom Function implementation that should be available for use in the expression.
        Returns:
        the ExpressionBuilder instance
      • functions

        public ExpressionBuilder functions​(Function... functions)
        Add multiple Function implementations available for use in the expression.
        Parameters:
        functions - the custom Function implementations
        Returns:
        the ExpressionBuilder instance
      • functions

        public ExpressionBuilder functions​(java.util.List<Function> functions)
        Add multiple Function implementations available for use in the expression
        Parameters:
        functions - A List of custom Function implementations
        Returns:
        the ExpressionBuilder instance
      • variables

        public ExpressionBuilder variables​(java.util.Set<java.lang.String> variableNames)
        Add multiple variables 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:
        java.lang.IllegalArgumentException - if the variable name contains spaces or operator characters
      • variables

        public ExpressionBuilder variables​(java.lang.String... variableNames)
        Add multiple variables 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:
        java.lang.IllegalArgumentException - if the variable name contains spaces or operator characters
      • variable

        public ExpressionBuilder variable​(java.lang.String variableName)
        Add a variable 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:
        java.lang.IllegalArgumentException - if the variable name contains spaces or operator characters
      • operator

        public ExpressionBuilder operator​(Operator operator)
        Add an Operator which should be available for use in the expression
        Parameters:
        operator - the custom Operator to add
        Returns:
        the ExpressionBuilder instance
      • operators

        public ExpressionBuilder operators​(Operator... operators)
        Add multiple Operator implementations which should be available for use in the expression
        Parameters:
        operators - the set of custom Operator implementations to add
        Returns:
        the ExpressionBuilder instance
      • operators

        public ExpressionBuilder operators​(java.util.List<Operator> operators)
        Add multiple Operator implementations which should be available for use in the expression
        Parameters:
        operators - the List of custom Operator implementations to add
        Returns:
        the ExpressionBuilder instance
      • build

        public Expression build()
        Build the Expression instance using the custom operators and functions set.
        Returns:
        an Expression instance which can be used to evaluate the result of the expression
      • build

        public Expression build​(boolean simplify)
        Build the Expression instance using the custom operators and functions set.
        Parameters:
        simplify - true if you want to attempt to simplify constants false otherwise
        Returns:
        an Expression instance which can be used to evaluate the result of the expression
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object