com.accountingenhancements.formula
Class FormulaVariableList

java.lang.Object
  extended by com.accountingenhancements.formula.FormulaVariableList

public class FormulaVariableList
extends java.lang.Object

Manage a list of FormulaVariables. Variables with the highest levels replace variables with lower levels. When higher levels are removed, the lower levels by the same name return in scope.
This list treats all variable names as ignore-case.


Field Summary
protected  int highestLevel
           
protected  java.util.ArrayList<FormulaVariable> variableArray
           
protected  java.util.HashMap<java.lang.String,FormulaVariable> variableList
           
 
Constructor Summary
FormulaVariableList()
          Creates a new instance of FormulaVariableList
 
Method Summary
 FormulaVariable addValue(java.lang.String variableName, java.math.BigDecimal value)
          Add a value to the variable list.
 FormulaVariable addValue(java.lang.String variableName, java.math.BigDecimal value, int scale)
          Add a value to the variable list.
 FormulaVariable addValue(java.lang.String variableName, java.math.BigDecimal value, int scale, int level)
          Add a value to the variable list.
 FormulaVariable addValue(java.lang.String variableName, boolean value)
          Add a value to the variable list.
 FormulaVariable addValue(java.lang.String variableName, boolean value, int scale)
          Add a value to the variable list.
 FormulaVariable addValue(java.lang.String variableName, boolean value, int scale, int level)
          Add a value to the variable list.
 FormulaVariable addValue(java.lang.String variableName, java.util.Date value)
          Add a value to the variable list.
 FormulaVariable addValue(java.lang.String variableName, java.util.Date value, int level)
          Add a value to the variable list.
 FormulaVariable addValue(java.lang.String variableName, double value)
          Add a value to the variable list.
 FormulaVariable addValue(java.lang.String variableName, double value, int scale)
          Add a value to the variable list.
 FormulaVariable addValue(java.lang.String variableName, double value, int scale, int level)
          Add a value to the variable list.
 FormulaVariable addValue(java.lang.String variableName, long value)
          Add a value to the variable list.
 FormulaVariable addValue(java.lang.String variableName, long value, int level)
          Add a value to the variable list.
 FormulaVariable addValue(java.lang.String variableName, java.lang.String value)
          Add a value to the variable list.
 FormulaVariable addValue(java.lang.String variableName, java.lang.String value, boolean treatUnquotedTextAsFormulas)
          Add a value to the variable list.
 FormulaVariable addValue(java.lang.String variableName, java.lang.String value, int level)
          Add a value to the variable list.
 FormulaVariable addValue(java.lang.String variableName, java.lang.String value, int level, boolean treatUnquotedTextAsFormulas)
          Add a value to the variable list.
 FormulaVariable addValue(java.lang.String variableName, java.lang.String value, int scaleIfDouble, int level, boolean treatUnquotedTextAsFormulas)
          Add a value to the variable list.
 FormulaVariable addVariable(FormulaVariable variable)
          Add a variable to the list.
 FormulaVariable addVariable(java.lang.String variable)
          Add a variable where the variable name is part of the string.
 FormulaVariable addVariable(java.lang.String variable, int level)
          Add a variable where the variable name is part of the string.
 FormulaVariableStack addVariables(java.lang.String variables)
          Add a semi-colon separated list of variables in the order, variable name, equals sign, value, semi-colon, etc...
 FormulaVariableStack addVariables(java.lang.String variables, int level)
          Add a semi-colon separated list of variables in the order, variable name, equals sign, value, semi-colon, etc...
protected  FormulaVariable addVariableToList(FormulaVariable variable)
          Adds the specified variable to the HashMap.
 java.math.BigDecimal getBigDecimal(java.lang.String variableName)
           
 java.lang.Boolean getBoolean(java.lang.String variableName)
           
 java.util.Date getDate(java.lang.String variableName)
           
 java.lang.Double getDouble(java.lang.String variableName)
           
 java.lang.Long getLong(java.lang.String variableName)
           
 java.lang.String getString(java.lang.String variableName)
           
 FormulaVariable getVariable(java.lang.String variableName)
           
 int getVariableType(java.lang.String variableName)
           
