Aviator是一个高性能、轻量级的基于java实现的表达式引擎,它动态地将String类型的表达式编译成Java ByteCode并交给JVM执行。
Aviator支持所有的关系运算符和算术运算符,不支持位运算,同时支持表达式的优先级,优先级跟Java的运算符一样,并且支持通过括号来强制优先级。
示例代码:
Map<String, Object> env = new HashMap<String, Object>();
env.put("email", "killme2008@gmail.com");
String name = (String)AviatorEvaluator.execute("email=~/([\\w0-8]+@\\w+[\\.\\w+]+)/ ? $1:'unknow'", env);
import com.googlecode.aviator.AviatorEvaluator; for (LERule lERule:lERules) { ??????????? String rulePatternTemplate = lERule.getRulePattern(); ??????????? String rulePatternStr = FreemarkerTemplateUtil.processFreemarker(rulePatternTemplate, bPBody.getBPInfo()); ??????????? if(StringUtils.isNotBlank(rulePatternStr)){ ??????????????? boolean isEvent = (Boolean) AviatorEvaluator.execute(rulePatternStr); ??????????????? if(isEvent){ ??????????????????? lEList.add(lERule.getLE()); ??????????????? } ??????????? } ??????? }
maven的坐标:
<dependency>
<groupId>com.googlecode.aviator</groupId>
<artifactId>aviator</artifactId>
<version>5.2.7</version>
</dependency>
|