Class ForwardingNavigableSet<E extends @Nullable Object>
- java.lang.Object
-
- com.google.common.collect.ForwardingObject
-
- com.google.common.collect.ForwardingCollection<E>
-
- com.google.common.collect.ForwardingSet<E>
-
- com.google.common.collect.ForwardingSortedSet<E>
-
- com.google.common.collect.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 @Nullable Object> 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
ForwardingNavigableSetforward indiscriminately to the methods of the delegate. For example, overridingForwardingCollection.add(E)alone will not change the behavior ofForwardingCollection.addAll(java.util.Collection<? extends E>), which can lead to unexpected behavior. In this case, you should overrideaddAllas well, either providing your own implementation, or delegating to the providedstandardAddAllmethod.defaultmethod warning: This class does not forward calls todefaultmethods. Instead, it inherits their default implementations. When those implementations invoke methods, they invoke methods on theForwardingNavigableSet.Each of the
standardmethods 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 theSetcontract.The
standardmethods 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classForwardingNavigableSet.StandardDescendingSetA sensible implementation ofNavigableSet.descendingSet()in terms of the other methods ofNavigableSet, notably includingNavigableSet.descendingIterator().
-
Constructor Summary
Constructors Modifier Constructor Description protectedForwardingNavigableSet()Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Eceiling(E e)Returns the least element in this set greater than or equal to the given element, ornullif there is no such element.protected abstract NavigableSet<E>delegate()Returns the backing delegate instance that methods are forwarded to.Iterator<E>descendingIterator()Returns an iterator over the elements in this set, in descending order.NavigableSet<E>descendingSet()Returns a reverse order view of the elements contained in this set.Efloor(E e)Returns the greatest element in this set less than or equal to the given element, ornullif there is no such element.NavigableSet<E>headSet(E toElement, boolean inclusive)Returns a view of the portion of this set whose elements are less than (or equal to, ifinclusiveis true)toElement.Ehigher(E e)Returns the least element in this set strictly greater than the given element, ornullif there is no such element.Elower(E e)Returns the greatest element in this set strictly less than the given element, ornullif there is no such element.EpollFirst()Retrieves and removes the first (lowest) element, or returnsnullif this set is empty.EpollLast()Retrieves and removes the last (highest) element, or returnsnullif this set is empty.protected EstandardCeiling(E e)protected EstandardFirst()protected EstandardFloor(E e)A sensible definition offloor(E)in terms of thedescendingIteratormethod ofheadSet(Object, boolean).protected SortedSet<E>standardHeadSet(E toElement)A sensible definition ofForwardingSortedSet.headSet(Object)in terms of theheadSet(Object, boolean)method.protected EstandardHigher(E e)protected EstandardLast()protected EstandardLower(E e)A sensible definition oflower(E)in terms of thedescendingIteratormethod ofheadSet(Object, boolean).protected EstandardPollFirst()A sensible definition ofpollFirst()in terms of theiteratormethod.protected EstandardPollLast()A sensible definition ofpollLast()in terms of thedescendingIteratormethod.protected NavigableSet<E>standardSubSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)A sensible definition ofsubSet(Object, boolean, Object, boolean)in terms of theheadSetandtailSetmethods.protected SortedSet<E>standardSubSet(E fromElement, E toElement)A sensible definition ofForwardingSortedSet.subSet(Object, Object)in terms of thesubSet(Object, boolean, Object, boolean)method.protected SortedSet<E>standardTailSet(E fromElement)A sensible definition ofForwardingSortedSet.tailSet(Object)in terms of thetailSet(Object, boolean)method.NavigableSet<E>subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)Returns a view of the portion of this set whose elements range fromfromElementtotoElement.NavigableSet<E>tailSet(E fromElement, boolean inclusive)Returns a view of the portion of this set whose elements are greater than (or equal to, ifinclusiveis true)fromElement.-
Methods inherited from class com.google.common.collect.ForwardingSortedSet
comparator, first, headSet, last, standardContains, standardRemove, subSet, tailSet
-
Methods inherited from class com.google.common.collect.ForwardingSet
equals, hashCode, standardEquals, standardHashCode, standardRemoveAll
-
Methods inherited from class com.google.common.collect.ForwardingCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, standardAddAll, standardClear, standardContainsAll, standardIsEmpty, standardRetainAll, standardToArray, standardToArray, standardToString, toArray, toArray
-
Methods inherited from class com.google.common.collect.ForwardingObject
toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.NavigableSet
headSet, iterator, subSet, tailSet
-
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, size, toArray, toArray
-
Methods inherited from interface java.util.SortedSet
comparator, first, last, spliterator
-
-
-
-
Constructor Detail
-
ForwardingNavigableSet
protected ForwardingNavigableSet()
Constructor for use by subclasses.
-
-
Method Detail
-
delegate
protected abstract NavigableSet<E> delegate()
Description copied from class:ForwardingObjectReturns 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 asForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.- Specified by:
delegatein classForwardingSortedSet<E extends @Nullable Object>
-
lower
@CheckForNull public E lower(E e)
Description copied from interface:java.util.NavigableSetReturns the greatest element in this set strictly less than the given element, ornullif there is no such element.- Specified by:
lowerin interfaceNavigableSet<E extends @Nullable Object>- Parameters:
e- the value to match- Returns:
- the greatest element less than
e, ornullif there is no such element
-
standardLower
@CheckForNull protected E standardLower(E e)
A sensible definition oflower(E)in terms of thedescendingIteratormethod ofheadSet(Object, boolean). If you overrideheadSet(Object, boolean), you may wish to overridelower(E)to forward to this implementation.
-
floor
@CheckForNull public E floor(E e)
Description copied from interface:java.util.NavigableSetReturns the greatest element in this set less than or equal to the given element, ornullif there is no such element.- Specified by:
floorin interfaceNavigableSet<E extends @Nullable Object>- Parameters:
e- the value to match- Returns:
- the greatest element less than or equal to
e, ornullif there is no such element
-
standardFloor
@CheckForNull protected E standardFloor(E e)
A sensible definition offloor(E)in terms of thedescendingIteratormethod ofheadSet(Object, boolean). If you overrideheadSet(Object, boolean), you may wish to overridefloor(E)to forward to this implementation.
-
ceiling
@CheckForNull public E ceiling(E e)
Description copied from interface:java.util.NavigableSetReturns the least element in this set greater than or equal to the given element, ornullif there is no such element.- Specified by:
ceilingin interfaceNavigableSet<E extends @Nullable Object>- Parameters:
e- the value to match- Returns:
- the least element greater than or equal to
e, ornullif there is no such element
-
standardCeiling
@CheckForNull protected E standardCeiling(E e)
A sensible definition ofceiling(E)in terms of theiteratormethod oftailSet(Object, boolean). If you overridetailSet(Object, boolean), you may wish to overrideceiling(E)to forward to this implementation.
-
higher
@CheckForNull public E higher(E e)
Description copied from interface:java.util.NavigableSetReturns the least element in this set strictly greater than the given element, ornullif there is no such element.- Specified by:
higherin interfaceNavigableSet<E extends @Nullable Object>- Parameters:
e- the value to match- Returns:
- the least element greater than
e, ornullif there is no such element
-
standardHigher
@CheckForNull protected E standardHigher(E e)
A sensible definition ofhigher(E)in terms of theiteratormethod oftailSet(Object, boolean). If you overridetailSet(Object, boolean), you may wish to overridehigher(E)to forward to this implementation.
-
pollFirst
@CheckForNull public E pollFirst()
Description copied from interface:java.util.NavigableSetRetrieves and removes the first (lowest) element, or returnsnullif this set is empty.- Specified by:
pollFirstin interfaceNavigableSet<E extends @Nullable Object>- Returns:
- the first element, or
nullif this set is empty
-
standardPollFirst
@CheckForNull protected E standardPollFirst()
A sensible definition ofpollFirst()in terms of theiteratormethod. If you overrideForwardingCollection.iterator()you may wish to overridepollFirst()to forward to this implementation.
-
pollLast
@CheckForNull public E pollLast()
Description copied from interface:java.util.NavigableSetRetrieves and removes the last (highest) element, or returnsnullif this set is empty.- Specified by:
pollLastin interfaceNavigableSet<E extends @Nullable Object>- Returns:
- the last element, or
nullif this set is empty
-
standardPollLast
@CheckForNull protected E standardPollLast()
A sensible definition ofpollLast()in terms of thedescendingIteratormethod. If you overridedescendingIterator()you may wish to overridepollLast()to forward to this implementation.
-
standardFirst
protected E standardFirst()
-
standardLast
protected E standardLast()
-
descendingSet
public NavigableSet<E> descendingSet()
Description copied from interface:java.util.NavigableSetReturns 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 ownremoveoperation), the results of the iteration are undefined.The returned set has an ordering equivalent to
Collections.reverseOrder(comparator()). The expressions.descendingSet().descendingSet()returns a view ofsessentially equivalent tos.- Specified by:
descendingSetin interfaceNavigableSet<E extends @Nullable Object>- Returns:
- a reverse order view of this set
-
descendingIterator
public Iterator<E> descendingIterator()
Description copied from interface:java.util.NavigableSetReturns an iterator over the elements in this set, in descending order. Equivalent in effect todescendingSet().iterator().- Specified by:
descendingIteratorin interfaceNavigableSet<E extends @Nullable Object>- Returns:
- an iterator over the elements in this set, in descending order
-
subSet
public NavigableSet<E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)
Description copied from interface:java.util.NavigableSetReturns a view of the portion of this set whose elements range fromfromElementtotoElement. IffromElementandtoElementare equal, the returned set is empty unlessfromInclusiveandtoInclusiveare 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
IllegalArgumentExceptionon an attempt to insert an element outside its range.- Specified by:
subSetin interfaceNavigableSet<E extends @Nullable Object>- Parameters:
fromElement- low endpoint of the returned setfromInclusive-trueif the low endpoint is to be included in the returned viewtoElement- high endpoint of the returned settoInclusive-trueif 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, totoElement, exclusive
-
standardSubSet
@Beta protected NavigableSet<E> standardSubSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)
A sensible definition ofsubSet(Object, boolean, Object, boolean)in terms of theheadSetandtailSetmethods. In many cases, you may wish to overridesubSet(Object, boolean, Object, boolean)to forward to this implementation.
-
standardSubSet
protected SortedSet<E> standardSubSet(E fromElement, E toElement)
A sensible definition ofForwardingSortedSet.subSet(Object, Object)in terms of thesubSet(Object, boolean, Object, boolean)method. If you overridesubSet(Object, boolean, Object, boolean), you may wish to overrideForwardingSortedSet.subSet(Object, Object)to forward to this implementation.- Overrides:
standardSubSetin classForwardingSortedSet<E extends @Nullable Object>
-
headSet
public NavigableSet<E> headSet(E toElement, boolean inclusive)
Description copied from interface:java.util.NavigableSetReturns a view of the portion of this set whose elements are less than (or equal to, ifinclusiveis 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
IllegalArgumentExceptionon an attempt to insert an element outside its range.- Specified by:
headSetin interfaceNavigableSet<E extends @Nullable Object>- Parameters:
toElement- high endpoint of the returned setinclusive-trueif 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
inclusiveis true)toElement
-
standardHeadSet
protected SortedSet<E> standardHeadSet(E toElement)
A sensible definition ofForwardingSortedSet.headSet(Object)in terms of theheadSet(Object, boolean)method. If you overrideheadSet(Object, boolean), you may wish to overrideForwardingSortedSet.headSet(Object)to forward to this implementation.
-
tailSet
public NavigableSet<E> tailSet(E fromElement, boolean inclusive)
Description copied from interface:java.util.NavigableSetReturns a view of the portion of this set whose elements are greater than (or equal to, ifinclusiveis 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
IllegalArgumentExceptionon an attempt to insert an element outside its range.- Specified by:
tailSetin interfaceNavigableSet<E extends @Nullable Object>- Parameters:
fromElement- low endpoint of the returned setinclusive-trueif 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
-
standardTailSet
protected SortedSet<E> standardTailSet(E fromElement)
A sensible definition ofForwardingSortedSet.tailSet(Object)in terms of thetailSet(Object, boolean)method. If you overridetailSet(Object, boolean), you may wish to overrideForwardingSortedSet.tailSet(Object)to forward to this implementation.
-
-