当前位置: 首页>>代码示例>>Java>>正文


Java Expression类代码示例

本文整理汇总了Java中org.apache.commons.jexl2.Expression的典型用法代码示例。如果您正苦于以下问题:Java Expression类的具体用法?Java Expression怎么用?Java Expression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Expression类属于org.apache.commons.jexl2包,在下文中一共展示了Expression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: evaluate

import org.apache.commons.jexl2.Expression; //导入依赖的package包/类
public String evaluate(final String expression,
        final JexlContext jexlContext) {

    String result = "";

    if (expression != null
            && !expression.isEmpty() && jexlContext != null) {

        try {
            Expression jexlExpression =
                    jexlEngine.createExpression(expression);
            Object evaluated = jexlExpression.evaluate(jexlContext);
            if (evaluated != null) {
                result = evaluated.toString();
            }
        } catch (JexlException e) {
            LOG.error("Invalid jexl expression: " + expression, e);
            result = "";
        }
    } else {
        LOG.debug("Expression not provided or invalid context");
    }

    return result;
}
 
开发者ID:ilgrosso,项目名称:oldSyncopeIdM,代码行数:26,代码来源:JexlUtil.java

示例2: isAboveThreshold

import org.apache.commons.jexl2.Expression; //导入依赖的package包/类
/**
 *
 */
@Override
public boolean isAboveThreshold(MetricTimeSeries timeSeries)
{
  Set<Long> timeWindowSet = timeSeries.getTimeWindowSet();
  JexlEngine jexl = new JexlEngine();
  JexlContext context = new MapContext();
  Expression e = jexl.createExpression(this.thresholdExpr);
  for(String metricName : metricNames){
    long sum = 0;
    for (Long timeWindow : timeWindowSet) {
      sum += timeSeries.get(timeWindow, metricName).longValue();
    }
    context.set(metricName, sum);
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug(metricName + " = " + sum);
    }
  }
  return ((Boolean)e.evaluate(context)).booleanValue();
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:23,代码来源:MultiMetricTotalAggregateBasedRollupFunction.java

示例3: testPower

import org.apache.commons.jexl2.Expression; //导入依赖的package包/类
@Test
public void testPower() {
	JexlEngine engine = ExpressionEvalFactory.getInstance();
	Expression expr = engine.createExpression("X^2");

	JexlContext context = new MapContext();
	// Don't need this really
	context.set("A", 20);
	context.set("B", 0);

	ArrayList<Double> actualList = new ArrayList<>();
	for (int i = -20; i < 20; i++) {
		context.set("X", i);
		Double result = (Double) expr.evaluate(context);
		actualList.add(result);
		System.out.println(result + ",");
	}

	Double[] actual = actualList.toArray(new Double[0]);
	Double[] expected = {400.0, 361.0, 324.0, 289.0, 256.0, 225.0, 196.0,
		169.0, 144.0, 121.0, 100.0, 81.0, 64.0, 49.0, 36.0, 25.0, 16.0,
		9.0, 4.0, 1.0, 0.0, 1.0, 4.0, 9.0, 16.0, 25.0, 36.0, 49.0, 64.0,
		81.0, 100.0, 121.0, 144.0, 169.0, 196.0, 225.0, 256.0, 289.0,
		324.0, 361.0};
	Assert.assertArrayEquals("results wrong", expected, actual);
}
 
开发者ID:umeding,项目名称:fuzzer,代码行数:27,代码来源:JEXLTest.java

示例4: evaluate

import org.apache.commons.jexl2.Expression; //导入依赖的package包/类
/**
 * <p>
 * The condition can be any JEXL boolean expression:
 * </p>
 * <ul>
 * <li><code>obj.field == 'value'</code></li>
 * <li><code>obj.field != null && obj.field == 'value'</code></li>
 * </ul>
 */
@Override
public boolean evaluate(R request, C context, String condition) {
	StopWatchLogger stopWatchLogger = new StopWatchLogger(logger);
	try {
		stopWatchLogger.start();

		String booleanCondition = "if (" + condition + ") {return true;} else {return false;}";

		logger.debug("Evaluating JEXL condition: " + booleanCondition);
		Expression expression = jexlEngine.createExpression(booleanCondition);

		Boolean result = (Boolean) expression.evaluate(populateJexlContext(request, context));
		return result.booleanValue();
	} finally {
		stopWatchLogger.debug("Evaluated JEXL expression");
		stopWatchLogger.stop();
	}
}
 
开发者ID:jramoyo,项目名称:flowee,代码行数:28,代码来源:AbstractJexlFilter.java

示例5: evaluate

