/** * Scans the itemId and all its children for which items should be included * when filtering. All items which passes the filters are included. * Additionally all items that have a child node that should be included are * also themselves included. * * @param itemId * @param includedItems * @return true if the itemId should be included in the filtered container. */ private boolean filterIncludingParents(Object itemId, HashSet<Object> includedItems) { boolean toBeIncluded = passesFilters(itemId); LinkedList<Object> childList = children.get(itemId); if (childList != null) { for (Object childItemId : children.get(itemId)) { toBeIncluded |= filterIncludingParents(childItemId, includedItems); } } if (toBeIncluded) { includedItems.add(itemId); } return toBeIncluded; }
if (filterIncludingParents(rootId, includedItems)) { filteredRoots.add(rootId); addFilteredChildrenRecursively(rootId, includedItems);