use of org.apache.commons.jexl3.MapContext in project shifu by ShifuML.
the class JexlTest method testJavaDouble.
@Test
public void testJavaDouble() {
JexlEngine jexl = new JexlEngine();
String jexlExp = "columnA + columnB";
Expression e = jexl.createExpression(jexlExp);
JexlContext jc = new MapContext();
// Now evaluate the expression, getting the result
Integer val = (Integer) e.evaluate(jc);
Assert.assertEquals(val, Integer.valueOf(0));
jc.set("columnA", "0.3");
double value = (Double) e.evaluate(jc);
Assert.assertEquals(0.3, value);
jc.set("columnB", "0.7");
value = (Double) e.evaluate(jc);
Assert.assertEquals(value, 1.0);
}
use of org.apache.commons.jexl3.MapContext in project aries by apache.
the class JexlPropertyEvaluator method evaluate.
public Object evaluate(String expression, Map<String, Object> properties) {
try {
JexlEngine engine = new JexlEngine();
MapContext context = new MapContext(properties);
Expression exp = engine.createExpression(expression);
return exp.evaluate(context);
} catch (Exception e) {
LOGGER.info("Could not evaluate expression: {}", expression);
LOGGER.info("Exception:", e);
return null;
}
}
use of org.apache.commons.jexl3.MapContext in project dhis2-core by dhis2.
the class ExpressionUtils method evaluate.
/**
* @param expression the expression.
* @param vars the variables, can be null.
* @param strict indicates whether to use strict or lenient engine mode.
* @return the result of the evaluation.
*/
private static Object evaluate(String expression, Map<String, Object> vars, boolean strict) {
expression = expression.replaceAll(IGNORED_KEYWORDS_REGEX, StringUtils.EMPTY);
JexlEngine engine = strict ? JEXL_STRICT : JEXL;
Expression exp = engine.createExpression(expression);
JexlContext context = vars != null ? new MapContext(vars) : new MapContext();
return exp.evaluate(context);
}
Aggregations