@Override public SortedSet<E> tailSet(final E fromElement) { final SortedSet<E> tail = decorated().tailSet(fromElement); return new PredicatedSortedSet<>(tail, predicate); }
/** * Returns a predicated (validating) sorted set backed by the given sorted 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 sorted set to predicate, must not be null * @param predicate the predicate for the sorted set, must not be null * @return a predicated sorted set backed by the given sorted set * @throws NullPointerException if the set or predicate is null */ public static <E> SortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate) { return PredicatedSortedSet.predicatedSortedSet(set, predicate); }
/** * Gets the navigable set being decorated. * * @return the decorated navigable set */ @Override protected NavigableSet<E> decorated() { return (NavigableSet<E>) super.decorated(); }
/** * Factory method to create a predicated (validating) sorted 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 sorted set. * @throws NullPointerException if set or predicate is null * @throws IllegalArgumentException if the set contains invalid elements * @since 4.0 */ public static <E> PredicatedSortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate) { return new PredicatedSortedSet<>(set, predicate); }
@Override public E first() { return decorated().first(); }
@Override public SortedSet<E> headSet(final E toElement) { final SortedSet<E> head = decorated().headSet(toElement); return new PredicatedSortedSet<>(head, predicate); }
@Override public Comparator<? super E> comparator() { return decorated().comparator(); }
@Override public SortedSet<E> subSet(final E fromElement, final E toElement) { final SortedSet<E> sub = decorated().subSet(fromElement, toElement); return new PredicatedSortedSet<>(sub, predicate); }
@Override public E last() { return decorated().last(); }