|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.accountingenhancements.formula.FormulaVariable
public class FormulaVariable
FormulaVariable
is used to store variables and mathematical operators. An instance can only be one or the other.
It is used be FormulaVariableList
and FormulaVariableStack
.
A formula variable that may, or may not, be set.
The variable is stored as a String. and supports return types of String, Long, Double, and Boolean.
If the variable type is boolean and it is being set as a long or boolean type, then 0(+/-.49) = false, non-zero = true.
If the variable type is long then a double is truncated.
If the variable type is Formula then the string should be processed with Formula.solve() to retrieve result which may be String, Long, Double, or Boolean.
Field Summary | |
---|---|
protected FormulaFunction |
formulaFunction
If this is TYPE_FUNCTION then this is the function that was created when first solving this variable. |
protected int |
highestLevel
If this is TYPE_FORMULA, TYPE_FUNCTION, or TYPE_VARIABLE then this reflects the highest level of variable used in solving for resolvedVariable |
static boolean[] |
IS_COMPARATOR_OPERATOR
boolean array used to determine whether a TYPE is a comparator operator (!=, >, >=, =, <=, <). |
static boolean[] |
IS_UNARY_OPERATOR
boolean array used to determine whether a TYPE is a unary operator. |
protected int |
level
|
static java.lang.String |
OPERATOR_STRING
|
protected int |
precision
|
protected FormulaVariable |
resolvedVariable
If this is TYPE_VARIABLE then this is the value of the resultant value. |
protected int |
scale
|
protected FormulaVariableStack |
stack
If this is TYPE_FORMULA then this is the stack of the formula as processed by FormulaVariableSack |
protected boolean |
stripSurroundingQuotesFromStrings
|
protected boolean |
treatUnquotedTextAsFormulas
|
static int |
TYPE_BOOLEAN
Value is of type Boolean |
static int |
TYPE_DATE
Value is of type Date |
static int |
TYPE_DOUBLE
Value is of type Double |
static int |
TYPE_FORMULA
Value is of type Formula where formula should be run through Formula.solve() |
static int |
TYPE_FUNCTION
Value is of type Function where this should be solved through the function processing methods |
static int |
TYPE_LONG
Value is of type Long |
static int |
TYPE_NOTHING
Undefined variable. |
static int |
TYPE_OPERATOR_AND
Test previous object for non-zero versus zero. |
static int |
TYPE_OPERATOR_BIT_AND
Apply a bitwise And of previous object against the next object |
static int |
TYPE_OPERATOR_BIT_OR
Apply a bitwise Or of previous object against the next object |
static int |
TYPE_OPERATOR_BIT_XOR
Apply a bitwise Xor of previous object against the next object |
static int |
TYPE_OPERATOR_DIVIDE
Divide previous object by next object |
static int |
TYPE_OPERATOR_EQUALS
Compare previous object to next object for identical values, return 1 if true, 0 if false |
static int |
TYPE_OPERATOR_GREATER_THAN
Compare previous object to next object for whether previous object is greater than next object, return 1 if true, 0 if false |
static int |
TYPE_OPERATOR_GREATER_THAN_OR_EQUAL
Compare previous object to next object for whether previous object is greater than or equal to next object, return 1 if true, 0 if false |
static int |
TYPE_OPERATOR_LESS_THAN
Compare previous object to next object for whether previous object is less than next object, return 1 if true, 0 if false |
static int |
TYPE_OPERATOR_LESS_THAN_OR_EQUAL
Compare previous object to next object for whether previous object is less than or equal to next object, return 1 if true, 0 if false |
static int |
TYPE_OPERATOR_MINUS
subtract next object from previous object. |
static int |
TYPE_OPERATOR_MODULUS
Return Remainder of division of previous object by next object. |
static int |
TYPE_OPERATOR_MULTIPLY
Multiply next object by previous object |
static int |
TYPE_OPERATOR_NOT_EQUAL
Compare previous object to next object for non-identical values, return 1 if true, 0 if false |
static int |
TYPE_OPERATOR_OR
Test previous object for non-zero versus zero. |
static int |
TYPE_OPERATOR_PLUS
Add next object to previous object. |
static int |
TYPE_OPERATOR_UNARY_BIT_NOT
Unary Bitwise Not (~) to be applied to next object. |
static int |
TYPE_OPERATOR_UNARY_NOT
Unary Not (!) logical Not to be applied to next object (0=1, non-zero=0) |
static int |
TYPE_STRING
Value is of type String |
static java.lang.String[] |
TYPE_TO_STRING_ARRAY
Return the String form of TYPE_ |
static int |
TYPE_VARIABLE
Value is of type Variable where this variable references another variable and should be resolved through a FormulaVariableList |
protected java.lang.String |
variableName
|
protected int |
variableType
|
protected java.lang.String |
variableValue
|
Constructor Summary | |
---|---|
protected |
FormulaVariable()
Blank FormulaVariable. |
|
FormulaVariable(int variableType)
Creates a new instance of FormulaVariable |
|
FormulaVariable(int variableType,
int level)
Creates a new instance of FormulaVariable |
|
FormulaVariable(int variableType,
int level,
boolean stripSurroundingQuotesFromStrings)
Creates a new instance of FormulaVariable |
|
FormulaVariable(java.lang.String variable)
This constructor pulls the variable name from the first part of the String and the value from the last part. |
|
FormulaVariable(java.lang.String variableName,
java.math.BigDecimal variableValue,
int level)
Creates a new instance of FormulaVariable Tries to determine type of variable based on contents of value. |
|
FormulaVariable(java.lang.String variableName,
java.math.BigDecimal variableValue,
int scale,
int level)
Creates a new instance of FormulaVariable Tries to determine type of variable based on contents of value. |
|
FormulaVariable(java.lang.String variableName,
java.math.BigDecimal variableValue,
int variableType,
int scaleIfDouble,
int level)
Creates a new instance of FormulaVariable |
|
FormulaVariable(java.lang.String variableName,
boolean variableValue,
int level)
Creates a new instance of FormulaVariable. |
|
FormulaVariable(java.lang.String variableName,
boolean variableValue,
int scale,
int level)
Creates a new instance of FormulaVariable. |
|
FormulaVariable(java.lang.String variableName,
boolean variableValue,
int variableType,
int scaleIfDouble,
int level)
Creates a new instance of FormulaVariable |
|
FormulaVariable(java.lang.String variableName,
java.util.Date variableValue,
int level)
Creates a new instance of FormulaVariable Tries to determine type of variable based on contents of value. |
|
FormulaVariable(java.lang.String variableName,
java.util.Date variableValue,
int variableType,
int scaleIfDouble,
int level)
Creates a new instance of FormulaVariable |
|
FormulaVariable(java.lang.String variableName,
double variableValue,
int level)
Creates a new instance of FormulaVariable. |
|
FormulaVariable(java.lang.String variableName,
double variableValue,
int scale,
int level)
Creates a new instance of FormulaVariable. |
|
FormulaVariable(java.lang.String variableName,
double variableValue,
int variableType,
int scaleIfDouble,
int level)
Creates a new instance of FormulaVariable |
|
FormulaVariable(java.lang.String variable,
int level)
This constructor pulls the variable name from the first part of the String and the value from the last part. |
|
FormulaVariable(java.lang.String variableName,
int variableType,
int level)
Creates a new instance of FormulaVariable |
|
FormulaVariable(java.lang.String variableName,
int variableType,
int level,
boolean stripSurroundingQuotesFromStrings)
Creates a new instance of FormulaVariable |
|
FormulaVariable(java.lang.String variableName,
int variableType,
int scaleIfDouble,
int level)
Creates a new instance of FormulaVariable |
|
FormulaVariable(java.lang.String variableName,
long variableValue,
int level)
Creates a new instance of FormulaVariable Tries to determine type of variable based on contents of value. |
|
FormulaVariable(java.lang.String variableName,
long variableValue,
int variableType,
int scaleIfDouble,
int level)
Creates a new instance of FormulaVariable |
|
FormulaVariable(java.lang.String variableName,
java.lang.String variableValue,
int level)
Creates a new instance of FormulaVariable. |
|
FormulaVariable(java.lang.String variableName,
java.lang.String variableValue,
int level,
boolean treatUnquotedTextAsFormulas)
Creates a new instance of FormulaVariable Tries to determine type of variable based on contents of value. |
|
FormulaVariable(java.lang.String variableName,
java.lang.String variableValue,
int scaleIfDouble,
int level,
boolean treatUnquotedTextAsFormulas)
Creates a new instance of FormulaVariable Tries to determine type of variable based on contents of value. |
|
FormulaVariable(java.lang.String variableName,
java.lang.String variableValue,
int variableType,
int scaleIfDouble,
int level)
Creates a new instance of FormulaVariable |
Method Summary | |
---|---|
protected boolean |
booleanValue(java.lang.String value)
|
FormulaVariable |
clone()
|
static int |
detectVariableType(java.lang.String variableValue,
boolean treatUnquotedTextAsFormulas)
|
static int |
findOperatorPrecedence(java.lang.String operator)
Find the operator precedence of an operator that is handed to this method. |
static int |
findScaleOfDouble(java.lang.String variableValue)
If variableValue is known to contain an integer or double then what is the scale (integer would be scale=0). |
java.math.BigDecimal |
getBigDecimal()
|
java.math.BigDecimal |
getBigDecimalScaled()
|
boolean |
getBoolean()
|
java.util.Date |
getDate()
|
java.lang.Double |
getDouble()
|
int |
getHighestLevel()
|
int |
getLevel()
|
java.lang.Long |
getLong()
|
int |
getOperator()
|
int |
getPrecision()
|
int |
getScale()
|
java.lang.String |
getString()
|
boolean |
getStripSurroundingQuotesFromStrings()
|
java.lang.Object |
getValue()
|
java.lang.String |
getVariableName()
|
int |
getVariableType()
|
boolean |
isComparatorOperator()
|
boolean |
isNonUnaryOperator()
|
boolean |
isNull()
|
boolean |
isOperator()
|
boolean |
isUnaryOperator()
|
protected static java.lang.String |
padString(java.lang.String orgString,
int size,
char padChar,
boolean padOnLeft)
Pad a string with repeating characters such that the final string is size long.Examples: padString("12",5,'0',true).equals("00012")==true padString("Hi",4,' ',false).equals("Hi ")==true |
void |
purgeResultsGreaterThanSpecifiedLevel(int specifiedLevel)
If the result of a calculation used a value above the specified level, then purge the answer. |
void |
setHighestLevel(int highestLevel)
|
void |
setPrecision(int precision)
|
void |
setScale(int scale)
|
void |
setStripSurroundingQuotesFromStrings(boolean state)
|
void |
setValue(java.math.BigDecimal value)
|
void |
setValue(java.math.BigDecimal value,
int scale)
This method updates the scale value then executes setValue(BigDecimal value) |
void |
setValue(boolean value)
|
void |
setValue(java.util.Date value)
|
void |
setValue(double value)
|
void |
setValue(double value,
int scale)
This method updates the scale value then executes setValue(double value) |
void |
setValue(long value)
|
void |
setValue(java.lang.String value)
|
FormulaVariable |
solve(FormulaVariableList variableList,
int iteration,
SupportParameters supportParameters,
FormulaFunctionList functionList,
int resolveEverythingAboveLevel)
IF this variable is of TYPE_FORMULA, TYPE_FUNCTION, or TYPE_VARIABLE then this method solves for the value. |
static boolean |
testIsComparatorOperator(int operator)
|
static boolean |
testIsOperator(char operator)
Test whether a character is part of an operator. |
static boolean |
testIsOperator(int operator)
Test whether a specified TYPE is an operator. |
static boolean |
testIsOperator(java.lang.String operator)
Test whether a string segment is an operator. |
static boolean |
testIsUnaryOperator(int operator)
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.lang.String variableName
protected java.lang.String variableValue
protected int variableType
protected int level
protected int scale
protected int precision
protected boolean treatUnquotedTextAsFormulas
protected boolean stripSurroundingQuotesFromStrings
protected FormulaVariableStack stack
protected FormulaVariable resolvedVariable
protected int highestLevel
protected FormulaFunction formulaFunction
public static final int TYPE_NOTHING
public static final int TYPE_STRING
public static final int TYPE_LONG
public static final int TYPE_DOUBLE
public static final int TYPE_BOOLEAN
public static final int TYPE_FORMULA
public static final int TYPE_VARIABLE
public static final int TYPE_DATE
public static final int TYPE_FUNCTION
public static final int TYPE_OPERATOR_UNARY_BIT_NOT
public static final int TYPE_OPERATOR_UNARY_NOT
public static final int TYPE_OPERATOR_EQUALS
public static final int TYPE_OPERATOR_NOT_EQUAL
public static final int TYPE_OPERATOR_LESS_THAN_OR_EQUAL
public static final int TYPE_OPERATOR_LESS_THAN
public static final int TYPE_OPERATOR_GREATER_THAN_OR_EQUAL
public static final int TYPE_OPERATOR_GREATER_THAN
public static final int TYPE_OPERATOR_OR
public static final int TYPE_OPERATOR_AND
public static final int TYPE_OPERATOR_MULTIPLY
public static final int TYPE_OPERATOR_DIVIDE
public static final int TYPE_OPERATOR_MODULUS
public static final int TYPE_OPERATOR_BIT_AND
public static final int TYPE_OPERATOR_BIT_OR
public static final int TYPE_OPERATOR_BIT_XOR
public static final int TYPE_OPERATOR_PLUS
public static final int TYPE_OPERATOR_MINUS
public static final java.lang.String[] TYPE_TO_STRING_ARRAY
public static final java.lang.String OPERATOR_STRING
public static final boolean[] IS_UNARY_OPERATOR
public static final boolean[] IS_COMPARATOR_OPERATOR
Constructor Detail |
---|
protected FormulaVariable()
public FormulaVariable(java.lang.String variable) throws java.text.ParseException
variable
- the variable name, an equals sign, the value. Example: new FormulaVariable("testVar=\"Hi There\"). Unquoted text is treated as a formula. "testVar=A+B" is formula, "testVar=\"A+B\"" is text string.
java.text.ParseException
- is equal sign is missingpublic FormulaVariable(java.lang.String variable, int level) throws java.text.ParseException
variable
- the variable name, an equals sign, the value. Example: new FormulaVariable("testVar=\"Hi There\",1). Unquoted text is treated as a formula. "testVar=A+B" is formula, "testVar=\"A+B\"" is text string.level
- the level to be assigned to the variable.
java.text.ParseException
- is equal sign is missingpublic FormulaVariable(java.lang.String variableName, int variableType, int level)
variableName
- is used by the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.variableType
- is the type of operator. In this instance is intended for easy creation of operators and scaleIfDouble is set to 0.level
- is used when purging variables from the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.public FormulaVariable(java.lang.String variableName, int variableType, int level, boolean stripSurroundingQuotesFromStrings)
variableName
- is used by the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.variableType
- is the type of operator. In this instance is intended for easy creation of operators and scaleIfDouble is set to 0.level
- is used when purging variables from the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.stripSurroundingQuotesFromStrings
- causes setValue(String value) to strip surrounding quotespublic FormulaVariable(int variableType, int level)
variableType
- is the type of operator. In this instance is intended for easy creation of operators and scaleIfDouble is set to 0.level
- is used when purging variables from the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.public FormulaVariable(int variableType, int level, boolean stripSurroundingQuotesFromStrings)
variableType
- is the type of operator. In this instance is intended for easy creation of operators and scaleIfDouble is set to 0.level
- is used when purging variables from the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.stripSurroundingQuotesFromStrings
- causes setValue(String value) to strip surrounding quotespublic FormulaVariable(int variableType)
variableType
- is the type of operator. In this instance is intended for easy creation of operators. ScaleIfDouble and level are set to 0.public FormulaVariable(java.lang.String variableName, int variableType, int scaleIfDouble, int level)
variableName
- is used by the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.variableType
- is the type of variable or operator (TYPE_STRING, TYPE_OPERATOR_PLUS, etc..). If not an operator type then the value is null until setValue() is used.scaleIfDouble
- If variableType==TYPE_DOUBLE then this is the number of digits kept to the right of the decimal point before rounding. If Boolean and setValue(Double value) is used and this value sets the rounding sensitivity when determining true from false. newValue=Round(value*pow(10,scaleIfDouble).intValue)/pow(10,scaleIfDouble).intValue.level
- is used when purging variables from the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.public FormulaVariable(java.lang.String variableName, java.lang.String variableValue, int variableType, int scaleIfDouble, int level) throws java.lang.NumberFormatException
variableName
- is used by the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.variableValue
- the value of the varaible. It should match the variableType.variableType
- is the type of variable (TYPE_STRING, etc...). shouldn't be a TYPE_OPERATOR such as TYPE_OPERATOR_ADD, etc...scaleIfDouble
- If variableType==TYPE_DOUBLE then this is the number of digits kept to the right of the decimal point before rounding. If Boolean and setValue(Double value) is used and this value sets the rounding sensitivity when determining true from false. newValue=Round(value*pow(10,scaleIfDouble).intValue)/pow(10,scaleIfDouble).intValue.level
- is used when purging variables from the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.
java.lang.NumberFormatException
- if variableType wrong compared to variable value (As in variableType being of the TYPE_OPERATOR set).public FormulaVariable(java.lang.String variableName, long variableValue, int variableType, int scaleIfDouble, int level) throws java.lang.NumberFormatException
variableName
- is used by the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.variableValue
- the value of the varaible. It should match the variableType.variableType
- is the type of variable (TYPE_STRING, etc...). shouldn't be a TYPE_OPERATOR such as TYPE_OPERATOR_ADD, etc...scaleIfDouble
- If variableType==TYPE_DOUBLE then this is the number of digits kept to the right of the decimal point before rounding. If Boolean and setValue(Double value) is used and this value sets the rounding sensitivity when determining true from false. newValue=Round(value*pow(10,scaleIfDouble).intValue)/pow(10,scaleIfDouble).intValue.level
- is used when purging variables from the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.
java.lang.NumberFormatException
- if variableType wrong compared to variable value (As in variableType being of the TYPE_OPERATOR set).public FormulaVariable(java.lang.String variableName, double variableValue, int variableType, int scaleIfDouble, int level) throws java.lang.NumberFormatException
variableName
- is used by the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.variableValue
- the value of the varaible. It should match the variableType.variableType
- is the type of variable (TYPE_STRING, etc...). shouldn't be a TYPE_OPERATOR such as TYPE_OPERATOR_ADD, etc...scaleIfDouble
- If variableType==TYPE_DOUBLE then this is the number of digits kept to the right of the decimal point before rounding. If Boolean and setValue(Double value) is used and this value sets the rounding sensitivity when determining true from false. newValue=Round(value*pow(10,scaleIfDouble).intValue)/pow(10,scaleIfDouble).intValue.level
- is used when purging variables from the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.
java.lang.NumberFormatException
- if variableType wrong compared to variable value (As in variableType being of the TYPE_OPERATOR set).public FormulaVariable(java.lang.String variableName, boolean variableValue, int variableType, int scaleIfDouble, int level) throws java.lang.NumberFormatException
variableName
- is used by the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.variableValue
- the value of the varaible. It should match the variableType.variableType
- is the type of variable (TYPE_STRING, etc...). shouldn't be a TYPE_OPERATOR such as TYPE_OPERATOR_ADD, etc...scaleIfDouble
- If variableType==TYPE_DOUBLE then this is the number of digits kept to the right of the decimal point before rounding. If Boolean and setValue(Double value) is used and this value sets the rounding sensitivity when determining true from false. newValue=Round(value*pow(10,scaleIfDouble).intValue)/pow(10,scaleIfDouble).intValue.level
- is used when purging variables from the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.
java.lang.NumberFormatException
- if variableType wrong compared to variable value (As in variableType being of the TYPE_OPERATOR set).public FormulaVariable(java.lang.String variableName, java.util.Date variableValue, int variableType, int scaleIfDouble, int level) throws java.lang.NumberFormatException
variableName
- is used by the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.variableValue
- the value of the varaible. It should match the variableType.variableType
- is the type of variable (TYPE_STRING, etc...). shouldn't be a TYPE_OPERATOR such as TYPE_OPERATOR_ADD, etc...scaleIfDouble
- If variableType==TYPE_DOUBLE then this is the number of digits kept to the right of the decimal point before rounding. If Boolean and setValue(Double value) is used and this value sets the rounding sensitivity when determining true from false. newValue=Round(value*pow(10,scaleIfDouble).intValue)/pow(10,scaleIfDouble).intValue.level
- is used when purging variables from the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.
java.lang.NumberFormatException
- if variableType wrong compared to variable value (As in variableType being of the TYPE_OPERATOR set).public FormulaVariable(java.lang.String variableName, java.math.BigDecimal variableValue, int variableType, int scaleIfDouble, int level) throws java.lang.NumberFormatException
variableName
- is used by the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.variableValue
- the value of the varaible. It should match the variableType.variableType
- is the type of variable (TYPE_STRING, etc...). shouldn't be a TYPE_OPERATOR such as TYPE_OPERATOR_ADD, etc...scaleIfDouble
- If variableType==TYPE_DOUBLE then this is the number of digits kept to the right of the decimal point before rounding. If Boolean and setValue(Double value) is used and this value sets the rounding sensitivity when determining true from false. newValue=Round(value*pow(10,scaleIfDouble).intValue)/pow(10,scaleIfDouble).intValue.level
- is used when purging variables from the FormulaVariableList
and by the FormulaVariableStack
to determine whether various variables need to be resolved.
java.lang.NumberFormatException
- if variableType wrong compared to variable value (As in variableType being of the TYPE_OPERATOR set).public FormulaVariable(java.lang.String variableName, java.lang.String variableValue, int level)
variableName
- Needed by FormulaVariableList, but not by MathStack.variableValue
- the value of the variable. if numeric with a decimal point then Double, if numeric then Integer, if level
- Used by FormulaVariableList to determine when variable can be desposed. Not used by MathStack.public FormulaVariable(java.lang.String variableName, long variableValue, int level)
variableName
- Needed by FormulaVariableList, but not by MathStack.variableValue
- the value of the variable.level
- Used by FormulaVariableList to determine when variable can be desposed. Not used by MathStack.public FormulaVariable(java.lang.String variableName, double variableValue, int level)
variableName
- Needed by FormulaVariableList, but not by MathStack.variableValue
- the value of the variable.level
- Used by FormulaVariableList to determine when variable can be desposed. Not used by MathStack.public FormulaVariable(java.lang.String variableName, double variableValue, int scale, int level)
variableName
- Needed by FormulaVariableList, but not by MathStack.variableValue
- the value of the variable.scale
- This is the number of digits kept to the right of the decimal point before rounding.level
- Used by FormulaVariableList to determine when variable can be desposed. Not used by MathStack.public FormulaVariable(java.lang.String variableName, boolean variableValue, int level)
variableName
- Needed by FormulaVariableList, but not by MathStack.variableValue
- the value of the variable.level
- Used by FormulaVariableList to determine when variable can be desposed. Not used by MathStack.public FormulaVariable(java.lang.String variableName, boolean variableValue, int scale, int level)
variableName
- Needed by FormulaVariableList, but not by MathStack.variableValue
- the value of the variable.scale
- When Boolean and setValue(Double value) is used and this value sets the rounding sensitivity when determining true from false. newValue=Round(value*pow(10,scaleIfDouble).intValue)/pow(10,scaleIfDouble).intValue.level
- Used by FormulaVariableList to determine when variable can be desposed. Not used by MathStack.public FormulaVariable(java.lang.String variableName, java.util.Date variableValue, int level)
variableName
- Needed by FormulaVariableList, but not by MathStack.variableValue
- the value of the variable. if numeric with a decimal point then Double, if numeric then Integer, if level
- Used by FormulaVariableList to determine when variable can be desposed. Not used by MathStack.public FormulaVariable(java.lang.String variableName, java.math.BigDecimal variableValue, int level)
variableName
- Needed by FormulaVariableList, but not by MathStack.variableValue
- the value of the variable. if numeric with a decimal point then Double, if numeric then Integer, if level
- Used by FormulaVariableList to determine when variable can be desposed. Not used by MathStack.public FormulaVariable(java.lang.String variableName, java.math.BigDecimal variableValue, int scale, int level)
variableName
- Needed by FormulaVariableList, but not by MathStack.variableValue
- the value of the variable. if numeric with a decimal point then Double, if numeric then Integer, if scale
- This is the number of digits kept to the right of the decimal point before rounding.level
- Used by FormulaVariableList to determine when variable can be desposed. Not used by MathStack.public FormulaVariable(java.lang.String variableName, java.lang.String variableValue, int level, boolean treatUnquotedTextAsFormulas)
variableName
- Needed by FormulaVariableList, but not by MathStack.variableValue
- the value of the variable. if numeric with a decimal point then Double, if numeric then Integer, if level
- Used by FormulaVariableList to determine when variable can be desposed. Not used by MathStack.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.public FormulaVariable(java.lang.String variableName, java.lang.String variableValue, int scaleIfDouble, int level, boolean treatUnquotedTextAsFormulas)
variableName
- Needed by FormulaVariableList, but not by MathStack.variableValue
- the value of the variable. if numeric with a decimal point then Double, if numeric then Integer, if scaleIfDouble
- If variableType==TYPE_DOUBLE then this is the number of digits kept to the right of the decimal point before rounding. If Boolean and setValue(Double value) is used and this value sets the rounding sensitivity when determining true from false. newValue=Round(value*pow(10,scaleIfDouble).intValue)/pow(10,scaleIfDouble).intValue.level
- Used by FormulaVariableList to determine when variable can be desposed. Not used by MathStack.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.Method Detail |
---|
public static int findScaleOfDouble(java.lang.String variableValue)
variableValue
- value tested to figure out scale.
public static int detectVariableType(java.lang.String variableValue, boolean treatUnquotedTextAsFormulas)
public void setValue(java.lang.String value) throws java.lang.NumberFormatException
value
- a string value that is to be the new value. If this is TYPE_DOUBLE, then it will be rounded to the specified scale as defined when this was created.
java.lang.NumberFormatException
- if the variableType is of the TYPE_OPERATOR set or if variableType is TYPE_INTEGER or TYPE_DOUBLE and the value can't be converted.public void setValue(long value) throws java.lang.NumberFormatException
value
- the new long value. If TYPE_BOOLEAN then long value will be converted to 1 or 0 meaning that setValue((long)103) then getLong()==1. If TYPE_DATE then java.util.Date(long value) is used to get the date.
java.lang.NumberFormatException
- if variableType is of the TYPE_OPERATOR_ set.public void setValue(double value) throws java.lang.NumberFormatException
value
- the new double value. If TYPE_BOOLEAN then double value. scale will be used to set the sensitivity of true versus false. scale==2 means false is 0 +-.0049. If TYPE_DATE then java.util.Date(long value) is used to get the date.
java.lang.NumberFormatException
- if variableType is of the TYPE_OPERATOR_ set.public void setValue(double value, int scale) throws java.lang.NumberFormatException
value
- the new double value for this variable. If TYPE_DATE then java.util.Date(long value) is used to get the date.scale
- rounding scale where 1 = Tenths, 2 = OneHundreths, etc. Setting this value only makes sense for TYPE_DOUBLE and TYPE_BOOLEAN variableTypes
.
java.lang.NumberFormatException
- if variableType is of the TYPE_OPERATOR_ set.public void setValue(java.math.BigDecimal value) throws java.lang.NumberFormatException
value
- the new BigDecimal value. If TYPE_BOOLEAN then double value. scale will be used to set the sensitivity of true versus false. scale==2 means false is 0 +-.0049. If TYPE_DATE then java.util.Date(long value) is used to get the date.
java.lang.NumberFormatException
- if variableType is of the TYPE_OPERATOR_ set.public void setValue(java.math.BigDecimal value, int scale) throws java.lang.NumberFormatException
value
- the new BigDecimal value for this variable. If TYPE_DATE then java.util.Date(long value) is used to get the date.scale
- rounding scale where 1 = Tenths, 2 = OneHundreths, etc. Setting this value only makes sense for TYPE_DOUBLE and TYPE_BOOLEAN variableTypes
.
java.lang.NumberFormatException
- if variableType is of the TYPE_OPERATOR_ set.public void setValue(java.util.Date value) throws java.lang.NumberFormatException
value
- the Date value for this variable. If TYPE_LONG or TYPE_DOUBLE then value.toTime() is used.
java.lang.NumberFormatException
- if TYPE_BOOLEAN, TYPE_FORMULA, TYPE_FUNCTION, or TYPE_VARIABLE.public void setValue(boolean value) throws java.lang.NumberFormatException
value
- becomes a 0 if false, 1 if true if variableType is TYPE_BOOLEAN, TYPE_LONG, or TYPE_DOUBLE. TYPE_STRING will be "true" or "false"
java.lang.NumberFormatException
- if variableType is of the TYPE_OPERATOR_ set.public java.lang.String getString()
public java.lang.Long getLong() throws java.lang.NumberFormatException
java.lang.NumberFormatException
- if variableType is of the TYPE_OPERATOR_ set.public java.lang.Double getDouble() throws java.lang.NumberFormatException
java.lang.NumberFormatException
- if variableType is of the TYPE_OPERATOR_ set.public java.math.BigDecimal getBigDecimal() throws java.lang.NumberFormatException
java.lang.NumberFormatException
- if variableType is of the TYPE_OPERATOR_ set.public java.math.BigDecimal getBigDecimalScaled() throws java.lang.NumberFormatException
java.lang.NumberFormatException
- if variableType is of the TYPE_OPERATOR_ set.public boolean getBoolean() throws java.lang.NumberFormatException
java.lang.NumberFormatException
- if variableType is of the TYPE_OPERATOR_ set.public java.util.Date getDate() throws java.text.ParseException
java.text.ParseException
- if date can't be created from variableValueprotected boolean booleanValue(java.lang.String value)
value
- a string that considered true unless the value is null, an empty string, or matches (case-insensitive) the words false, f, no, n, or is zero when converted to long (If this is of TYPE_BOOLEAN or TYPE_DOUBLE, and the value can be converted into a Double, then it is rounded based on the scale).
public int getVariableType()
public java.lang.Object getValue()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getVariableName()
public int getLevel()
public int getScale()
public void setScale(int scale)
scale
- the number of digits to the right of the decimal point.public void setHighestLevel(int highestLevel)
highestLevel
- the highest level used when solving this variable. It gets set automatically, however, you may want to update it if you determined it's use based on a variable with a higher level than the one recorded here.public boolean isOperator()
public boolean isNonUnaryOperator()
public boolean isUnaryOperator()
public boolean isComparatorOperator()
public static boolean testIsOperator(java.lang.String operator)
operator
- String containing suspected operator (<, <=, =, >=, >, *, /, etc...).
public static boolean testIsOperator(char operator)
operator
- String containing suspected operator (<, <=, =, >=, >, *, /, etc...).
public static boolean testIsOperator(int operator)
operator
- the operator number.
public static int findOperatorPrecedence(java.lang.String operator)
operator
- String containing a possible operator (<, <=, =, >=, >, *, /, etc...).
public static boolean testIsUnaryOperator(int operator)
operator
- an int operator that is to be tested. Only Unary Operators at time of this writing were the exclamation point(NOT) and tilda(BIT NOT).
public static boolean testIsComparatorOperator(int operator)
operator
- an int operator that is to be tested. Only Comparator Operators at time of this writing were !=, <. <=, =, >=, and >.
public int getOperator()
public FormulaVariable clone()
clone
in class java.lang.Object
public int getHighestLevel()
public FormulaVariable solve(FormulaVariableList variableList, int iteration, SupportParameters supportParameters, FormulaFunctionList functionList, int resolveEverythingAboveLevel) throws java.text.ParseException, java.lang.ArithmeticException, java.lang.ClassNotFoundException
java.text.ParseException
java.lang.ArithmeticException
java.lang.ClassNotFoundException
public boolean isNull()
protected static java.lang.String padString(java.lang.String orgString, int size, char padChar, boolean padOnLeft)
size
long.
orgString
- the original Stringsize
- the final size of the returned StringpadChar
- the fill character used when padding the StringpadOnLeft
- If true the pad string from left else pad string from right.
public int getPrecision()
public void setPrecision(int precision)
precision
- the mathematical precision of the number. In doubles, this value defaults to the number of digits to the left of the decimal point + the scale since Doubles have 17 significant digits of precision. This is used in multiplication and division to determine the precision of the result (The lesser precision of two doubles). Ex: 10.2 would have a Precision of 3, 10.24 would have a precision of 4, 101 would have a precision of 3, 1.23456789098765432 would have a precision of 17.public void setStripSurroundingQuotesFromStrings(boolean state)
state
- If true then setValue(String value) will strip surrounding quotes from the value. This defaults to false unless treatUnquotedTextAsFormulas is set true, then this defaults to true as well.public boolean getStripSurroundingQuotesFromStrings()
public void purgeResultsGreaterThanSpecifiedLevel(int specifiedLevel)
specifiedLevel
- the level above which all results are to be purged.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |