com.accountingenhancements.formula
Class FormulaVariableMath

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

public class FormulaVariableMath
extends java.lang.Object


Constructor Summary
FormulaVariableMath()
          Creates a new instance of FormulaVariableMath
 
Method Summary
static boolean applyOperatorToCompareDates(java.util.Date left, int operator, java.util.Date right)
          Compares two dates.
Note: Ignores Time portion of date so new Date(1151064000000L) equals new Date(1151064006000L)
static boolean applyOperatorToCompareStrings(java.lang.String left, int operator, java.lang.String right)
           
static boolean applyOperatorToTwoVariables(boolean left, int operator, boolean right)
           
static long applyOperatorToTwoVariables(java.util.Date left, int operator, java.util.Date right)
          Find out the number of days between two dates.
static java.util.Date applyOperatorToTwoVariables(java.util.Date left, int operator, long right)
           
static double applyOperatorToTwoVariables(double left, int operator, double right)
           
static FormulaVariable applyOperatorToTwoVariables(FormulaVariable leftVariable, int operator, FormulaVariable rightVariable, FormulaVariableList variableList, SupportParameters supportParameters, FormulaFunctionList functionList, int resolveEverythingAboveLevel)
          Please note, when doing multiplication or division with doubles (where both variables are TYPE_DOUBLE, precision becomes important.
The lowest precision determines the number of digits to the right of the decimal point.
Ex: Assuming the precision of 10 is 2 (Not overriden by user so 2 digits long) .234 * 10 = 2.3 therefore scale=1
However, differing from real math, 12.345 * 10 = 123 (scale=0) instead of 120 (scale=-1) as regular math requires it because I am assuming user intent is that accuracy is always at least to the 1's place.
On a related note if one variable is a TYPE_LONG or TYPE_BOOLEAN , that variable defaults to a precision of 17, so in this case the precision ends up being the same as the precision of the only double value.
static FormulaVariable applyOperatorToTwoVariables(java.lang.Integer optionalLeftUnaryOperator, FormulaVariable leftVariable, int operator, java.lang.Integer optionalRightUnaryOperator, FormulaVariable rightVariable, FormulaVariableList variableList, SupportParameters supportParameters, FormulaFunctionList functionList, int resolveEverythingAboveLevel)
          Please note, when doing multiplication or division with doubles (where both variables are TYPE_DOUBLE, precision becomes important.
The lowest precision determines the number of digits to the right of the decimal point.
Ex: Assuming the precision of 10 is 2 (Not overriden by user so 2 digits long) .234 * 10 = 2.3 therefore scale=1
However, differing from real math, 12.345 * 10 = 123 (scale=0) instead of 120 (scale=-1) as regular math requires it because I am assuming user intent is that accuracy is always at least to the 1's place.
On a related note if one variable is a TYPE_LONG or TYPE_BOOLEAN , that variable defaults to a precision of 17, so in this case the precision ends up being the same as the precision of the only double value.
This means (Assuming scale of 12.345 is 5) that 12.345 * 10 = 123.45 and scale=2.
static long applyOperatorToTwoVariables(long left, int operator, long right)
           
static java.lang.String applyOperatorToTwoVariables(java.lang.String left, int operator, java.lang.String right)
           
static FormulaVariable solveUnaryOfVariable(int unaryOperator, FormulaVariable variable, FormulaVariableList variableList, SupportParameters supportParameters, FormulaFunctionList functionList, int resolveEverythingAboveLevel)
          Apply unary operations to variable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormulaVariableMath

public FormulaVariableMath()
Creates a new instance of FormulaVariableMath

Method Detail

solveUnaryOfVariable

public static FormulaVariable solveUnaryOfVariable(int unaryOperator,
                                                   FormulaVariable variable,
                                                   FormulaVariableList variableList,
                                                   SupportParameters supportParameters,
                                                   FormulaFunctionList functionList,
                                                   int resolveEverythingAboveLevel)
                                            throws java.text.ParseException,
                                                   java.lang.ArithmeticException,
                                                   java.lang.ClassNotFoundException
Apply unary operations to variable

Parameters:
unaryOperator - FormulaVariable.TYPE_OPERATOR_UNARY_BIT_NOT or FormulaVariable.TYPE_OPERATOR_UNARY_NOT
variable - the variable to which the unary operation is to be applied
variableList - a list of variables, used to resolve variable if variable is of TYPE_VARIABLE, TYPE_FUNCTION, or TYPE_FORMULA
supportParameters - a list of function parameters, used to resolve variable if variable is of TYPE_FORMULA or TYPE_FUNCTION
functionList - a list of functions, used to resolve variable if variable is of TYPE_FORMULA or TYPE_FUNCTION
resolveEverythingAboveLevel - reflects level at which TYPE_VARIABLE, TYPE_FUNCTION, and TYPE_FORMULA variables need to be re-solved.
Returns:
FormulaVariable containing the result of the operation. If of the TYPE_OPERATOR_UNARY_NOT variety then a TYPE_BOOLEAN variable is returned.
Throws:
ParseException, - ArithmeticException, ClassNotFoundException
java.text.ParseException
java.lang.ArithmeticException
java.lang.ClassNotFoundException

applyOperatorToTwoVariables

public static FormulaVariable applyOperatorToTwoVariables(FormulaVariable leftVariable,
                                                          int operator,
                                                          FormulaVariable rightVariable,
                                                          FormulaVariableList variableList,
                                                          SupportParameters supportParameters,
                                                          FormulaFunctionList functionList,
                                                          int resolveEverythingAboveLevel)
                                                   throws java.text.ParseException,
                                                          java.lang.ArithmeticException,
                                                          java.lang.ClassNotFoundException
Please note, when doing multiplication or division with doubles (where both variables are TYPE_DOUBLE, precision becomes important.
The lowest precision determines the number of digits to the right of the decimal point.
Ex: Assuming the precision of 10 is 2 (Not overriden by user so 2 digits long) .234 * 10 = 2.3 therefore scale=1
However, differing from real math, 12.345 * 10 = 123 (scale=0) instead of 120 (scale=-1) as regular math requires it because I am assuming user intent is that accuracy is always at least to the 1's place.
On a related note if one variable is a TYPE_LONG or TYPE_BOOLEAN , that variable defaults to a precision of 17, so in this case the precision ends up being the same as the precision of the only double value. This means (Assuming scale of 12.345 is 5) that 12.345 * 10 = 123.45 and scale=2. When adding or subtracting with only 1 variable being TYPE_DOUBLE, the scale is the scale of the TYPE_DOUBLE. The TYPE_LONG scale==0 is ignored.
The upshot is two TYPE_DOUBLEs can give you a different result than a TYPE_DOUBLE and TYPE_LONG given the same values.

Throws:
java.text.ParseException
java.lang.ArithmeticException
java.lang.ClassNotFoundException

applyOperatorToTwoVariables

public static FormulaVariable applyOperatorToTwoVariables(java.lang.Integer optionalLeftUnaryOperator,
                                                          FormulaVariable leftVariable,
                                                          int operator,
                                                          java.lang.Integer optionalRightUnaryOperator,
                                                          FormulaVariable rightVariable,
                                                          FormulaVariableList variableList,
                                                          SupportParameters supportParameters,
                                                          FormulaFunctionList functionList,
                                                          int resolveEverythingAboveLevel)
                                                   throws java.text.ParseException,
                                                          java.lang.ArithmeticException,
                                                          java.lang.ClassNotFoundException
Please note, when doing multiplication or division with doubles (where both variables are TYPE_DOUBLE, precision becomes important.
The lowest precision determines the number of digits to the right of the decimal point.
Ex: Assuming the precision of 10 is 2 (Not overriden by user so 2 digits long) .234 * 10 = 2.3 therefore scale=1
However, differing from real math, 12.345 * 10 = 123 (scale=0) instead of 120 (scale=-1) as regular math requires it because I am assuming user intent is that accuracy is always at least to the 1's place.
On a related note if one variable is a TYPE_LONG or TYPE_BOOLEAN , that variable defaults to a precision of 17, so in this case the precision ends up being the same as the precision of the only double value.
This means (Assuming scale of 12.345 is 5) that 12.345 * 10 = 123.45 and scale=2. When adding or subtracting with only 1 variable being TYPE_DOUBLE, the scale is the scale of the TYPE_DOUBLE. The TYPE_LONG scale==0 is ignored.
The upshot is two TYPE_DOUBLEs can give you a different result than a TYPE_DOUBLE and TYPE_LONG given the same values.
When working with Dates, If either or both arguments is/are TYPE_STRING(s) but the detectVariableType() confirms that it/they are date(s), the string(s) will be treated as date(s).

Throws:
java.text.ParseException
java.lang.ArithmeticException
java.lang.ClassNotFoundException

applyOperatorToTwoVariables

public static boolean applyOperatorToTwoVariables(boolean left,
                                                  int operator,
                                                  boolean right)
                                           throws java.lang.ArithmeticException
Parameters:
left - left value
operator - operation to be applied to left and right values
right - right value
Returns:
the result of the computation
Throws:
java.lang.ArithmeticException - if operation is invalid for these values.

applyOperatorToTwoVariables

public static long applyOperatorToTwoVariables(long left,
                                               int operator,
                                               long right)
                                        throws java.lang.ArithmeticException
Parameters:
left - left value
operator - operation to be applied to left and right values
right - right value
Returns:
the result of the computation
Throws:
java.lang.ArithmeticException - if operation is invalid for these values.

applyOperatorToTwoVariables

public static long applyOperatorToTwoVariables(java.util.Date left,
                                               int operator,
                                               java.util.Date right)
                                        throws java.lang.ArithmeticException
Find out the number of days between two dates.

Parameters:
left - left value
operator - operation to be applied to left and right values. Only allowed to TYPE_OPERATOR_MINUS two dates.
right - right value
Returns:
the number of days between the two dates.
Throws:
java.lang.ArithmeticException - if operation is invalid for these values.

applyOperatorToTwoVariables

public static java.util.Date applyOperatorToTwoVariables(java.util.Date left,
                                                         int operator,
                                                         long right)
                                                  throws java.lang.ArithmeticException
Parameters:
left - left value
operator - operation to be applied to left and right values
right - right value in days
Returns:
the result of the computation
Throws:
java.lang.ArithmeticException - if operation is invalid for these values.

applyOperatorToTwoVariables

public static double applyOperatorToTwoVariables(double left,
                                                 int operator,
                                                 double right)
                                          throws java.lang.ArithmeticException
Parameters:
left - left value
operator - operation to be applied to left and right values
right - right value
Returns:
the result of the computation
Throws:
java.lang.ArithmeticException - if operation is invalid for these values.

applyOperatorToCompareDates

public static boolean applyOperatorToCompareDates(java.util.Date left,
                                                  int operator,
                                                  java.util.Date right)
                                           throws java.lang.ArithmeticException
Compares two dates.
Note: Ignores Time portion of date so new Date(1151064000000L) equals new Date(1151064006000L)

Parameters:
left - left value
operator - operation to be applied to left and right values
right - right value
Returns:
the result of the computation
Throws:
java.lang.ArithmeticException - if operation is invalid for these values.

applyOperatorToCompareStrings

public static boolean applyOperatorToCompareStrings(java.lang.String left,
                                                    int operator,
                                                    java.lang.String right)
                                             throws java.lang.ArithmeticException
Parameters:
left - left value
operator - operation to be applied to left and right values
right - right value
Returns:
the result of the computation
Throws:
java.lang.ArithmeticException - if operation is invalid for these values.

applyOperatorToTwoVariables

public static java.lang.String applyOperatorToTwoVariables(java.lang.String left,
                                                           int operator,
                                                           java.lang.String right)
                                                    throws java.lang.ArithmeticException
Parameters:
left - left value
operator - operation to be applied to left and right values. Only allowed to TYPE_OPERATOR_PLUS two strings
right - right value
Returns:
the result of the computation
Throws:
java.lang.ArithmeticException - if operation is invalid for these values.