public static int getMatchingIndex(String spelExpression, ListMultimap<String, String> values) throws NoSuchElementException { // Compile the expression final ExpressionParser parser = new SpelExpressionParser(); final Expression exp = parser.parseExpression(spelExpression); // Recursively check all levels, defaulting to the first element return getMatchingIndex(exp, values, 0); }
public static int getMatchingIndex(String spelExpression, ListMultimap<String, String> values) throws NoSuchElementException { // Compile the expression final ExpressionParser parser = new SpelExpressionParser(); final Expression exp = parser.parseExpression(spelExpression); // Recursively check all levels, defaulting to the first element return getMatchingIndex(exp, values, 0); }
private static int getMatchingIndex(Expression exp, ListMultimap<String, String> valuesByName, int depth) throws NoSuchElementException { // Build the context with values from all the attributes at the current depth final StandardEvaluationContext context = new StandardEvaluationContext(); int maxDepth = 0; for (String name : valuesByName.keySet()) { List<String> values = valuesByName.get(name); // Keep track of the largest depth maxDepth = Math.max(maxDepth, values.size()); // Skip the variable if there are no values are the current depth if (values.size() < depth + 1) { continue; } // Store the value for the current depth in the context context.setVariable(name, values.get(depth)); } // Evaluate our expression try { if (exp.getValue(context, Boolean.class)) { return depth; } } catch (Exception e) { LOG.error("Failed to evaluate expression {}. Msg: {}", exp.getExpressionString(), e.getMessage()); throw new NoSuchElementException(); } if (maxDepth > depth) { // Recurse return getMatchingIndex(exp, valuesByName, depth+1); } throw new NoSuchElementException(); }
private static int getMatchingIndex(Expression exp, ListMultimap<String, String> valuesByName, int depth) throws NoSuchElementException { // Build the context with values from all the attributes at the current depth final StandardEvaluationContext context = new StandardEvaluationContext(); int maxDepth = 0; for (String name : valuesByName.keySet()) { List<String> values = valuesByName.get(name); // Keep track of the largest depth maxDepth = Math.max(maxDepth, values.size()); // Skip the variable if there are no values are the current depth if (values.size() < depth + 1) { continue; } // Store the value for the current depth in the context context.setVariable(name, values.get(depth)); } // Evaluate our expression try { if (exp.getValue(context, Boolean.class)) { return depth; } } catch (Exception e) { LOG.error("Failed to evaluate expression {}. Msg: {}", exp.getExpressionString(), e.getMessage()); throw new NoSuchElementException(); } if (maxDepth > depth) { // Recurse return getMatchingIndex(exp, valuesByName, depth+1); } throw new NoSuchElementException(); }
ResponseHandlingUtils.getMatchingIndex(rule, elementValues);
ResponseHandlingUtils.getMatchingIndex(rule, elementValues);
if (attributeValues.size() > 1 && attrib.getIndexOf() != null) { try { int index = ResponseHandlingUtils.getMatchingIndex(attrib.getIndexOf(), elementValues); valueAsString = attributeValues.get(index); } catch (NoSuchElementException e) {
if (attributeValues.size() > 1 && attrib.getIndexOf() != null) { try { int index = ResponseHandlingUtils.getMatchingIndex(attrib.getIndexOf(), elementValues); valueAsString = attributeValues.get(index); } catch (NoSuchElementException e) {