// 数值型
Expression exp = new Expression("(x + y)/2");
Map variables = new HashMap();
variables.put("x", new BigDecimal("4.32"));
variables.put("y", new BigDecimal("342.1"));
BigDecimal result = exp.eval(variables);
System.out.println(result);
// 布尔型
Expression ww = new Expression("( A && B ) || C ");
Map vs = new HashMap();
vs.put("A", new BigDecimal("0"));
vs.put("B", new BigDecimal("1"));
vs.put("C", new BigDecimal("1"));
System.out.println(ww.eval(vs));
// 布尔型
Expression dd = new Expression(" A > 200 ");
Map as = new HashMap();
as.put("A", new BigDecimal("12000"));
System.out.println(dd.eval(as));
需要eval.jar
posted on 2014-04-02 17:07 zhaonp 阅读(79) 评论(0) 编辑 收藏 所属分类: Java