/** * * @param source input collection * @param target collection containing filtered items * @param filter * @param <T> item type * @param <C> collection type * @param <E> * @return target * @throws E */ public static <T, C extends Collection<T>, E extends Throwable> C filter(Collection<T> source, C target, Filter<T,E> filter) throws E { for (T item : source) { if (filter.execute(item)) { target.add(item); } } return target; } }