Expression MVEL
Expression MVEL
MVEL based implementation of the Everit Expression API.
The following code snippet compiles an expression and evaluates it:
MvelExpressionCompiler compiler = new MvelExpressionCompiler(); String testExpression = "a + b"; CompiledExpression compiledExpression = compiler.compile(testExpression, new ParserConfiguration(this.getClass().getClassLoader())); Mapvars = new HashMap (); vars.put("a", 1); vars.put("b", 2); Integer result = compiledExpression.eval(vars); System.out.println(result);
Please note that it is recommended to keep the compiled expression and reuse it! The library is based on MVEL. The syntax of MVEL expressions can be used.
In case of an exception during evaluation the column and row is not calculated well. This is an issue of MVEL as sometimes the thrown exception contains wrong position.