jsky.util
Class JavaExpr

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

public class JavaExpr
extends Object
implements gnu.jel.DVResolver

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(String exprStr)
          Initialize and compile a new expression.
JavaExpr(String exprStr, gnu.jel.DVResolver 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.
 Object evalObject()
          Evaluate the expression and return the result as an Object.
 double getDoubleProperty(String name)
          Called by reflection for the DVResolver interface to get the value of the named variable
 String getTypeName(String name)
          Implements the DVResolver interface
static void main(String[] args)
          test main
 void setVar(String name, double value)
          Set the value of the given variable to the given value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaExpr

public JavaExpr(String exprStr)
         throws 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:
Throwable

JavaExpr

public JavaExpr(String exprStr,
                gnu.jel.DVResolver resolver)
         throws 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:
Throwable
Method Detail

getTypeName

public String getTypeName(String name)
Implements the DVResolver interface

Specified by:
getTypeName in interface gnu.jel.DVResolver

getDoubleProperty

public double getDoubleProperty(String name)
Called by reflection for the DVResolver interface to get the value of the named variable


setVar

public void setVar(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 Throwable
Evaluate the expression and return the result.

Throws:
Throwable

evalBoolean

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

Throws:
Throwable

evalObject

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

Throws:
Throwable

main

public static void main(String[] args)
test main



Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.