Class FormulaInterpreter

java.lang.Object
xal.tools.formula.FormulaInterpreter

public final class FormulaInterpreter extends Object
FormulaInterpreter is a class used to evaluate a formula with a given set of variables provided by the user.
Author:
tap
  • Constructor Details

    • FormulaInterpreter

      public FormulaInterpreter()
      Creates a new instance of FormulaInterpreter
  • Method Details

    • setVariable

      public final void setVariable(String name, double value)
      Set the named variable to the specified value. Overrides the previous value (if any) of the variable.
      Parameters:
      name - name of the variable
      value - value assigned to the variable
    • hasVariable

      public final boolean hasVariable(String name)
      Determine if a variable of the specified name exists and has been assigned a value.
      Parameters:
      name - The name of the variable for which to check.
      Returns:
      true if the variable exists; false otherwise.
    • compile

      public void compile(String formula)
      compile the specified formula
    • evaluate

      public double evaluate(String formula)
      Compile and evaluate the specified formula.
      Returns:
      The result of evaluating the formula with the present variable values.
    • evaluate

      public double evaluate()
      evaluate the compiled formula