All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----gnu.jel.CompiledExpression
You can not get the instance of this class (because it is abstract) but every JEL compiled expression is subclass of it. Some functions in this class are overridden by the result of compilation.
Most methods of this class accept a reference to the array of objects. This reference is the pointer to the dynamic object library. As You, probably, read : JEL allows to call virtual methods of Java classes. But, virtual methods require the reference to the object (this) to be passed along with parameters. That is, the array dl (dynamic library) should contain references to objects of all classes, whose virtual methods were put into the Library of callable functions. The objects in the dl array should be instances of corresponding classes in the array, passed as a second argument of gnu.jel.Library constructor.
There are two ways of evaluation of compiled expressions. These methods vary in the performance achieved.
The first method (simplest one) is based on the call to the evaluate method, which will return an object even if the result of computation was the primitive type. The primitive types will be converted to the corresponding reflection objects. There is certain overhead, associated with object creation, it takes CPU cycles and also produces load on the garbage collector later..
For massive (thousand times) evaluations of functions, producing results of primitive Java types , the second method can be more suitable. It is based on : first, determining the type of the result, and, then, subsequent call to the proper evaluateXXX method.
The type of the resulting expression can be determined by call to the getType() method. It will return an integer number, indentifying the type, proper method can be determined, based on the following table:
getType() | method to call ------------+---------------------- 0 | evaluate_boolean(...) 1 | evaluate_byte(...) 2 | evaluate_char(...) 3 | evaluate_short(...) 4 | evaluate_int(...) 5 | evaluate_long(...) 6 | evaluate_float(...) 7 | evaluate_double(...) >7 | evaluate() <- means result is Object or void (null) -----------------------------------
Note: If You call wrong evaluateXXX() method -- zero will be returned, and warning will be printed to stderr (in debug version of JEL only).
There is the possibility to enforce resulting type of the expression at compile time. Use it to avoid unnecesary type checks.
public CompiledExpression()
public abstract int getType()
The type is encoded in integer. Following table could help in determining what it is : getType() | method to call ------------+----------------- 0 | boolean 1 | byte 2 | char 3 | short 4 | int 5 | long 6 | float 7 | double 8 | void 9 | Object
The reason not to introduce the family of, say, TYPE_XXX constants is to save space... well there are many things connected with these particular numbers in codegenerator that it could be a pain to change the meaning of those numbers. This is not needed also because these are ALL Java 1.X primitive types.
public Object evaluate(Object dl[]) throws Throwable
If the result of evaluation is Java primitive type it gets wrapped into corresponding reflection object , i.e. int -> java.lang.Integer, boolean -> java.lang.Boolean,...
public boolean evaluate_boolean(Object dl[]) throws Throwable
If the type of the result is not a boolean this function returns always false, debug version will print warning to stderr.
public byte evaluate_byte(Object dl[]) throws Throwable
If the type of the result is not a byte this function returns always 0, debug version will print warning to stderr.
public short evaluate_short(Object dl[]) throws Throwable
If the type of the result is not a short this function returns always 0, debug version will print warning to stderr.
public char evaluate_char(Object dl[]) throws Throwable
If the type of the result is not a char this function returns always '?', debug version will print warning to stderr.
public int evaluate_int(Object dl[]) throws Throwable
If the type of the result is not a int this function returns always 0, debug version will print warning to stderr.
public long evaluate_long(Object dl[]) throws Throwable
If the type of the result is not a long this function returns always 0, debug version will print warning to stderr.
public float evaluate_float(Object dl[]) throws Throwable
If the type of the result is not a float this function returns always 0.0, debug version will print warning to stderr.
public double evaluate_double(Object dl[]) throws Throwable
If the type of the result is not a double this function returns always 0.0, debug version will print warning to stderr.
All Packages Class Hierarchy This Package Previous Next Index