import org.apache.commons.jexl2.Expression; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object evaluate(final String expression, final Map<String, ?> values) {
    
    ArgUtils.notEmpty(expression, "expression");
    ArgUtils.notNull(values, "values");
    
    if(logger.isDebugEnabled()) {
        logger.debug("Evaluating JEXL expression: {}", expression);
    }
    
    try {
        Expression expr = expressionCache.get(expression);
        if (expr == null) {
            expr = jexlEngine.createExpression(expression);
            expressionCache.put(expression, expr);
        }
        
        return expr.evaluate(new MapContext((Map<String, Object>) values));
        
    } catch(Exception ex) {
        throw new ExpressionEvaluationException(String.format("Evaluating [%s] script with JEXL failed.", expression), ex);
    }
}
 
开发者ID:mygreen,项目名称:xlsmapper,代码行数:25,代码来源:ExpressionLanguageJEXLImpl.java

示例6: evaluateComponent

import org.apache.commons.jexl2.Expression; //导入依赖的package包/类
protected Object evaluateComponent(int i, BindingEnv env) {
    Object component = components.get(i);
    Object result = null;
    if (component instanceof String) {
        result = component;
    } else if (component instanceof Expression) {
        result = ((Expression)component).evaluate(env);
    } else if (component instanceof Script) {
        result = ((Script)component).execute(env);
    } else if (component instanceof ValueFunction) {
        ((ValueFunction)component).setBindingEnv(env);
        return component;
    }  else {
        // Can't happen
        throw new EpiException("Internal state error in pattern evaluation");
    }
    if (result == null) {
        throw new NullResult();
    }
    return result;
}
 
开发者ID:epimorphics,项目名称:dclib,代码行数:22,代码来源:Pattern.java

示例7: evaluate

import org.apache.commons.jexl2.Expression; //导入依赖的package包/类
@Override
public Object evaluate(final String expression, final Map<String, Object> values) {
    
    Objects.requireNonNull(expression, "expression shoud not be null.");
    Objects.requireNonNull(values, "values shoud not be null.");
    
    if(logger.isDebugEnabled()) {
        logger.debug("Evaluating JEXL expression: {}", expression);
    }
    
    try {
        Expression expr = expressionCache.get(expression);
        if (expr == null) {
            expr = jexlEngine.createExpression(expression);
            expressionCache.put(expression, expr);
        }
        
        return expr.evaluate(new MapContext((Map<String, Object>) values));
        
    } catch(Exception ex) {
        throw new ExpressionEvaluationException(String.format("Evaluating [%s] script with JEXL failed.", expression), ex,
                expression, values);
    }
}
 
开发者ID:mygreen,项目名称:super-csv-annotation,代码行数:25,代码来源:ExpressionLanguageJEXLImpl.java

示例8: getFirstFromSintax

import org.apache.commons.jexl2.Expression; //导入依赖的package包/类
public static Mention getFirstFromSintax(Mention s, Expression expression, JexlContext jexlContext) {
    Mention t = null;
    int minDist = Integer.MAX_VALUE;
    Mention prev = s.prev();
    while (prev != null) {
        if (s.type == Dictionaries.MentionType.NOMINAL && Filter.sentenceDistance(s, prev) > Constants.SENTENCE_WINDOW) {break;}
        if (s.type == Dictionaries.MentionType.PRONOMINAL && Filter.sentenceDistance(s, prev) > 3) {break;}
                    
        if (s != prev && _filterAgree(s, prev, expression, jexlContext)) {
            int dist = s.node.minDistance(prev.node);
            if (t == null || dist < minDist) {
                t = prev;
                minDist = dist;
            }
        }
        prev = prev.prev();
    }
    return t;
}
 
开发者ID:aznotins,项目名称:LVCoref,代码行数:20,代码来源:MentionBrowser.java

示例9: _resolveAllFromSameSentence

import org.apache.commons.jexl2.Expression; //导入依赖的package包/类
private static void _resolveAllFromSameSentence(Document d, String filter, String comment) {        
    JexlEngine jexl = new JexlEngine();
    jexl.setSilent(JEXL_SILENT);
    jexl.setLenient(JEXL_LENIENT);
    jexl.setDebug(JEXL_DBG);
    Expression expression = jexl.createExpression(filter);
    JexlContext jexlContext = new MapContext();
    jexlContext.set("Filter", Filter.class);
    for (Mention s: d.mentions) {
        jexlContext.set("s", s);
        List<Mention> tt = MentionBrowser.getAllFromSameSentence(s, expression, jexlContext);      
        for (Mention t : tt) {
            _resolve(d, s, t, comment);
        }
        
    }
}
 
开发者ID:aznotins,项目名称:LVCoref,代码行数:18,代码来源:Resolve.java

示例10: parseExpression

