cn.hutool.extra.expression.engine.aviator.AviatorEngine 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.aviator;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.extra.expression.ExpressionEngine;
import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.AviatorEvaluatorInstance;
import com.googlecode.aviator.Options;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
/**
* Aviator引擎封装
* 见:https://github.com/killme2008/aviatorscript
*
* @author looly
* @since 5.5.0
*/
public class AviatorEngine implements ExpressionEngine {
private final AviatorEvaluatorInstance engine;
/**
* 构造
*/
public AviatorEngine() {
engine = AviatorEvaluator.getInstance();
}
@Override
public Object eval(String expression, Map context, Collection> allowClassSet) {
// issue#I6AJWJ
engine.setOption(Options.ALLOWED_CLASS_SET,
CollUtil.isEmpty(allowClassSet) ? Collections.emptySet() : CollUtil.newHashSet(allowClassSet));
return engine.execute(expression, context);
}
/**
* 获取{@link AviatorEvaluatorInstance}
*
* @return {@link AviatorEvaluatorInstance}
*/
public AviatorEvaluatorInstance getEngine() {
return this.engine;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy