jsky.util
Class JavaExpr

java.lang.Object
  extended by gnu.jel.DVMap
      extended by jsky.util.JavaExpr
All Implemented Interfaces:
gnu.jel.DVResolver

public class JavaExpr
extends gnu.jel.DVMap

This class is a simple wrapper for the JEL package and provides support for evaluating dynamic, numerical expressions in Java.

Author:
Allan Brighton

Constructor Summary
JavaExpr(java.lang.String exprStr)
          Initialize and compile a new expression.
JavaExpr(java.lang.String exprStr, gnu.jel.DVMap resolver)
          Initialize and compile a new expression.
 
Method Summary
 double eval()
          Evaluate the expression and return the result.
 boolean evalBoolean()
          Evaluate the expression and return the result as a boolean.
 java.lang.Object evalObject()
          Evaluate the expression and return the result as an Object.
 double getDoubleProperty(java.lang.String name)
          Called by reflection for the DVMap interface to get the value of the named variable
 java.lang.String getTypeName(java.lang.String name)
          Implements the DVMap interface
static void main(java.lang.String[] args)
          test main
 void setVar(java.lang.String name, double value)
          Set the value of the given variable to the given value.
 
Methods inherited from class gnu.jel.DVMap
translate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaExpr

public JavaExpr(java.lang.String exprStr)
         throws java.lang.Throwable
Initialize and compile a new expression. Any variables used in the expression must be set with the setVar method of this class.

Parameters:
exprStr - contains the expression string
Throws:
java.lang.Throwable

JavaExpr

public JavaExpr(java.lang.String exprStr,
                gnu.jel.DVMap resolver)
         throws java.lang.Throwable
Initialize and compile a new expression. Variables used in the expression are resolved using the given resolver object.

Parameters:
exprStr - contains the expression string
resolver - used to resolve variable names in expressions
Throws:
java.lang.Throwable
Method Detail

getTypeName

public java.lang.String getTypeName(java.lang.String name)
Implements the DVMap interface


getDoubleProperty

public double getDoubleProperty(java.lang.String name)
Called by reflection for the DVMap interface to get the value of the named variable


setVar

public void setVar(java.lang.String name,
                   double value)
Set the value of the given variable to the given value.

Note that variable names must conform to Java syntax ("$X" is allowed, but not ${X}, for example).


eval

public double eval()
            throws java.lang.Throwable
Evaluate the expression and return the result.

Throws:
java.lang.Throwable

evalBoolean

public boolean evalBoolean()
                    throws java.lang.Throwable
Evaluate the expression and return the result as a boolean.

Throws:
java.lang.Throwable

evalObject

public java.lang.Object evalObject()
                            throws java.lang.Throwable
Evaluate the expression and return the result as an Object.

Throws:
java.lang.Throwable

main

public static void main(java.lang.String[] args)
test main