import org.apache.commons.jexl2.Expression; //导入依赖的package包/类
/**
 * Parses the given experssion to a Jexl expression. This supports
 * date parsing.
 *
 * @param expr the Jexl expression
 * @return parsed Jexl expression or null in case of parse error
 */
public static Expression parseExpression(String expr) {
  if (expr == null) return null;
  
  try {
    // Translate any date object into a long, dates must be specified as 20-03-2016T00:00:00Z
    Matcher matcher = datePattern.matcher(expr);
    if (matcher.find()) {
      String date = matcher.group();
      
      // Parse the thing and get epoch!
      Date parsedDate = DateUtils.parseDateStrictly(date, new String[] {"yyyy-MM-dd'T'HH:mm:ss'Z'"});
      long time = parsedDate.getTime();
      
      // Replace in the original expression
      expr = expr.replace(date, Long.toString(time));
    }
    
    JexlEngine jexl = new JexlEngine();
    jexl.setSilent(true);
    jexl.setStrict(true);
    return jexl.createExpression(expr);
  } catch (Exception e) {
    LOG.error(e.getMessage());
  }
  
  return null;
}
 
开发者ID:jorcox,项目名称:GeoCrawler,代码行数:35,代码来源:JexlUtil.java

示例11: evaluate

import org.apache.commons.jexl2.Expression; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Object evaluate(final String expression, final Map<String, ?> values) throws ExpressionEvaluationException {
    LOG.debug("Evaluating JEXL expression: {1}", expression);
    try {
        Expression expr = expressionCache.get(expression);
        if (expr == null) {
            expr = jexl.createExpression(expression);
            expressionCache.put(expression, expr);
        }
        return expr.evaluate(new MapContext((Map<String, Object>) values));
    } catch (final Exception ex) {
        throw new ExpressionEvaluationException("Evaluating JEXL expression failed: " + expression, ex);
    }
}
 
开发者ID:sebthom,项目名称:oval,代码行数:15,代码来源:ExpressionLanguageJEXLImpl.java

示例12: getDataByExpression

import org.apache.commons.jexl2.Expression; //导入依赖的package包/类
@Override
public <T> T getDataByExpression(String expression) {
    Expression e;
    try {
        e = jexl.createExpression(expression);
    } catch (NullPointerException ex) {
        logger.log(Level.SEVERE, String.format("Error evaluating expresion %s", expression), ex);
        return null;
    }
    @SuppressWarnings("unchecked")
    T data = (T) e.evaluate(runtimeContext);

    return data;
}
 
开发者ID:carlos-verdes,项目名称:scxml-java,代码行数:15,代码来源:JexlFSMContext.java

示例13: evaluateConditionGuardExpresion

import org.apache.commons.jexl2.Expression; //导入依赖的package包/类
@Override
public boolean evaluateConditionGuardExpresion(String expression) {
    if (logger.isLoggable(Level.FINEST)) {
        logger.log(Level.FINEST, "evaluateConditionGuardExpresion({0})", new Object[]{expression});
        logger.log(Level.FINEST, "" + this.runtimeContext.get("breadcrumb"));
    }
    Expression e = jexl.createExpression(expression);
    Boolean result = (Boolean) e.evaluate(runtimeContext);

    return result;
}
 
开发者ID:carlos-verdes,项目名称:scxml-java,代码行数:12,代码来源:JexlFSMContext.java

示例14: getDataByExpression

import org.apache.commons.jexl2.Expression; //导入依赖的package包/类
@Override
public <T> T getDataByExpression(String expression) {
    Expression e;

    try {
        e = getEngineInstance().createExpression(expression);
    } catch (NullPointerException ex) {
        logger.log(Level.SEVERE, String.format("Error evaluating expresion %s", expression), ex);
        return null;
    }
    @SuppressWarnings("unchecked")
    T data = (T) e.evaluate(this.innerContext);

    return data;
}
 
开发者ID:carlos-verdes,项目名称:scxml-java,代码行数:16,代码来源:JexlMapFSMContextInstance.java

示例15: testJexl

import org.apache.commons.jexl2.Expression; //导入依赖的package包/类
public void testJexl() {
    JexlEngine engine = new JexlEngine();
    
    Map<String, Object> values = new HashMap<String, Object>();
    values.put("a", 12);
    values.put("b", "abcde");
    values.put("c", new Test());
    values.put("$row", new Row(42));
    
    Expression expression = engine.createExpression("'I see ' + $row.bnode");
    
    Object result = expression.evaluate(new MapContext(values));
    
    System.out.println(" -> " + result);
}
 
开发者ID:epimorphics,项目名称:dclib,代码行数:16,代码来源:Temp.java


注:本文中的org.apache.commons.jexl2.Expression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。