/** * Filters (removes elements from) the given {@link Iterable} using the * given filter. * * @param <T> the type of object being filtered * @param unfiltered the iterable to filter; can be <code>null</code> * @param filter the filter to apply; can be <code>null</code> for none * @return a non-<code>null</code> list */ public static <T> List<T> filter(final Iterable<? extends T> unfiltered, final Filter<T> filter) { final List<T> filtered = new ArrayList<T>(); if (unfiltered != null) { for (final T element : unfiltered) { if (filter == null || filter.include(element)) { filtered.add(element); } } } return filtered; }