Class ForwardingNavigableMap.StandardDescendingMap
- java.lang.Object
-
- com.google.common.collect.ForwardingObject
-
- com.google.common.collect.ForwardingMap<K,V>
-
- com.google.common.collect.ForwardingNavigableMap.StandardDescendingMap
-
- All Implemented Interfaces:
Map<K,V>,NavigableMap<K,V>,SortedMap<K,V>
@Beta protected class ForwardingNavigableMap.StandardDescendingMap extends ForwardingMap<K,V>
A sensible implementation ofNavigableMap.descendingMap()in terms of the methods of thisNavigableMap. In many cases, you may wish to overrideForwardingNavigableMap.descendingMap()to forward to this implementation or a subclass thereof.In particular, this map iterates over entries with repeated calls to
NavigableMap.lowerEntry(K). If a more efficient means of iteration is available, you may wish to override theentryIterator()method of this class.- Since:
- 12.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.common.collect.ForwardingMap
ForwardingMap.StandardEntrySet, ForwardingMap.StandardKeySet, ForwardingMap.StandardValues
-
-
Constructor Summary
Constructors Constructor Description StandardDescendingMap()Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Map.Entry<K,V>ceilingEntry(K key)Returns a key-value mapping associated with the least key greater than or equal to the given key, ornullif there is no such key.KceilingKey(K key)Returns the least key greater than or equal to the given key, ornullif there is no such key.Comparator<? super K>comparator()Returns the comparator used to order the keys in this map, ornullif this map uses the natural ordering of its keys.protected Map<K,V>delegate()Returns the backing delegate instance that methods are forwarded to.NavigableSet<K>descendingKeySet()Returns a reverse orderNavigableSetview of the keys contained in this map.NavigableMap<K,V>descendingMap()Returns a reverse order view of the mappings contained in this map.protected Iterator<Map.Entry<K,V>>entryIterator()Set<Map.Entry<K,V>>entrySet()Returns aSetview of the mappings contained in this map.Map.Entry<K,V>firstEntry()Returns a key-value mapping associated with the least key in this map, ornullif the map is empty.KfirstKey()Returns the first (lowest) key currently in this map.Map.Entry<K,V>floorEntry(K key)Returns a key-value mapping associated with the greatest key less than or equal to the given key, ornullif there is no such key.KfloorKey(K key)Returns the greatest key less than or equal to the given key, ornullif there is no such key.SortedMap<K,V>headMap(K toKey)Returns a view of the portion of this map whose keys are strictly less thantoKey.NavigableMap<K,V>headMap(K toKey, boolean inclusive)Returns a view of the portion of this map whose keys are less than (or equal to, ifinclusiveis true)toKey.Map.Entry<K,V>higherEntry(K key)Returns a key-value mapping associated with the least key strictly greater than the given key, ornullif there is no such key.KhigherKey(K key)Returns the least key strictly greater than the given key, ornullif there is no such key.Set<K>keySet()Returns aSetview of the keys contained in this map.Map.Entry<K,V>lastEntry()Returns a key-value mapping associated with the greatest key in this map, ornullif the map is empty.KlastKey()Returns the last (highest) key currently in this map.Map.Entry<K,V>lowerEntry(K key)Returns a key-value mapping associated with the greatest key strictly less than the given key, ornullif there is no such key.KlowerKey(K key)Returns the greatest key strictly less than the given key, ornullif there is no such key.NavigableSet<K>navigableKeySet()Returns aNavigableSetview of the keys contained in this map.Map.Entry<K,V>pollFirstEntry()Removes and returns a key-value mapping associated with the least key in this map, ornullif the map is empty.Map.Entry<K,V>pollLastEntry()Removes and returns a key-value mapping associated with the greatest key in this map, ornullif the map is empty.NavigableMap<K,V>subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)Returns a view of the portion of this map whose keys range fromfromKeytotoKey.SortedMap<K,V>subMap(K fromKey, K toKey)Returns a view of the portion of this map whose keys range fromfromKey, inclusive, totoKey, exclusive.SortedMap<K,V>tailMap(K fromKey)Returns a view of the portion of this map whose keys are greater than or equal tofromKey.NavigableMap<K,V>tailMap(K fromKey, boolean inclusive)Returns a view of the portion of this map whose keys are greater than (or equal to, ifinclusiveis true)fromKey.StringtoString()Returns the string representation generated by the delegate'stoStringmethod.Collection<V>values()Returns aCollectionview of the values contained in this map.-
Methods inherited from class com.google.common.collect.ForwardingMap
clear, containsKey, containsValue, equals, get, hashCode, isEmpty, put, putAll, remove, size, standardClear, standardContainsKey, standardContainsValue, standardEquals, standardHashCode, standardIsEmpty, standardPutAll, standardRemove, standardToString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, equals, forEach, get, getOrDefault, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size
-
-
-
-
Constructor Detail
-
StandardDescendingMap
public StandardDescendingMap()
Constructor for use by subclasses.
-
-
Method Detail
-
entryIterator
protected Iterator<Map.Entry<K,V>> entryIterator()
-
delegate
protected final Map<K,V> 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.
-
comparator
public Comparator<? super K> comparator()
Description copied from interface:java.util.SortedMapReturns the comparator used to order the keys in this map, ornullif this map uses the natural ordering of its keys.
-
firstKey
public K firstKey()
Description copied from interface:java.util.SortedMapReturns the first (lowest) key currently in this map.
-
lastKey
public K lastKey()
Description copied from interface:java.util.SortedMapReturns the last (highest) key currently in this map.
-
lowerEntry
@CheckForNull public Map.Entry<K,V> lowerEntry(K key)
Description copied from interface:java.util.NavigableMapReturns a key-value mapping associated with the greatest key strictly less than the given key, ornullif there is no such key.- Specified by:
lowerEntryin interfaceNavigableMap<K extends @Nullable Object,V extends @Nullable Object>- Parameters:
key- the key- Returns:
- an entry with the greatest key less than
key, ornullif there is no such key
-
lowerKey
@CheckForNull public K lowerKey(K key)
Description copied from interface:java.util.NavigableMapReturns the greatest key strictly less than the given key, ornullif there is no such key.
-
floorEntry
@CheckForNull public Map.Entry<K,V> floorEntry(K key)
Description copied from interface:java.util.NavigableMapReturns a key-value mapping associated with the greatest key less than or equal to the given key, ornullif there is no such key.- Specified by:
floorEntryin interfaceNavigableMap<K extends @Nullable Object,V extends @Nullable Object>- Parameters:
key- the key- Returns:
- an entry with the greatest key less than or equal to
key, ornullif there is no such key
-
floorKey
@CheckForNull public K floorKey(K key)
Description copied from interface:java.util.NavigableMapReturns the greatest key less than or equal to the given key, ornullif there is no such key.
-
ceilingEntry
@CheckForNull public Map.Entry<K,V> ceilingEntry(K key)
Description copied from interface:java.util.NavigableMapReturns a key-value mapping associated with the least key greater than or equal to the given key, ornullif there is no such key.- Specified by:
ceilingEntryin interfaceNavigableMap<K extends @Nullable Object,V extends @Nullable Object>- Parameters:
key- the key- Returns:
- an entry with the least key greater than or equal to
key, ornullif there is no such key
-
ceilingKey
@CheckForNull public K ceilingKey(K key)
Description copied from interface:java.util.NavigableMapReturns the least key greater than or equal to the given key, ornullif there is no such key.- Specified by:
ceilingKeyin interfaceNavigableMap<K extends @Nullable Object,V extends @Nullable Object>- Parameters:
key- the key- Returns:
- the least key greater than or equal to
key, ornullif there is no such key
-
higherEntry
@CheckForNull public Map.Entry<K,V> higherEntry(K key)
Description copied from interface:java.util.NavigableMapReturns a key-value mapping associated with the least key strictly greater than the given key, ornullif there is no such key.- Specified by:
higherEntryin interfaceNavigableMap<K extends @Nullable Object,V extends @Nullable Object>- Parameters:
key- the key- Returns:
- an entry with the least key greater than
key, ornullif there is no such key
-
higherKey
@CheckForNull public K higherKey(K key)
Description copied from interface:java.util.NavigableMapReturns the least key strictly greater than the given key, ornullif there is no such key.
-
firstEntry
@CheckForNull public Map.Entry<K,V> firstEntry()
Description copied from interface:java.util.NavigableMapReturns a key-value mapping associated with the least key in this map, ornullif the map is empty.- Specified by:
firstEntryin interfaceNavigableMap<K extends @Nullable Object,V extends @Nullable Object>- Returns:
- an entry with the least key,
or
nullif this map is empty
-
lastEntry
@CheckForNull public Map.Entry<K,V> lastEntry()
Description copied from interface:java.util.NavigableMapReturns a key-value mapping associated with the greatest key in this map, ornullif the map is empty.
-
pollFirstEntry
@CheckForNull public Map.Entry<K,V> pollFirstEntry()
Description copied from interface:java.util.NavigableMapRemoves and returns a key-value mapping associated with the least key in this map, ornullif the map is empty.- Specified by:
pollFirstEntryin interfaceNavigableMap<K extends @Nullable Object,V extends @Nullable Object>- Returns:
- the removed first entry of this map,
or
nullif this map is empty
-
pollLastEntry
@CheckForNull public Map.Entry<K,V> pollLastEntry()
Description copied from interface:java.util.NavigableMapRemoves and returns a key-value mapping associated with the greatest key in this map, ornullif the map is empty.- Specified by:
pollLastEntryin interfaceNavigableMap<K extends @Nullable Object,V extends @Nullable Object>- Returns:
- the removed last entry of this map,
or
nullif this map is empty
-
descendingMap
public NavigableMap<K,V> descendingMap()
Description copied from interface:java.util.NavigableMapReturns a reverse order view of the mappings contained in this map. The descending map is backed by this map, so changes to the map are reflected in the descending map, and vice-versa. If either map is modified while an iteration over a collection view of either map is in progress (except through the iterator's ownremoveoperation), the results of the iteration are undefined.The returned map has an ordering equivalent to
Collections.reverseOrder(comparator()). The expressionm.descendingMap().descendingMap()returns a view ofmessentially equivalent tom.- Specified by:
descendingMapin interfaceNavigableMap<K extends @Nullable Object,V extends @Nullable Object>- Returns:
- a reverse order view of this map
-
entrySet
public Set<Map.Entry<K,V>> entrySet()
Description copied from interface:java.util.MapReturns aSetview of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremoveoperation, or through thesetValueoperation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Set.remove,removeAll,retainAllandclearoperations. It does not support theaddoraddAlloperations.- Specified by:
entrySetin interfaceMap<K extends @Nullable Object,V extends @Nullable Object>- Specified by:
entrySetin interfaceSortedMap<K extends @Nullable Object,V extends @Nullable Object>- Overrides:
entrySetin classForwardingMap<K extends @Nullable Object,V extends @Nullable Object>- Returns:
- a set view of the mappings contained in this map
-
keySet
public Set<K> keySet()
Description copied from interface:java.util.MapReturns aSetview of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremoveoperation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Set.remove,removeAll,retainAll, andclearoperations. It does not support theaddoraddAlloperations.- Specified by:
keySetin interfaceMap<K extends @Nullable Object,V extends @Nullable Object>- Specified by:
keySetin interfaceSortedMap<K extends @Nullable Object,V extends @Nullable Object>- Overrides:
keySetin classForwardingMap<K extends @Nullable Object,V extends @Nullable Object>- Returns:
- a set view of the keys contained in this map
-
navigableKeySet
public NavigableSet<K> navigableKeySet()
Description copied from interface:java.util.NavigableMapReturns aNavigableSetview of the keys contained in this map. The set's iterator returns the keys in ascending order. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremoveoperation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Set.remove,removeAll,retainAll, andclearoperations. It does not support theaddoraddAlloperations.- Specified by:
navigableKeySetin interfaceNavigableMap<K extends @Nullable Object,V extends @Nullable Object>- Returns:
- a navigable set view of the keys in this map
-
descendingKeySet
public NavigableSet<K> descendingKeySet()
Description copied from interface:java.util.NavigableMapReturns a reverse orderNavigableSetview of the keys contained in this map. The set's iterator returns the keys in descending order. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremoveoperation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Set.remove,removeAll,retainAll, andclearoperations. It does not support theaddoraddAlloperations.- Specified by:
descendingKeySetin interfaceNavigableMap<K extends @Nullable Object,V extends @Nullable Object>- Returns:
- a reverse order navigable set view of the keys in this map
-
subMap
public NavigableMap<K,V> subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
Description copied from interface:java.util.NavigableMapReturns a view of the portion of this map whose keys range fromfromKeytotoKey. IffromKeyandtoKeyare equal, the returned map is empty unlessfromInclusiveandtoInclusiveare both true. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.The returned map will throw an
IllegalArgumentExceptionon an attempt to insert a key outside of its range, or to construct a submap either of whose endpoints lie outside its range.- Specified by:
subMapin interfaceNavigableMap<K extends @Nullable Object,V extends @Nullable Object>- Parameters:
fromKey- low endpoint of the keys in the returned mapfromInclusive-trueif the low endpoint is to be included in the returned viewtoKey- high endpoint of the keys in the returned maptoInclusive-trueif the high endpoint is to be included in the returned view- Returns:
- a view of the portion of this map whose keys range from
fromKeytotoKey
-
subMap
public SortedMap<K,V> subMap(K fromKey, K toKey)
Description copied from interface:java.util.NavigableMapReturns a view of the portion of this map whose keys range fromfromKey, inclusive, totoKey, exclusive. (IffromKeyandtoKeyare equal, the returned map is empty.) The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.The returned map will throw an
IllegalArgumentExceptionon an attempt to insert a key outside its range.Equivalent to
subMap(fromKey, true, toKey, false).- Specified by:
subMapin interfaceNavigableMap<K extends @Nullable Object,V extends @Nullable Object>- Specified by:
subMapin interfaceSortedMap<K extends @Nullable Object,V extends @Nullable Object>- Parameters:
fromKey- low endpoint (inclusive) of the keys in the returned maptoKey- high endpoint (exclusive) of the keys in the returned map- Returns:
- a view of the portion of this map whose keys range from
fromKey, inclusive, totoKey, exclusive
-
headMap
public NavigableMap<K,V> headMap(K toKey, boolean inclusive)
Description copied from interface:java.util.NavigableMapReturns a view of the portion of this map whose keys are less than (or equal to, ifinclusiveis true)toKey. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.The returned map will throw an
IllegalArgumentExceptionon an attempt to insert a key outside its range.- Specified by:
headMapin interfaceNavigableMap<K extends @Nullable Object,V extends @Nullable Object>- Parameters:
toKey- high endpoint of the keys in the returned mapinclusive-trueif the high endpoint is to be included in the returned view- Returns:
- a view of the portion of this map whose keys are less than
(or equal to, if
inclusiveis true)toKey
-
headMap
public SortedMap<K,V> headMap(K toKey)
Description copied from interface:java.util.NavigableMapReturns a view of the portion of this map whose keys are strictly less thantoKey. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.The returned map will throw an
IllegalArgumentExceptionon an attempt to insert a key outside its range.Equivalent to
headMap(toKey, false).- Specified by:
headMapin interfaceNavigableMap<K extends @Nullable Object,V extends @Nullable Object>- Specified by:
headMapin interfaceSortedMap<K extends @Nullable Object,V extends @Nullable Object>- Parameters:
toKey- high endpoint (exclusive) of the keys in the returned map- Returns:
- a view of the portion of this map whose keys are strictly
less than
toKey
-
tailMap
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive)
Description copied from interface:java.util.NavigableMapReturns a view of the portion of this map whose keys are greater than (or equal to, ifinclusiveis true)fromKey. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.The returned map will throw an
IllegalArgumentExceptionon an attempt to insert a key outside its range.- Specified by:
tailMapin interfaceNavigableMap<K extends @Nullable Object,V extends @Nullable Object>- Parameters:
fromKey- low endpoint of the keys in the returned mapinclusive-trueif the low endpoint is to be included in the returned view- Returns:
- a view of the portion of this map whose keys are greater than
(or equal to, if
inclusiveis true)fromKey
-
tailMap
public SortedMap<K,V> tailMap(K fromKey)
Description copied from interface:java.util.NavigableMapReturns a view of the portion of this map whose keys are greater than or equal tofromKey. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.The returned map will throw an
IllegalArgumentExceptionon an attempt to insert a key outside its range.Equivalent to
tailMap(fromKey, true).- Specified by:
tailMapin interfaceNavigableMap<K extends @Nullable Object,V extends @Nullable Object>- Specified by:
tailMapin interfaceSortedMap<K extends @Nullable Object,V extends @Nullable Object>- Parameters:
fromKey- low endpoint (inclusive) of the keys in the returned map- Returns:
- a view of the portion of this map whose keys are greater
than or equal to
fromKey
-
values
public Collection<V> values()
Description copied from interface:java.util.MapReturns aCollectionview of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's ownremoveoperation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Collection.remove,removeAll,retainAllandclearoperations. It does not support theaddoraddAlloperations.- Specified by:
valuesin interfaceMap<K extends @Nullable Object,V extends @Nullable Object>- Specified by:
valuesin interfaceSortedMap<K extends @Nullable Object,V extends @Nullable Object>- Overrides:
valuesin classForwardingMap<K extends @Nullable Object,V extends @Nullable Object>- Returns:
- a collection view of the values contained in this map
-
toString
public String toString()
Description copied from class:ForwardingObjectReturns the string representation generated by the delegate'stoStringmethod.- Overrides:
toStringin classForwardingObject- Returns:
- a string representation of the object.
-
-