Menu

Home Log in to Edit

lenysoft

Javex

Javex is a Java expression parser and evaluator.
It can parse and evaluate math, logical, string and date functions.

You can prepare (parse) the expression one time and then evaluate it multiple times with distincts sets of variables.

In addition, javex support external functions (user defined functions) into the expression.

Functions supported

add , substract , divide , multiply , power , sqrt, abs
and, or, not, >, >=, <, <=, ==, !=, !
date diff, date add
length, tolower, toupper, substring, ends with, starts with,
contains, match
between, in list

Example

String s = "5 + externalfunction(TST1,TST2,TST3)";

ArrayList l=new ArrayList();
l.add(new ExternalFunctionTest());

Map m=new TreeMap();
m.put("TST1", 1);
m.put("TST2", 2);
m.put("TST3", 3);

try {   

    ExpressionImpl x1 = new ExpressionImpl(s);
    x1.setExternalFunctions(l);
    x1.prepare();

        //To evaluate more than once
        ExpressionImpl x2=x1.getInstance();
    Object result = x2.evaluate(variables);

} catch (Exception e) {

    System.out.println("error");

}

Discussion

Anonymous
Anonymous

Add attachments
Cancel