package com.changhong.epc.parsing.service.autosubmit.tool; import java.util.Map; import com.googlecode.aviator.AviatorEvaluator; import com.changhong.epc.parsing.service.autosubmit.tool.function.Avg; import com.changhong.epc.parsing.service.autosubmit.tool.function.Sum; public class AviatorTool { static{ // 子表单 聚合函数 总和 AviatorEvaluator.addFunction(new Sum()); // 子表单 聚合函数 平均值 AviatorEvaluator.addFunction(new Avg()); } public static T execute(String expression, Map env, Class clazz){ return execute(expression, env, clazz, null); } @SuppressWarnings("unchecked") public static T execute(String expression, Map env, Class clazz, CallBack call){ try{ return (T) AviatorEvaluator.compile(expression).execute(env); }catch (Exception e) { if(call != null) return call.error(e); return null; } } @FunctionalInterface public static interface CallBack{ T error(Exception e); } }