(Set<E> unfiltered, Predicate<? super E> predicate)
| 861 | |
| 862 | |
| 863 | public static <E> Set<E> filter(Set<E> unfiltered, Predicate<? super E> predicate) { |
| 864 | if (unfiltered instanceof SortedSet) { |
| 865 | return filter((SortedSet<E>) unfiltered, predicate); |
| 866 | } |
| 867 | if (unfiltered instanceof FilteredSet) { |
| 868 | // Support clear(), removeAll(), and retainAll() when filtering a filtered |
| 869 | // collection. |
| 870 | FilteredSet<E> filtered = (FilteredSet<E>) unfiltered; |
| 871 | Predicate<E> combinedPredicate = Predicates.<E>and(filtered.predicate, predicate); |
| 872 | return new FilteredSet<E>((Set<E>) filtered.unfiltered, combinedPredicate); |
| 873 | } |
| 874 | return new FilteredSet<E>(checkNotNull(unfiltered), checkNotNull(predicate)); |
| 875 | } |
| 876 | |
| 877 | private static class FilteredSet<E> extends FilteredCollection<E> |
| 878 | implements Set<E> { |
no test coverage detected