org.apache.commons.jexl2.MapContext.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(241)

本文整理了Java中org.apache.commons.jexl2.MapContext.<init>()方法的一些代码示例,展示了MapContext.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MapContext.<init>()方法的具体详情如下:
包路径:org.apache.commons.jexl2.MapContext
类名称:MapContext
方法名:<init>

MapContext.<init>介绍

[英]Creates a MapContext on an automatically allocated underlying HashMap.
[中]在自动分配的基础HashMap上创建MapContext。

代码示例

代码示例来源:origin: jmxtrans/jmxtrans

/**
 * Format the name for the given result.
 *
 * @param result - the result of a JMX query.
 * @return String - the formatted string resulting from the expression, or null if the formatting fails.
 */
@Override
public String formatName(Result result) {
  String formatted;
  JexlContext context = new MapContext();
  this.populateContext(context, result);
  try {
    formatted = (String) this.parsedExpr.evaluate(context);
  } catch (JexlException jexlExc) {
    LOG.error("error applying JEXL expression to query results", jexlExc);
    formatted = null;
  }
  return formatted;
}

代码示例来源:origin: traccar/traccar

private MapContext prepareContext(Position position) {
  MapContext result = new MapContext();
  if (mapDeviceAttributes) {
    Device device = Context.getIdentityManager().getById(position.getDeviceId());
    if (device != null) {
      for (Object key : device.getAttributes().keySet()) {
        result.set((String) key, device.getAttributes().get(key));
      }
    }
  }
  Set<Method> methods = new HashSet<>(Arrays.asList(position.getClass().getMethods()));
  methods.removeAll(Arrays.asList(Object.class.getMethods()));
  for (Method method : methods) {
    if (method.getName().startsWith("get") && method.getParameterTypes().length == 0) {
      String name = Character.toLowerCase(method.getName().charAt(3)) + method.getName().substring(4);
      try {
        if (!method.getReturnType().equals(Map.class)) {
          result.set(name, method.invoke(position));
        } else {
          for (Object key : ((Map) method.invoke(position)).keySet()) {
            result.set((String) key, ((Map) method.invoke(position)).get(key));
          }
        }
      } catch (IllegalAccessException | InvocationTargetException error) {
        LOGGER.warn("Attribute reflection error", error);
      }
    }
  }
  return result;
}

代码示例来源:origin: azkaban/azkaban

