com.accountingenhancements.formula
Class FormulaFunctionList
java.lang.Object
com.accountingenhancements.formula.FormulaFunctionList
public class FormulaFunctionList
- extends java.lang.Object
FormulaFunctionList
is used to hand various programmer defined functions to the various Formula solve(...)
methods, such as FormulaVariable.solve(...)
. For a FormulaVariable
of TYPE_FUNCTION
, the solve
method will call the getFunction(FormulaVariable functionVariable)
method to instantiate correct Function.
Example: formulaVariable=new FormulaFunction("","IIF(9<8,7,6)",0,true); getFunction(formulaVariable);
will return a ((FormulaFunction)new FormulaFunction_IIF(formulaVariable))
through the use of reflection.
When creating a function, it needs to extend FormulaFunction
. Take a look at FormulaFunction_Left
or any of the other built-in functions for examples. Most of these functions override the solve(...) method, however, FormulaFunction_IIF overrides the function(...) method. It is better to override the solve() method in case more function(...) methods are added in the future (All function(...) methods from the underlying FormulaFunction call solve(...) to retrieve the result).
Note: When creating a new function, the public static getName() and public FormulaVariable solve(...) methods must be overridden!!!
The getRequiredSupportParameters(), getRequiredFormulaVariables(), getRequiredArguments(), and getRequiredArguments() are for allowing users to understand how to use the various formulas in a run-time formula creating environment. You should override the methods that apply to your situation. getRequiredArguments() is the most common one overriden.
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
FormulaFunctionList
public FormulaFunctionList()
- Creates a new instance of FormulaFunctionList.
The following Function classes are automatically added to the list:
FormulaFunction_IIF, FormulaFunction_LCase, FormulaFunction_Left, FormulaFunction_Ren, FormulaFunction_Mid, FormulaFunction_Right, and , FormulaFunction_UCase.
addFunction
public void addFunction(java.lang.Class<? extends FormulaFunction> functionClass)
- Parameters:
functionClass
- a function.class that extends FormulaFunction that is to be added to the list. The function name will be tracked as upper case. The name is retrieved through the getName() function so make this has been overriden from the underlying class. FormulaFunction.getName() returns "" and won't be added.
getFunctionClass
public java.lang.Class<? extends FormulaFunction> getFunctionClass(java.lang.String functionName)
- Parameters:
functionName
- a function name whose function is to be returned. The function name is converted to upper case for the search. If the function name contains the parentheses and arguments, these will be stripped off so handing IIF(9<8,5,4) to this routine will return the FormulaFunction_IIF class.
dropFunction
public void dropFunction(java.lang.String functionName)
- Parameters:
functionName
- a function name whose function is to be dropped from the list. The function name is converted to upper case.
getFunction
public FormulaFunction getFunction(FormulaVariable functionVariable)
throws java.lang.ClassNotFoundException
- This method will instantiate and return the correct function based on the TYPE_FUNCTION FormulaVariable handed to this routine.
- Parameters:
functionVariable
- A FormulaVariable of TYPE_FUNCTION. if the function name isn't found, or, if instantiating the class causes a ClassNotFoundException, IllegalAccessException, InstantiationExceptionSecurityException, NoSuchMethodException, or InvocationTargetException, a ClassNotFoundException will be thrown.
Ex: functionVariable.getString()=="IIF(9<8,7,6)" will instantiate FormulaFunction_IIF using the ForulaFunction_IIF(FormulaVariable) constructor.
- Throws:
java.lang.ClassNotFoundException
getFunction
public FormulaFunction getFunction(java.lang.String function)
throws java.lang.ClassNotFoundException
- Parameters:
function
- a function in String form. This creates a FormulaVariable from the supplied string with a default level of zero then calls the getFunction(FormulaVariable) method.
- Throws:
java.lang.ClassNotFoundException
getFunction
public FormulaFunction getFunction(java.lang.String function,
int level)
throws java.lang.ClassNotFoundException
- Parameters:
function
- a function in String form. This creates a FormulaVariable from the supplied string then calls the getFunction(FormulaVariable) method.level
- is the level assigned to the newly created FormulaVariable.
- Throws:
java.lang.ClassNotFoundException