Exemplo n.º 1
0
  /**
   * Sets JEXL context variables' values and returns {@code this}.
   *
   * @param vals Set of tuples representing JEXL context to be bound. First element in the tuple
   *     represents the name and the second element represents its value in the context.
   * @return This predicate so that this call can be chained.
   */
  public GridJexlPredicate2<T1, T2> with(GridTuple2<String, Object>... vals) {
    for (GridTuple2<String, Object> t : vals) {
      map.put(t.get1(), t.get2());
    }

    return this;
  }
Exemplo n.º 2
0
  /** {@inheritDoc} */
  @Override
  public boolean apply(@Nullable T1 t1, @Nullable T2 t2) {
    lazyCompile();

    if (expr != null) {
      JexlContext ctx = new MapContext();

      ctx.set(var1, t1);
      ctx.set(var2, t2);

      for (Map.Entry<String, Object> e : map.entrySet()) {
        ctx.set(e.getKey(), e.getValue());
      }

      try {
        Object obj = expr.evaluate(ctx);

        if (obj instanceof Boolean) {
          return (Boolean) obj;
        }
      } catch (Exception ex) {
        throw F.wrap(ex);
      }
    }

    return false;
  }
Exemplo n.º 3
0
  /**
   * Sets JEXL context variable value and returns {@code this}.
   *
   * @param var Name of the variable in JEXL context (new or existing).
   * @param val Value to be set or overridden in JEXL context.
   * @return This predicate so that this call can be chained.
   */
  public GridJexlPredicate2<T1, T2> with(String var, @Nullable Object val) {
    A.notNull(var, "var");

    map.put(var, val);

    return this;
  }