/** * Factory method to create a predicated (validating) navigable set. * <p> * If there are any elements already in the set being decorated, they * are validated. * * @param <E> the element type * @param set the set to decorate, must not be null * @param predicate the predicate to use for validation, must not be null * @return a new predicated navigable set. * @throws NullPointerException if set or predicate is null * @throws IllegalArgumentException if the set contains invalid elements * @since 4.0 */ public static <E> PredicatedNavigableSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate) { return new PredicatedNavigableSet<>(set, predicate); }
@Override public NavigableSet<E> subSet(final E fromElement, final boolean fromInclusive, final E toElement, final boolean toInclusive) { final NavigableSet<E> sub = decorated().subSet(fromElement, fromInclusive, toElement, toInclusive); return predicatedNavigableSet(sub, predicate); }
@Override public E higher(final E e) { return decorated().higher(e); }
/** * Returns a predicated (validating) navigable set backed by the given navigable set. * <p> * Only objects that pass the test in the given predicate can be added to the set. * Trying to add an invalid object results in an IllegalArgumentException. * It is important not to use the original set after invoking this method, * as it is a backdoor for adding invalid objects. * * @param <E> the element type * @param set the navigable set to predicate, must not be null * @param predicate the predicate for the navigable set, must not be null * @return a predicated navigable set backed by the given navigable set * @throws NullPointerException if the set or predicate is null * @since 4.1 */ public static <E> SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate) { return PredicatedNavigableSet.predicatedNavigableSet(set, predicate); }
@Override public E floor(final E e) { return decorated().floor(e); }
@Override public NavigableSet<E> descendingSet() { return predicatedNavigableSet(decorated().descendingSet(), predicate); }
@Override public E ceiling(final E e) { return decorated().ceiling(e); }
@Override public NavigableSet<E> headSet(final E toElement, final boolean inclusive) { final NavigableSet<E> head = decorated().headSet(toElement, inclusive); return predicatedNavigableSet(head, predicate); }
@Override public Iterator<E> descendingIterator() { return decorated().descendingIterator(); }
@Override public NavigableSet<E> tailSet(final E fromElement, final boolean inclusive) { final NavigableSet<E> tail = decorated().tailSet(fromElement, inclusive); return predicatedNavigableSet(tail, predicate); }
@Override public E lower(final E e) { return decorated().lower(e); }
@Override public E pollFirst() { return decorated().pollFirst(); }
@Override public E pollLast() { return decorated().pollLast(); }