try {
 final Expression e = jexl.createExpression(innerExpression);
 result = e.evaluate(new MapContext());
} catch (final JexlException e) {
 throw new IllegalArgumentException("Expression " + value

代码示例来源:origin: org.apache.commons/commons-configuration2

/**
 * Creates a new {@code JexlContext} and initializes it with the variables
 * managed by this Lookup object.
 *
 * @return the newly created context
 */
private JexlContext createContext()
{
  final JexlContext ctx = new MapContext();
  initializeContext(ctx);
  return ctx;
}

代码示例来源:origin: neuland/jade4j

public Object evaluateExpression(String expression, JadeModel model) throws ExpressionException {
  try {
    expression = removeVar(expression);
    if (isplusplus.matcher(expression).find()) {
      expression = convertPlusPlusExpression(expression);
    }
    if (isminusminus.matcher(expression).find()) {
      expression = convertMinusMinusExpression(expression);
    }
    Script e = jexl.createScript(expression);
    Object evaluate = e.execute(new MapContext(model));
    return evaluate;
  } catch (Exception e) {
    throw new ExpressionException(expression, e);
  }
}

代码示例来源:origin: stackoverflow.com

// create context
JexlContext jc = new MapContext();
context.set("current", someObject);
context.set("previous", anotherObject);

// create expression
String jexlExp = "current.preTaxProfit > (previous.preTaxProfit * 1.10)";
Expression e = jexl.createExpression(jexlExp);

// evaluate
Object result = e.evaluate(jc);

代码示例来源:origin: org.apache.commons/org.motechproject.org.apache.commons.configuration

/**
 * Creates a new {@code JexlContext} and initializes it with the variables
 * managed by this Lookup object.
 *
 * @return the newly created context
 */
private JexlContext createContext()
{
  JexlContext ctx = new MapContext();
  initializeContext(ctx);
  return ctx;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-configuration

/**
 * Creates a new {@code JexlContext} and initializes it with the variables
 * managed by this Lookup object.
 *
 * @return the newly created context
 */
private JexlContext createContext()
{
  JexlContext ctx = new MapContext();
  initializeContext(ctx);
  return ctx;
}

代码示例来源:origin: OpenNMS/newts

@Override
  public double apply(double... ds) {
    JexlContext jc = new MapContext();
    for(int i = 0; i < labels.length; i++) {
      jc.set(labels[i], ds[i]);
    }
    return ((Number)expr.evaluate(jc)).doubleValue();
    
  }
};

代码示例来源:origin: net.sf.jxls/jxls-core

public Object evaluate() throws Exception {
  if (beans != null && !beans.isEmpty()) {
    JexlContext context = new MapContext(beans);
    Object ret = jexlExpresssion.evaluate(context);
    if (aggregateFunction != null) {
      return calculateAggregate(aggregateFunction, aggregateField, ret);
    }
    return ret;
  }
  return expression;
}

代码示例来源:origin: stackoverflow.com

Map<String, Object> functions=new HashMap<String, Object>(); 
 // creating namespace for function eg. 'math' will be treated as Math.class
 functions.put( "math",Math.class);
 JexlEngine jexl = new JexlEngine();
 //setting custom functions
 jexl.setFunctions( functions);
 // in expression 'pow' is a function name from 'math' wich is Math.class
 Expression expression = jexl.createExpression( "math:pow(2,3)" );   
 expression.evaluate(new MapContext());

代码示例来源:origin: org.apache.aries.blueprint/org.apache.aries.blueprint.jexl.evaluator

public Object evaluate(String expression, Map<String, Object> properties) {
  try {
    JexlEngine engine = new JexlEngine();
    MapContext context = new MapContext(properties);
    Expression exp = engine.createExpression(expression);
    return exp.evaluate(context);
  } catch (Exception e) {
    LOGGER.info("Could not evaluate expression: {}", expression);
    LOGGER.info("Exception:", e);
    return null;
  }
}

代码示例来源:origin: OpenNMS/opennms

public static String evaluateToString(JasperReport report, JRExpression expression) {
    Objects.requireNonNull(report);
    Objects.requireNonNull(expression);
    SubreportExpressionVisitor visitor = new SubreportExpressionVisitor(report);
    String string = visitor.visit(expression);
    if (string != null) {
      JexlEngine engine = new JexlEngine();
      return (String) engine.createExpression(string).evaluate(new MapContext());
    }
    return null;
  }
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {
 long a = 5;
 long b = 4;
 String theExpression = "a * b";
 JexlEngine jexl = new JexlEngine();
 Expression e = jexl.createExpression(theExpression);
 JexlContext context = new MapContext();
 context.set("a", a);
 context.set("b", b);
 Long result = (Long) e.evaluate(context);
 System.out.println("The answer : " + result);
}

代码示例来源:origin: stackoverflow.com

JexlEngine jexl = new JexlEngine();
 Expression expression = jexl.createExpression("value 1 = #value1 value 2 = #value2");
 int[] values = {1, 2};
 JexlContext context = new MapContext();
 for (int i = 0; i <  values.length; i++) {
   context.set("#value" + (i + 1), values[i]);
 }
 String result = (String)expression.evaluate(context);

代码示例来源:origin: com.github.sebhoss.contract/contract-jexl

@Override
public ContractContext createContext(final Object instance, final Object[] arguments, final String[] parameterNames) {
  final JexlContext context = new MapContext();
  for (int index = 0; index < arguments.length; index++) {
    context.set(parameterNames[index], arguments[index]);
  }
  context.set(Clause.THIS, instance);
  return new JEXLContractContext(context, jexlEngine);
}

代码示例来源:origin: stackoverflow.com

JexlEngine jexl = new JexlBuilder().create();
   JxltEngine jxlt = jexl.createJxltEngine();
   JxltEngine.Expression expr = jxlt.createExpression(expression);
   JexlContext context = new MapContext();
   context.set("utilClass", new UtilClass());context.set("car", new Car())

代码示例来源:origin: SheetJS/jxls

public XLSReadStatus read(XLSRowCursor cursor, Map beans) {
  readStatus.clear();
  JexlContext context = new MapContext(beans);
  ExpressionCollectionParser parser = new ExpressionCollectionParser(context, items + ";", true);
  Collection itemsCollection = parser.getCollection();
  while (!loopBreakCheck.isCheckSuccessful(cursor)) {
    createNewCollectionItem(itemsCollection, beans);
    readInnerBlocks(cursor, beans);
  }
  cursor.moveBackward();
  return readStatus;
}

代码示例来源:origin: org.jdbi/jdbi

@Test
public void testJexl() throws Exception
{
  JexlEngine engine = new JexlEngine();
  Object topping = engine.createExpression("breakfast.waffle.topping")
              .evaluate(new MapContext(ImmutableMap.<String, Object>of("breakfast", new Breakfast())));
  assertThat(topping, instanceOf(String.class));
  assertThat((String) topping, equalTo("syrup"));
}

代码示例来源:origin: org.kill-bill.commons/killbill-jdbi

@Test
public void testJexl() throws Exception
{
  JexlEngine engine = new JexlEngine();
  Object topping = engine.createExpression("breakfast.waffle.topping")
              .evaluate(new MapContext(ImmutableMap.<String, Object>of("breakfast", new Breakfast())));
  assertThat(topping, instanceOf(String.class));
  assertThat((String) topping, equalTo("syrup"));
}

相关文章