Class ExpressionEnv

java.lang.Object
redempt.crunch.functional.ExpressionEnv
Direct Known Subclasses:
EvaluationEnvironment

public class ExpressionEnv extends Object
Represents an environment containing functions that can be called in expressions
  • Constructor Details

    • ExpressionEnv

      public ExpressionEnv()
      Creates a new EvaluationEnvironment
  • Method Details

    • addFunction

      public ExpressionEnv addFunction(Function function)
      Adds a Function that can be called from expressions with this environment
      Parameters:
      function - The function
    • addFunctions

      public ExpressionEnv addFunctions(Function... functions)
      Adds any number of Functions that can be called from expressions with this environment
      Parameters:
      functions - The functions to add
    • addLazyVariable

      public ExpressionEnv addLazyVariable(String name, DoubleSupplier supply)
      Adds a lazily-evaluated variable that will not need to be passed with the variable values
      Parameters:
      name - The name of the lazy variable
      supply - A function to supply the value of the variable when needed
    • setVariableNames

      public ExpressionEnv setVariableNames(String... names)
    • addFunction

      public ExpressionEnv addFunction(String name, int argCount, ToDoubleFunction<double[]> func)
      Adds a Function that can be called from expressions with this environment
      Parameters:
      name - The function name
      argCount - The argument count for the function
      func - The lambda to accept the arguments as a double array and return a value
    • getLeadingOperators

      public CharTree<Token> getLeadingOperators()
      Returns:
      The prefix tree of all leading operators, including unary operators and functions
    • getBinaryOperators

      public CharTree<BinaryOperator> getBinaryOperators()
      Returns:
      The prefix tree of all binary operators
    • getValues

      public CharTree<Value> getValues()
      Returns:
      The prefix tree of all values, including constants, variables, and lazy variables
    • getVariableCount

      public int getVariableCount()
      Returns:
      The number of variables in this expression environment