com.googlecode.aviator.AviatorEvaluator Java Examples

The following examples show how to use com.googlecode.aviator.AviatorEvaluator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AviaterELFilter.java    From binlake with Apache License 2.0 5 votes vote down vote up
public boolean filter(WaveEntry.Entry entry) throws BinlogException {
    if (StringUtils.isEmpty(expression)) {
        return true;
    }

    Map<String, Object> env = new HashMap<String, Object>();
    env.put(ROOT_KEY, entry);
    return (Boolean) AviatorEvaluator.execute(expression, env);
}
 
Example #2
Source File: UKTools.java    From youkefu with Apache License 2.0 5 votes vote down vote up
/***
 * 计算T+1
 * @param text
 * @param format
 * @return
 */
public static Object getDaysParam(String text){
	Map<String,Object>  context = new HashMap<String,Object>();
	context.put("T", processDays()) ;
	context.put("t", processDays()) ;
	context.put("M", processMonth()) ;
	context.put("m", processMonth()) ;
	context.put("Y", processYear()) ;
	context.put("y", processYear()) ;
	
   	return AviatorEvaluator.execute(text , context) ;
}
 
Example #3
Source File: AviaterELFilter.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public boolean filter(CanalEntry.Entry entry) throws CanalFilterException {
    if (StringUtils.isEmpty(expression)) {
        return true;
    }

    Map<String, Object> env = new HashMap<String, Object>();
    env.put(ROOT_KEY, entry);
    return (Boolean) AviatorEvaluator.execute(expression, env);
}
 
Example #4
Source File: Test.java    From vscrawler with Apache License 2.0 5 votes vote down vote up
public static void main1(String[] args) {
    List<String> symble = Lists.newArrayList("+", "-", "*", "/", "%", "^");

    for (String s1 : symble) {
        for (String s2 : symble) {
            String expression = "4" + s1 + "4" + s2 + "4";
            Object exec = AviatorEvaluator.exec(expression);
            System.out.println(expression + "=" + exec);
        }
    }
}
 
Example #5
Source File: AviatorExprUtils.java    From EasyReport with Apache License 2.0 5 votes vote down vote up
public static Object execute(final String expression, final Map<String, Object> context) {
    Object value = null;

    try {
        final Expression compiledExp = AviatorEvaluator.compile(expression, true);
        value = compiledExp.execute(context);
    } catch (final ExpressionRuntimeException ex) {
        logger.error(ex.getMessage());
    }

    return value;
}
 
Example #6
Source File: AviaterELFilter.java    From canal with Apache License 2.0 5 votes vote down vote up
public boolean filter(CanalEntry.Entry entry) throws CanalFilterException {
    if (StringUtils.isEmpty(expression)) {
        return true;
    }

    Map<String, Object> env = new HashMap<String, Object>();
    env.put(ROOT_KEY, entry);
    return (Boolean) AviatorEvaluator.execute(expression, env);
}
 
Example #7
Source File: WarningRuleHelper.java    From seppb with MIT License 4 votes vote down vote up
@Override
public Object runAndReturn(String expression, T t) {
    return AviatorEvaluator.execute(expression, beanToMap(t));
}
 
Example #8
Source File: WarningRuleHelperTest.java    From seppb with MIT License 4 votes vote down vote up
@Test
public void execute1() {
    Expression compile = AviatorEvaluator.compile("(influence - foundMeans) / defectPeriod > 0 && (influence - foundMeans) / defectPeriod < 1");
    boolean execute = warningRuleHelper.execute(compile, defect);
    assertTrue(execute);
}