Class ForwardingNavigableSet<E>

  • All Implemented Interfaces:
    Iterable<E>, Collection<E>, NavigableSet<E>, Set<E>, SortedSet<E>
    Direct Known Subclasses:
    ForwardingNavigableSet.StandardDescendingSet

    @GwtIncompatible
    public abstract class ForwardingNavigableSet<E>
    extends ForwardingSortedSet<E>
    implements NavigableSet<E>
    A navigable set which forwards all its method calls to another navigable set. Subclasses should override one or more methods to modify the behavior of the backing set as desired per the decorator pattern.

    Warning: The methods of ForwardingNavigableSet forward indiscriminately to the methods of the delegate. For example, overriding ForwardingCollection.add(E) alone will not change the behavior of ForwardingCollection.addAll(java.util.Collection<? extends E>), which can lead to unexpected behavior. In this case, you should override addAll as well, either providing your own implementation, or delegating to the provided standardAddAll method.

    default method warning: This class does not forward calls to default methods. Instead, it inherits their default implementations. When those implementations invoke methods, they invoke methods on the ForwardingNavigableSet.

    Each of the standard methods uses the set's comparator (or the natural ordering of the elements, if there is no comparator) to test element equality. As a result, if the comparator is not consistent with equals, some of the standard implementations may violate the Set contract.

    The standard methods and the collection views they return are not guaranteed to be thread-safe, even when all of the methods that they depend on are thread-safe.

    Since:
    12.0
    Author:
    Louis Wasserman
    • Method Detail

      • delegate

        protected abstract NavigableSet<Edelegate()
        Description copied from class: ForwardingObject
        Returns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such as ForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.
        Specified by:
        delegate in class ForwardingSortedSet<E>
      • lower

        public E lower(E e)
        Description copied from interface: java.util.NavigableSet
        Returns the greatest element in this set strictly less than the given element, or null if there is no such element.
        Specified by:
        lower in interface NavigableSet<E>
        Parameters:
        e - the value to match
        Returns:
        the greatest element less than e, or null if there is no such element
      • floor

        public E floor(E e)
        Description copied from interface: java.util.NavigableSet
        Returns the greatest element in this set less than or equal to the given element, or null if there is no such element.
        Specified by:
        floor in interface NavigableSet<E>
        Parameters:
        e - the value to match
        Returns:
        the greatest element less than or equal to e, or null if there is no such element
      • ceiling

        public E ceiling(E e)
        Description copied from interface: java.util.NavigableSet
        Returns the least element in this set greater than or equal to the given element, or null if there is no such element.
        Specified by:
        ceiling in interface NavigableSet<E>
        Parameters:
        e - the value to match
        Returns:
        the least element greater than or equal to e, or null if there is no such element
      • higher

        public E higher(E e)
        Description copied from interface: java.util.NavigableSet
        Returns the least element in this set strictly greater than the given element, or null if there is no such element.
        Specified by:
        higher in interface NavigableSet<E>
        Parameters:
        e - the value to match
        Returns:
        the least element greater than e, or null if there is no such element
      • pollFirst

        public E pollFirst()
        Description copied from interface: java.util.NavigableSet
        Retrieves and removes the first (lowest) element, or returns null if this set is empty.
        Specified by:
        pollFirst in interface NavigableSet<E>
        Returns:
        the first element, or null if this set is empty
      • pollLast

        public E pollLast()
        Description copied from interface: java.util.NavigableSet
        Retrieves and removes the last (highest) element, or returns null if this set is empty.
        Specified by:
        pollLast in interface NavigableSet<E>
        Returns:
        the last element, or null if this set is empty
      • descendingSet

        public NavigableSet<EdescendingSet()
        Description copied from interface: java.util.NavigableSet
        Returns a reverse order view of the elements contained in this set. The descending set is backed by this set, so changes to the set are reflected in the descending set, and vice-versa. If either set is modified while an iteration over either set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined.

        The returned set has an ordering equivalent to Collections.reverseOrder(comparator()). The expression s.descendingSet().descendingSet() returns a view of s essentially equivalent to s.

        Specified by:
        descendingSet in interface NavigableSet<E>
        Returns:
        a reverse order view of this set
      • subSet

        public NavigableSet<EsubSet(E fromElement,
                                      boolean fromInclusive,
                                      E toElement,
                                      boolean toInclusive)
        Description copied from interface: java.util.NavigableSet
        Returns a view of the portion of this set whose elements range from fromElement to toElement. If fromElement and toElement are equal, the returned set is empty unless fromInclusive and toInclusive are both true. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.

        The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.

        Specified by:
        subSet in interface NavigableSet<E>
        Parameters:
        fromElement - low endpoint of the returned set
        fromInclusive - true if the low endpoint is to be included in the returned view
        toElement - high endpoint of the returned set
        toInclusive - true if the high endpoint is to be included in the returned view
        Returns:
        a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive
      • headSet

        public NavigableSet<EheadSet(E toElement,
                                       boolean inclusive)
        Description copied from interface: java.util.NavigableSet
        Returns a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.

        The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.

        Specified by:
        headSet in interface NavigableSet<E>
        Parameters:
        toElement - high endpoint of the returned set
        inclusive - true if the high endpoint is to be included in the returned view
        Returns:
        a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement
      • tailSet

        public NavigableSet<EtailSet(E fromElement,
                                       boolean inclusive)
        Description copied from interface: java.util.NavigableSet
        Returns a view of the portion of this set whose elements are greater than (or equal to, if inclusive is true) fromElement. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.

        The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.

        Specified by:
        tailSet in interface NavigableSet<E>
        Parameters:
        fromElement - low endpoint of the returned set
        inclusive - true if the low endpoint is to be included in the returned view
        Returns:
        a view of the portion of this set whose elements are greater than or equal to fromElement