All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class gnu.jel.CompiledExpression

java.lang.Object
   |
   +----gnu.jel.CompiledExpression

public abstract class CompiledExpression
extends Object
The superclass of every compiled expression.

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.

See Also:
Library

Constructor Index

 o CompiledExpression()

Method Index

 o evaluate(Object[])
Evaluates the expression, representing result as an object.
 o evaluate_boolean(Object[])
Evaluates the expression whose result has type boolean.
 o evaluate_byte(Object[])
Evaluates the expression whose result has type byte.
 o evaluate_char(Object[])
Evaluates the expression whose result has type char.
 o evaluate_double(Object[])
Evaluates the expression whose result has type double.
 o evaluate_float(Object[])
Evaluates the expression whose result has type float.
 o evaluate_int(Object[])
Evaluates the expression whose result has type int.
 o evaluate_long(Object[])
Evaluates the expression whose result has type long.
 o evaluate_short(Object[])
Evaluates the expression whose result has type short.
 o getType()
Returns type of the expression result.

Constructors

 o CompiledExpression
 public CompiledExpression()

Methods

 o getType
 public abstract int getType()
Returns type of the expression result.

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.

Returns:
the type of the expression, encoded in integer.
 o evaluate
 public Object evaluate(Object dl[]) throws Throwable
Evaluates the expression, representing result as an object.

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,...

Parameters:
dl - Array of the instance references to the objects in dynamic library. See description of this class above for more details.
Returns:
the result fo computation.
Throws: Throwable
if any runtime error have occured (i.e. division by 0)
See Also:
compile, Library
 o evaluate_boolean
 public boolean evaluate_boolean(Object dl[]) throws Throwable
Evaluates the expression whose result has type boolean.

If the type of the result is not a boolean this function returns always false, debug version will print warning to stderr.

Parameters:
dl - Array of the instance references to the objects in dynamic library. See description of this class above for more details.
Returns:
the result fo computation.
Throws: Throwable
if any runtime error have occured (i.e. division by 0)
See Also:
compile, Library
 o evaluate_byte
 public byte evaluate_byte(Object dl[]) throws Throwable
Evaluates the expression whose result has type byte.

If the type of the result is not a byte this function returns always 0, debug version will print warning to stderr.

Parameters:
dl - Array of the instance references to the objects in dynamic library. See description of this class above for more details.
Returns:
the result fo computation.
Throws: Throwable
if any runtime error have occured (i.e. division by 0)
See Also:
compile, Library
 o evaluate_short
 public short evaluate_short(Object dl[]) throws Throwable
Evaluates the expression whose result has type short.

If the type of the result is not a short this function returns always 0, debug version will print warning to stderr.

Parameters:
dl - Array of the instance references to the objects in dynamic library. See description of this class above for more details.
Returns:
the result fo computation.
Throws: Throwable
if any runtime error have occured (i.e. division by 0)
See Also:
compile, Library
 o evaluate_char
 public char evaluate_char(Object dl[]) throws Throwable
Evaluates the expression whose result has type char.

If the type of the result is not a char this function returns always '?', debug version will print warning to stderr.

Parameters:
dl - Array of the instance references to the objects in dynamic library. See description of this class above for more details.
Returns:
the result fo computation.
Throws: Throwable
if any runtime error have occured (i.e. division by 0)
See Also:
compile, Library
 o evaluate_int
 public int evaluate_int(Object dl[]) throws Throwable
Evaluates the expression whose result has type int.

If the type of the result is not a int this function returns always 0, debug version will print warning to stderr.

Parameters:
dl - Array of the instance references to the objects in dynamic library. See description of this class above for more details.
Returns:
the result fo computation.
Throws: Throwable
if any runtime error have occured (i.e. division by 0)
See Also:
compile, Library
 o evaluate_long
 public long evaluate_long(Object dl[]) throws Throwable
Evaluates the expression whose result has type long.

If the type of the result is not a long this function returns always 0, debug version will print warning to stderr.

Parameters:
dl - Array of the instance references to the objects in dynamic library. See description of this class above for more details.
Returns:
the result fo computation.
Throws: Throwable
if any runtime error have occured (i.e. division by 0)
See Also:
compile, Library
 o evaluate_float
 public float evaluate_float(Object dl[]) throws Throwable
Evaluates the expression whose result has type float.

If the type of the result is not a float this function returns always 0.0, debug version will print warning to stderr.

Parameters:
dl - Array of the instance references to the objects in dynamic library. See description of this class above for more details.
Returns:
the result fo computation.
Throws: Throwable
if any runtime error have occured (i.e. division by 0)
See Also:
compile, Library
 o evaluate_double
 public double evaluate_double(Object dl[]) throws Throwable
Evaluates the expression whose result has type double.

If the type of the result is not a double this function returns always 0.0, debug version will print warning to stderr.

Parameters:
dl - Array of the instance references to the objects in dynamic library. See description of this class above for more details.
Returns:
the result fo computation.
Throws: Throwable
if any runtime error have occured (i.e. division by 0)
See Also:
compile, Library

All Packages  Class Hierarchy  This Package  Previous  Next  Index