@Override public boolean add(final T e) { if (filter.appliesTo(e)) { return backingCollection.add(e); } return false; }
/** * Filter a list of entities through a predicate. If the the predicate applies the entity will be * included. * * @param predicate * @param candidates * @return a subset of the actual list of candidates */ public List<T> apply(Predicate<T> predicate, List<T> candidates) { List<T> filtered = new ArrayList<T>(candidates.size()); for (T entity : candidates) { if (predicate.appliesTo(entity)) filtered.add(entity); } return filtered; }