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 TypeMethodDescriptionvoidcompile the specified formuladoubleevaluate()evaluate the compiled formuladoubleCompile and evaluate the specified formula.final booleanhasVariable(String name) Determine if a variable of the specified name exists and has been assigned a value.final voidsetVariable(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
-