Interface ICustomDefinedFunctions
The implementing class does not have to do any parameter type checking. Parameter type checking will be handled by the reporting engine.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final shortthe BOOLEAN data typestatic final shortthe DATE data typestatic final shortthe NUMERIC data typestatic final shortthe STRING data typestatic final shortthe TIME data typestatic final shortthe TIMESTAMP data type -
Method Summary
Modifier and TypeMethodDescriptionString[]Returns the names of all functions.int[]getParamTypes(String functionName) Gets the parameter types of the specified function.intgetReturnType(String functionName) Gets the return type of the specified function.This is where you implement your function.
-
Field Details
-
NUMERIC
static final short NUMERICthe NUMERIC data type- See Also:
-
STRING
static final short STRINGthe STRING data type- See Also:
-
BOOLEAN
static final short BOOLEANthe BOOLEAN data type- See Also:
-
DATE
static final short DATEthe DATE data type- See Also:
-
TIME
static final short TIMEthe TIME data type- See Also:
-
TIMESTAMP
static final short TIMESTAMPthe TIMESTAMP data type- See Also:
-
-
Method Details
-
getAllFunctionNames
String[] getAllFunctionNames()Returns the names of all functions.For example, if the functions MAX and MIN are going to be defined by this class, the implementation of the getAllFunctionNames() should read:
public String[] getAllFunctionNames() {- return new String[] {"MAX", "MIN"};
- Returns:
- a String[] of names of all functions defined in this class
-
getReturnType
Gets the return type of the specified function.For example, if the functions MAX and MIN both return a number, the implementation of the getReturnType() function might read:
public int getReturnType(String functionName) {- if (functionName.equals("MAX")) return NUMERIC;
else if (functionName.equals("MIN")) return NUMERIC;
return -1;- Parameters:
String- functionName: name of the custom defined function- Returns:
- int: data type of the object returned by the function
-
getParamTypes
Gets the parameter types of the specified function.For example, if the functions MAX and MIN both take in two arguments of type number, the implementation of the getParamTypes() function might read:
public int[] getParamTypes(String functionName) {- if (functionName.equals("MAX")) return new int[] {NUMERIC, NUMERIC};
else if (functionName.equals("MIN")) return new int[] {NUMERIC, NUMERIC};
return -1;- Parameters:
String- functionName: name of the custom defined function- Returns:
- int[]: data type of the parameters to the function.
-
getValue
This is where you implement your function. The function specified by the functionName gets passed in the correct arguments using the ARGS parameter and returns the calculated value after the function is applied. The class is responsible for type checking the incoming variables.For example, if the functions MAX and MIN gets the maximum and minimum of the two input arguments, respectively, the implementation of the getReturnType() function might read:
public Object getValue(String functionName, Object[] args) {- if (functionName.equals("MAX") invalid input: '&'invalid input: '&' (args[0] instanceof int) invalid input: '&'invalid input: '&' (args[1] instanceof int) )
- return java.lang.Math.max((int) args[0], (int) args[1]);
else if (functionName.equals("MIN") invalid input: '&'invalid input: '&' (args[0] instanceof int) invalid input: '&'invalid input: '&' (args[1] instanceof int) )- return java.lang.Math.max((int) args[0], (int) args[1]);
return null;- Parameters:
String- functionName: name of the custom defined functionObject- [] args: arguments to the function- Returns:
- Object: object returned by the function
- Throws:
Exception
-