
Formula 1.0.0  
PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
Object hirondelle.formula.Formula
public final class Formula
Evaluate a mathematical formula.
If any variables are present in the formula, then they must all be assigned a value before the formula can be successfully evaluated.
If any custom functions are present in the formula, then they must all be defined before the formula can be successfully evaluated.
Constructor Summary  

Formula(String aFormula)
Constructor for the simplest case. 

Formula(String aFormula,
Map<String,Decimal> aVariableValues)
Constructor for a formula containing variables. 

Formula(String aFormula,
Map<String,Decimal> aVariableValues,
Map<String,Function> aCustomFunctions)
Full constructor, taking all possible parameters. 
Method Summary  

Decimal 
getAnswer()
Evaluate the formula, and return the answer as a number. 
Map<String,Function> 
getCustomFunctions()
Return the Map of custom functions passed to the constructor, if any. 
static Map<String,Function> 
getDefaultFunctions()
Return all builtin functions, in a mutable Map, whose key is the name of the function as it appears in a formula. 
String 
getFormula()
Return the text of the formula passed to the constructor. 
List<String> 
getFunctionNames()
Return the names of all functions appearing in the formula, if any. 
List<String> 
getUnknownFunctionNames()
Return the names of all functions appearing in the formula which aren't recognized, if any. 
List<String> 
getUnpopulatedVariableNames()
Return the names of all variables appearing in the formula which aren't populated, if any. 
List<String> 
getVariableNames()
Return the names of all variables appearing in the formula, if any. 
Map<String,Decimal> 
getVariableValues()
Return the Map of variable values passed to the constructor, if any. 
boolean 
hasUnknownFunctionNames()
Return true only if the formula has at least one unknown function name. 
boolean 
hasUnpopulatedVariables()
Return true only if the formula has at least one variable which has not been populated. 
boolean 
hasVariables()
Return true only if the formula has at least one variable. 
Methods inherited from class Object 

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 
Constructor Detail 

public Formula(String aFormula)
As in the full constructor, but using an empty Map for the variables, and the default builtin functions. This constructor can only be used when there are no variables in the formula.
public Formula(String aFormula, Map<String,Decimal> aVariableValues)
public Formula(String aFormula, Map<String,Decimal> aVariableValues, Map<String,Function> aCustomFunctions)
aFormula
 the text of the formula; must have content; if the formula contains references to variables,
then values for all of those variables must be supplied in aVariableValuesaVariableValues
 maps all variable names to their corresponding values; possibly empty.aCustomFunctions
 maps all possible function names to their corresponding implementations of the Function
interface. Typically, callers will build this parameter by starting with getDefaultFunctions()
, and altering its return value.Method Detail 

public static Map<String,Function> getDefaultFunctions()
The caller can alter the returned Map, and then pass the new Map to a constructor of this class. This allows you to add to the builtin functions, and even customize/replace the builtin functions themselves. In general, you may take the return value and :
public String getFormula()
public Map<String,Decimal> getVariableValues()
Decimal
value. May return an empty Map.
public Map<String,Function> getCustomFunctions()
Function
object. May return an empty Map.
public boolean hasVariables()
public boolean hasUnpopulatedVariables()
public List<String> getVariableNames()
public List<String> getUnpopulatedVariableNames()
public List<String> getFunctionNames()
public boolean hasUnknownFunctionNames()
public List<String> getUnknownFunctionNames()
public Decimal getAnswer() throws MalformedFormulaException
UnpopulatedVariableException
 if there are one or more variables in the formula that are
not in the Map of variable values passed to the constructor.
UnknownFunctionException
 if there are one or more function names in the formula that are
not in the Map of functions passed to the constructor.
MalformedFormulaException

Formula 1.0.0  
PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 