cn.hutool.extra.expression.engine.qlexpress.QLExpressEngine Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hutool-all Show documentation
Show all versions of hutool-all Show documentation
Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
package cn.hutool.extra.expression.engine.qlexpress;
import cn.hutool.extra.expression.ExpressionEngine;
import cn.hutool.extra.expression.ExpressionException;
import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;
import java.util.Collection;
import java.util.Map;
/**
* QLExpress引擎封装
* 见:https://github.com/alibaba/QLExpress
*
* @author looly
* @since 5.8.9
*/
public class QLExpressEngine implements ExpressionEngine {
private final ExpressRunner engine;
/**
* 构造
*/
public QLExpressEngine() {
engine = new ExpressRunner();
}
@Override
public Object eval(final String expression, final Map context, Collection> allowClassSet) {
final DefaultContext defaultContext = new DefaultContext<>();
defaultContext.putAll(context);
try {
return engine.execute(expression, defaultContext, null, true, false);
} catch (final Exception e) {
throw new ExpressionException(e);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy