public static <T extends NamedElement> List<T> getIncludedElements(StringFilter filter, List<T> elements) { List<T> included = new ArrayList<T>(); for (T element : elements) { if (filter.include(element.getName())) { included.add(element); } } return included; }
/** * Remove any Strings from the collection that do not match the filter * * @deprecated */ @Deprecated public static List<String> filter(Collection<String> strings, StringFilter filter) { List<String> excluded = new ArrayList<String>(); Iterator<String> itr = strings.iterator(); while (itr.hasNext()) { String string = itr.next(); if (!filter.include(string)) { excluded.add(string); itr.remove(); } } return excluded; }
/** * Remove elements from the list that should not be there */ public static <T extends NamedElement> List<T> filterElements(List<T> elements, StringFilter filter) { // No filter, nothing to do if (filter == null) { return Collections.<T> emptyList(); } // Make sure we are configured correctly Assert.notNull(elements, "elements is null"); // Iterate over the elements, removing elements that shouldn't be there List<T> excluded = new ArrayList<T>(); Iterator<T> itr = elements.iterator(); while (itr.hasNext()) { T element = itr.next(); String name = element.getName(); if (!filter.include(name)) { excluded.add(element); itr.remove(); } } return excluded; }