Package xal.tools.formula
Class FormulaInterpreter
java.lang.Object
xal.tools.formula.FormulaInterpreter
FormulaInterpreter is a class used to evaluate a formula with a given set of
variables provided by the user.
- Author:
- tap
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
compile the specified formuladouble
evaluate()
evaluate the compiled formuladouble
Compile and evaluate the specified formula.final boolean
hasVariable
(String name) Determine if a variable of the specified name exists and has been assigned a value.final void
setVariable
(String name, double value) Set the named variable to the specified value.
-
Constructor Details
-
FormulaInterpreter
public FormulaInterpreter()Creates a new instance of FormulaInterpreter
-
-
Method Details
-
setVariable
Set the named variable to the specified value. Overrides the previous value (if any) of the variable.- Parameters:
name
- name of the variablevalue
- value assigned to the variable
-
hasVariable
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
compile the specified formula -
evaluate
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
-