: Class CompiledExpression

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## gnu.jel
Class CompiledExpression

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

public abstract class CompiledExpression
extends java.lang.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 Summary
`CompiledExpression()`

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

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### CompiledExpression

    public CompiledExpression()

Method Detail

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

### evaluate

    public java.lang.Object evaluate(java.lang.Object[] dl)
                              throws java.lang.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:
    java.lang.Throwable - if any runtime error have occured (i.e. division by 0)
  See Also:
    `Evaluator.compile(java.lang.String, gnu.jel.Library, java.lang.Class)`, `Library`

### evaluate_boolean

    public boolean evaluate_boolean(java.lang.Object[] dl)
                             throws java.lang.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:
    java.lang.Throwable - if any runtime error have occured (i.e. division by 0)
  See Also:
    `Evaluator.compile(java.lang.String, gnu.jel.Library, java.lang.Class)`, `Library`

### evaluate_byte

    public byte evaluate_byte(java.lang.Object[] dl)
                       throws java.lang.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:
    java.lang.Throwable - if any runtime error have occured (i.e. division by 0)
  See Also:
    `Evaluator.compile(java.lang.String, gnu.jel.Library, java.lang.Class)`, `Library`

### evaluate_short

    public short evaluate_short(java.lang.Object[] dl)
                         throws java.lang.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:
    java.lang.Throwable - if any runtime error have occured (i.e. division by 0)
  See Also:
    `Evaluator.compile(java.lang.String, gnu.jel.Library, java.lang.Class)`, `Library`

### evaluate_char

    public char evaluate_char(java.lang.Object[] dl)
                       throws java.lang.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:
    java.lang.Throwable - if any runtime error have occured (i.e. division by 0)
  See Also:
    `Evaluator.compile(java.lang.String, gnu.jel.Library, java.lang.Class)`, `Library`

### evaluate_int

    public int evaluate_int(java.lang.Object[] dl)
                     throws java.lang.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:
    java.lang.Throwable - if any runtime error have occured (i.e. division by 0)
  See Also:
    `Evaluator.compile(java.lang.String, gnu.jel.Library, java.lang.Class)`, `Library`

### evaluate_long

    public long evaluate_long(java.lang.Object[] dl)
                       throws java.lang.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:
    java.lang.Throwable - if any runtime error have occured (i.e. division by 0)
  See Also:
    `Evaluator.compile(java.lang.String, gnu.jel.Library, java.lang.Class)`, `Library`

### evaluate_float

    public float evaluate_float(java.lang.Object[] dl)
                         throws java.lang.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:
    java.lang.Throwable - if any runtime error have occured (i.e. division by 0)
  See Also:
    `Evaluator.compile(java.lang.String, gnu.jel.Library, java.lang.Class)`, `Library`

### evaluate_double

    public double evaluate_double(java.lang.Object[] dl)
                           throws java.lang.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:
    java.lang.Throwable - if any runtime error have occured (i.e. division by 0)
  See Also:
    `Evaluator.compile(java.lang.String, gnu.jel.Library, java.lang.Class)`, `Library`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD