/** * Get a set of books that satisfy the condition imposed by the filter. * * @param filter the condition on which to select books * @return the set of matching books */ public BookSet filter(Filter<Book> filter) { // create a copy of the list and // remove everything that fails the test. BookSet listSet = (BookSet) clone(); Iterator<Book> iter = listSet.iterator(); while (iter.hasNext()) { Book obj = iter.next(); if (!filter.test(obj)) { iter.remove(); } } return listSet; }
if (filter == null || filter.test(key)) { add(key, value);