protected  void rebuildVariableList()
          Rebuild the HashMap to make sure that the variables returned have the highest levels when names are shared.
 void removeLevel(int level)
           
 void removeVariable(FormulaVariable variable)
           
 void removeVariable(java.lang.String variableName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

variableList

protected java.util.HashMap<java.lang.String,FormulaVariable> variableList

variableArray

protected java.util.ArrayList<FormulaVariable> variableArray

highestLevel

protected int highestLevel
Constructor Detail

FormulaVariableList

public FormulaVariableList()
Creates a new instance of FormulaVariableList

Method Detail

getVariable

public FormulaVariable getVariable(java.lang.String variableName)
Returns:
the FormulaVariable class that is stored under assigned name, null if not found

addVariables

public FormulaVariableStack addVariables(java.lang.String variables)
                                  throws java.text.ParseException
Add a semi-colon separated list of variables in the order, variable name, equals sign, value, semi-colon, etc...

Parameters:
variables - a semi-colon. Example: addVariables("Var1=A+B;Var2=\"Hi There\"");
Returns:
a stack containing the variables that were added to the variable list.
Throws:
java.text.ParseException

addVariables

public FormulaVariableStack addVariables(java.lang.String variables,
                                         int level)
                                  throws java.text.ParseException
Add a semi-colon separated list of variables in the order, variable name, equals sign, value, semi-colon, etc...

Parameters:
variables - a semi-colon. Example: addVariables("Var1=A+B;Var2=\"Hi There\"",2);
level - the volatility of the variable.
Returns:
a stack containing the variables that were added to the variable list.
Throws:
java.text.ParseException

addVariable

public FormulaVariable addVariable(java.lang.String variable)
                            throws java.text.ParseException
Add a variable where the variable name is part of the string.

Parameters:
variable - variable name and value. Example: addVariable("Var1=A+B");
Returns:
the variable that was added.
Throws:
java.text.ParseException

addVariable

public FormulaVariable addVariable(java.lang.String variable,
                                   int level)
                            throws java.text.ParseException
Add a variable where the variable name is part of the string.

Parameters:
variable - variable name and value. Example: addVariable("Var1=A+B",1);
level - the volatility of the variable.
Returns:
the variable that was added.
Throws:
java.text.ParseException

addVariable

public FormulaVariable addVariable(FormulaVariable variable)
Add a variable to the list.

Parameters:
variable - the variable that is to be assigned to the list.
Returns:
variable the variable for chaining purposes.

addVariableToList

protected FormulaVariable addVariableToList(FormulaVariable variable)
Adds the specified variable to the HashMap. Makes sure not to replace variable names with higher levels.

Parameters:
variable - the variable to be added to the HashMap.
Returns:
variable if successful. If variable not replaced then null returned

addValue

public FormulaVariable addValue(java.lang.String variableName,
                                java.lang.String value,
                                int level)
Add a value to the variable list.

Parameters:
variableName - the name to be assigned to the variable that is to be created.
value - the value that is assigned to the new variable. FormulaVariable will automatically try to determine whether this data represents a TYPE_STRING, TYPE_DOUBLE, TYPE_LONG, or TYPE_DATE.
level - the level of the variable. When variables share the same name (not case sensitive), the highest level is returned.
Returns:
variable the variable for chaining purposes.

addValue

public FormulaVariable addValue(java.lang.String variableName,
                                java.lang.String value,
                                int level,
                                boolean treatUnquotedTextAsFormulas)
Add a value to the variable list.

Parameters:
variableName - the name to be assigned to the variable that is to be created.
value - the value that is assigned to the new variable. FormulaVariable will automatically try to determine whether this data represents a TYPE_STRING, TYPE_DOUBLE, TYPE_LONG, or TYPE_DATE.
level - the level of the variable. When variables share the same name (not case sensitive), the highest level is returned.
treatUnquotedTextAsFormulas - If true then if the variable value has beginning and ending quotes, they will be removed and the variable will be of TYPE_STRING, If unquoted only made up of letters, numbers, and underscores with no spaces, then the variable type will be TYPE_VARIABLE, else the variable type will be TYPE_FORMULA, or TYPE_FUNCTION.
If treatUnquotedTextAsFormula is false then the variable type will be TYPE_STRING if it is determined not to be TYPE_LONG, TYPE_BOOLEAN, or TYPE_DOUBLE and the value will be left as-is (no quotes removed).
Returns:
variable the variable for chaining purposes.

addValue

public FormulaVariable addValue(java.lang.String variableName,
                                java.lang.String value,
                                int scaleIfDouble,
                                int level,
                                boolean treatUnquotedTextAsFormulas)
Add a value to the variable list.

Parameters:
variableName - the name to be assigned to the variable that is to be created.
value - the value that is assigned to the new variable. FormulaVariable will automatically try to determine whether this data represents a TYPE_STRING, TYPE_DOUBLE, TYPE_LONG, or TYPE_DATE.
scaleIfDouble - the scale of a number
level - the level of the variable. When variables share the same name (not case sensitive), the highest level is returned.
treatUnquotedTextAsFormulas - If true then if the variable value has beginning and ending quotes, they will be removed and the variable will be of TYPE_STRING, If unquoted only made up of letters, numbers, and underscores with no spaces, then the variable type will be TYPE_VARIABLE, else the variable type will be TYPE_FORMULA, or TYPE_FUNCTION.
If treatUnquotedTextAsFormula is false then the variable type will be TYPE_STRING if it is determined not to be TYPE_LONG, TYPE_BOOLEAN, or TYPE_DOUBLE and the value will be left as-is (no quotes removed).
Returns:
variable the variable for chaining purposes.

addValue

public FormulaVariable addValue(java.lang.String variableName,
                                long value,
                                int level)
Add a value to the variable list.

Parameters:
variableName - the name to be assigned to the variable that is to be created.
value - the value that is assigned to the new variable.
level - the level of the variable. When variables share the same name (not case sensitive), the highest level is returned.
Returns:
variable the variable for chaining purposes.

addValue

public FormulaVariable addValue(java.lang.String variableName,
                                java.util.Date value,
                                int level)
Add a value to the variable list.

Parameters:
variableName - the name to be assigned to the variable that is to be created.
value - the value that is assigned to the new variable.
level - the level of the variable. When variables share the same name (not case sensitive), the highest level is returned.
Returns:
variable the variable for chaining purposes.

addValue

public FormulaVariable addValue(java.lang.String variableName,
                                double value,
                                int scale,
                                int level)
Add a value to the variable list.

Parameters:
variableName - the name to be assigned to the variable that is to be created.
value - the value that is assigned to the new variable.
scale - the scale of a number
level - the level of the variable. When variables share the same name (not case sensitive), the highest level is returned.
Returns:
variable the variable for chaining purposes.

addValue

public FormulaVariable addValue(java.lang.String variableName,
                                java.math.BigDecimal value,
                                int scale,
                                int level)
Add a value to the variable list.

Parameters:
variableName - the name to be assigned to the variable that is to be created.
value - the value that is assigned to the new variable.
scale - the scale of a number
level - the level of the variable. When variables share the same name (not case sensitive), the highest level is returned.
Returns:
variable the variable for chaining purposes.

addValue

public FormulaVariable addValue(java.lang.String variableName,
                                boolean value,
                                int scale,
                                int level)
Add a value to the variable list.

Parameters:
variableName - the name to be assigned to the variable that is to be created.
value - the value that is assigned to the new variable.
scale - the scale of a number if TYPE_DOUBLE or the sensitivity of a true/false test against a double if TYPE_BOOLEAN.
level - the level of the variable. When variables share the same name (not case sensitive), the highest level is returned.
Returns:
variable the variable for chaining purposes.

addValue

public FormulaVariable addValue(java.lang.String variableName,
                                java.lang.String value)
Add a value to the variable list. The level assigned to the newly created variable will be the highest active level.

Parameters:
variableName - the name to be assigned to the variable that is to be created.
value - the value that is assigned to the new variable.
Returns:
variable the variable for chaining purposes.

addValue

public FormulaVariable addValue(java.lang.String variableName,
                                java.lang.String value,
                                boolean treatUnquotedTextAsFormulas)
Add a value to the variable list. The level assigned to the newly created variable will be the highest active level.

Parameters:
variableName - the name to be assigned to the variable that is to be created.
value - the value that is assigned to the new variable.
treatUnquotedTextAsFormulas - If true then if the variable value has beginning and ending quotes, they will be removed and the variable will be of TYPE_STRING, If unquoted only made up of letters, numbers, and underscores with no spaces, then the variable type will be TYPE_VARIABLE, else the variable type will be TYPE_FORMULA or TYPE_FUNCTION.
If treatUnquotedTextAsFormula is false then the variable type will be TYPE_STRING if it is determined not to be TYPE_LONG, TYPE_BOOLEAN, or TYPE_DOUBLE and the value will be left as-is (no quotes removed).
Returns:
variable the variable for chaining purposes.

addValue

public FormulaVariable addValue(java.lang.String variableName,
                                long value)
Add a value to the variable list. The level assigned to the newly created variable will be the highest active level.

Parameters:
variableName - the name to be assigned to the variable that is to be created.
value - the value that is assigned to the new variable.
Returns:
variable the variable for chaining purposes.

addValue

public FormulaVariable addValue(java.lang.String variableName,
                                java.util.Date value)
Add a value to the variable list. The level assigned to the newly created variable will be the highest active level.

Parameters:
variableName - the name to be assigned to the variable that is to be created.
value - the value that is assigned to the new variable.
Returns:
variable the variable for chaining purposes.

addValue

public FormulaVariable addValue(java.lang.String variableName,
                                double value)
Add a value to the variable list. The level assigned to the newly created variable will be the highest active level.

Parameters:
variableName - the name to be assigned to the variable that is to be created.
value - the value that is assigned to the new variable.
Returns:
variable the variable for chaining purposes.

addValue

public FormulaVariable addValue(java.lang.String variableName,
                                double value,
                                int scale)
Add a value to the variable list. The level assigned to the newly created variable will be the highest active level.

Parameters:
variableName - the name to be assigned to the variable that is to be created.
value - the value that is assigned to the new variable.
scale - the scale of a number
Returns:
variable the variable for chaining purposes.

addValue

public FormulaVariable addValue(java.lang.String variableName,
                                java.math.BigDecimal value)
Add a value to the variable list. The level assigned to the newly created variable will be the highest active level.

Parameters:
variableName - the name to be assigned to the variable that is to be created.
value - the value that is assigned to the new variable.
Returns:
variable the variable for chaining purposes.

addValue

public FormulaVariable addValue(java.lang.String variableName,
                                java.math.BigDecimal value,
                                int scale)
Add a value to the variable list. The level assigned to the newly created variable will be the highest active level.

Parameters:
variableName - the name to be assigned to the variable that is to be created.
value - the value that is assigned to the new variable.
scale - the scale of a number
Returns:
variable the variable for chaining purposes.

addValue

public FormulaVariable addValue(java.lang.String variableName,
                                boolean value)
Add a value to the variable list. The level assigned to the newly created variable will be the highest active level.

Parameters:
variableName - the name to be assigned to the variable that is to be created.
value - the value that is assigned to the new variable.
Returns:
variable the variable for chaining purposes.

addValue

public FormulaVariable addValue(java.lang.String variableName,
                                boolean value,
                                int scale)
Add a value to the variable list. The level assigned to the newly created variable will be the highest active level.

Parameters:
variableName - the name to be assigned to the variable that is to be created.
value - the value that is assigned to the new variable.
scale - the scale of a number if TYPE_DOUBLE or the sensitivity of a true/false test against a double if TYPE_BOOLEAN.
Returns:
variable the variable for chaining purposes.

getString

public java.lang.String getString(java.lang.String variableName)
Parameters:
variableName - the name of the variable whose value is to be returned. Note: The name is not case sensitive.
Returns:
the value assigned to the variable who's name matches the requested name.

getLong

public java.lang.Long getLong(java.lang.String variableName)
Parameters:
variableName - the name of the variable whose value is to be returned. Note: The name is not case sensitive.
Returns:
the value assigned to the variable who's name matches the requested name.

getDouble

public java.lang.Double getDouble(java.lang.String variableName)
Parameters:
variableName - the name of the variable whose value is to be returned. Note: The name is not case sensitive.
Returns:
the value assigned to the variable who's name matches the requested name.

getBoolean

public java.lang.Boolean getBoolean(java.lang.String variableName)
Parameters:
variableName - the name of the variable whose value is to be returned. Note: The name is not case sensitive.
Returns:
the value assigned to the variable who's name matches the requested name.

getBigDecimal

public java.math.BigDecimal getBigDecimal(java.lang.String variableName)
Parameters:
variableName - the name of the variable whose value is to be returned. Note: The name is not case sensitive.
Returns:
the value assigned to the variable who's name matches the requested name.

getDate

public java.util.Date getDate(java.lang.String variableName)
                       throws java.text.ParseException
Parameters:
variableName - the name of the variable whose value is to be returned. Note: The name is not case sensitive.
Returns:
the value assigned to the variable who's name matches the requested name.
Throws:
java.text.ParseException - if variable value can't be converted to a Date.

getVariableType

public int getVariableType(java.lang.String variableName)
Parameters:
variableName - the name of the variable whose value is to be returned. Note: The name is not case sensitive.
Returns:
the variable type, String, Integer, Double, or Boolean.

removeVariable

public void removeVariable(FormulaVariable variable)
Parameters:
variable - remove the specified variable.

removeVariable

public void removeVariable(java.lang.String variableName)
Parameters:
variableName - the name of the variable to be removed. Not case sensitive. If more than one variable by the same name, then the one with the highest level is remove.

removeLevel

public void removeLevel(int level)
Parameters:
level - the level to be removed from the variable list. Note: All higher levels are removed as well. Removing level 0 clears everything unless you've been using negative numbers.

rebuildVariableList

protected void rebuildVariableList()
Rebuild the HashMap to make sure that the variables returned have the highest levels when names are shared. This method is executed by the various remove methods.