@Test public void findPredicate() { final String PATH = "/content/dam/a"; final Map<String, String> input = new HashMap<>(); input.put("group.path", PATH); input.put("group.path.path", PATH); input.put("group.path.1_path", PATH); input.put("1_group.path", PATH); input.put("1_group.path.path", PATH); input.put("1_group.path.1_path", PATH); input.put("1_group.1_path", PATH); input.put("1_group.1_path.path", PATH); input.put("1_group.1_path.1_path", PATH); input.put("type", "dam:Asset"); final Map<String, String> expected = new HashMap<>(); expected.put("group.path", PATH); expected.put("group.path.path", PATH); expected.put("group.path.1_path", PATH); expected.put("1_group.path", PATH); expected.put("1_group.path.path", PATH); expected.put("1_group.path.1_path", PATH); expected.put("1_group.1_path", PATH); expected.put("1_group.1_path.path", PATH); expected.put("1_group.1_path.1_path", PATH); ValueMap actual = PredicateUtil.findPredicate(input, "path", "path"); assertTrue(expected.keySet().equals(actual.keySet())); }
public static ValueMap findPredicate(Map<String, String> queryBuilderParams, String predicateName, String predicateValueName) { if (predicateValueName == null) { predicateValueName = predicateName; } final ValueMap foundPredicates = new ValueMapDecorator(new HashMap<>()); final Pattern p = Pattern.compile("^((\\d+_)?group\\.)?(\\d+_)?" + predicateName + "(\\.((\\d+_)?" + predicateValueName + "))?$"); queryBuilderParams.keySet().stream() .filter(key -> p.matcher(key).matches()) .forEach(key -> foundPredicates.put(key, queryBuilderParams.get(key))); return foundPredicates; }
PredicateUtil { public static ValueMap findPredicate(Map<String, String> queryBuilderParams, String predicateName, String predicateValueName) { if (predicateValueName == null) { predicateValueName = predicateName; } final ValueMap foundPredicates = new ValueMapDecorator(new HashMap<>()); final Pattern p = Pattern.compile("^((\\d+_)?group\\.)?(\\d+_)?" + predicateName + "(\\.((\\d+_)?" + predicateValueName + "))?$"); queryBuilderParams.keySet().stream() .filter(key -> p.matcher(key).matches()) .forEach(key -> foundPredicates.put(key, queryBuilderParams.get(key))); return foundPredicates; } }
PredicateUtil { public static ValueMap findPredicate(Map<String, String> queryBuilderParams, String predicateName, String predicateValueName) { if (predicateValueName == null) { predicateValueName = predicateName; } final ValueMap foundPredicates = new ValueMapDecorator(new HashMap<>()); final Pattern p = Pattern.compile("^((\\d+_)?group\\.)?(\\d+_)?" + predicateName + "(\\.((\\d+_)?" + predicateValueName + "))?$"); queryBuilderParams.keySet().stream() .filter(key -> p.matcher(key).matches()) .forEach(key -> foundPredicates.put(key, queryBuilderParams.get(key))); return foundPredicates; } private  PredicateUtil(); }
PredicateUtil { public static ValueMap findPredicate(Map<String, String> queryBuilderParams, String predicateName, String predicateValueName) { if (predicateValueName == null) { predicateValueName = predicateName; } final ValueMap foundPredicates = new ValueMapDecorator(new HashMap<>()); final Pattern p = Pattern.compile("^((\\d+_)?group\\.)?(\\d+_)?" + predicateName + "(\\.((\\d+_)?" + predicateValueName + "))?$"); queryBuilderParams.keySet().stream() .filter(key -> p.matcher(key).matches()) .forEach(key -> foundPredicates.put(key, queryBuilderParams.get(key))); return foundPredicates; } private  PredicateUtil(); static String getParamFromQueryParams(final SlingHttpServletRequest request, final String parameterName); static boolean isOptionInInitialValues(OptionItem optionItem, ValueMap initialValues); static boolean isOptionInInitialValues(String value, ValueMap initialValues); static String getInitialValue(SlingHttpServletRequest request, Predicate predicate, String predicateValueName); static ValueMap getInitialValues(SlingHttpServletRequest request, Predicate predicate, String predicateValueName); static ValueMap findPredicate(Map<String, String> queryBuilderParams, String predicateName, String predicateValueName); }
PredicateUtil { public static ValueMap findPredicate(Map<String, String> queryBuilderParams, String predicateName, String predicateValueName) { if (predicateValueName == null) { predicateValueName = predicateName; } final ValueMap foundPredicates = new ValueMapDecorator(new HashMap<>()); final Pattern p = Pattern.compile("^((\\d+_)?group\\.)?(\\d+_)?" + predicateName + "(\\.((\\d+_)?" + predicateValueName + "))?$"); queryBuilderParams.keySet().stream() .filter(key -> p.matcher(key).matches()) .forEach(key -> foundPredicates.put(key, queryBuilderParams.get(key))); return foundPredicates; } private  PredicateUtil(); static String getParamFromQueryParams(final SlingHttpServletRequest request, final String parameterName); static boolean isOptionInInitialValues(OptionItem optionItem, ValueMap initialValues); static boolean isOptionInInitialValues(String value, ValueMap initialValues); static String getInitialValue(SlingHttpServletRequest request, Predicate predicate, String predicateValueName); static ValueMap getInitialValues(SlingHttpServletRequest request, Predicate predicate, String predicateValueName); static ValueMap findPredicate(Map<String, String> queryBuilderParams, String predicateName, String predicateValueName);  }