Class ForwardingNavigableMap<K,V>
-
- com.google.common.collect.ForwardingObject
-
- com.google.common.collect.ForwardingMap<K,V>
-
- com.google.common.collect.ForwardingSortedMap<K,V>
-
- com.google.common.collect.ForwardingNavigableMap<K,V>
-
- All Implemented Interfaces:
<K,V>
,<K,V>
,<K,V>
@GwtIncompatible public abstract class ForwardingNavigableMap<K,V> extends ForwardingSortedMap<K,V> implements <K,V>
A navigable map which forwards all its method calls to another navigable map. Subclasses should override one or more methods to modify the behavior of the backing map as desired per the .Warning: The methods of
ForwardingNavigableMap
forward indiscriminately to the methods of the delegate. For example, overridingForwardingMap.put(K, V)
alone will not change the behavior ofForwardingMap.putAll(java.util.Map<? extends K, ? extends V>)
, which can lead to unexpected behavior. In this case, you should overrideputAll
as well, either providing your own implementation, or delegating to the providedstandardPutAll
method.default
method warning: This class does not forward calls todefault
methods. Instead, it inherits their default implementations. When those implementations invoke methods, they invoke methods on theForwardingNavigableMap
.Each of the
standard
methods uses the map'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 theMap
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
ForwardingNavigableMap.StandardDescendingMap
A sensible implementation of in terms of the methods of thisNavigableMap
.protected class
ForwardingNavigableMap.StandardNavigableKeySet
A sensible implementation of in terms of the methods of thisNavigableMap
.-
Nested classes/interfaces inherited from class com.google.common.collect.ForwardingSortedMap
ForwardingSortedMap.StandardKeySet
-
Nested classes/interfaces inherited from class com.google.common.collect.ForwardingMap
ForwardingMap.StandardEntrySet, ForwardingMap.StandardValues
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ForwardingNavigableMap()
Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <K,V>
ceilingEntry(K key)
Returns a key-value mapping associated with the least key greater than or equal to the given key, ornull
if there is no such key.K
ceilingKey(K key)
Returns the least key greater than or equal to the given key, ornull
if there is no such key.protected abstract <K,V>
delegate()
Returns the backing delegate instance that methods are forwarded to.<K>
descendingKeySet()
Returns a reverse order view of the keys contained in this map.<K,V>
descendingMap()
Returns a reverse order view of the mappings contained in this map.<K,V>
firstEntry()
Returns a key-value mapping associated with the least key in this map, ornull
if the map is empty.<K,V>
floorEntry(K key)
Returns a key-value mapping associated with the greatest key less than or equal to the given key, ornull
if there is no such key.K
floorKey(K key)
Returns the greatest key less than or equal to the given key, ornull
if there is no such key.<K,V>
headMap(K toKey, boolean inclusive)
Returns a view of the portion of this map whose keys are less than (or equal to, ifinclusive
is true)toKey
.<K,V>
higherEntry(K key)
Returns a key-value mapping associated with the least key strictly greater than the given key, ornull
if there is no such key.K
higherKey(K key)
Returns the least key strictly greater than the given key, ornull
if there is no such key.<K,V>
lastEntry()
Returns a key-value mapping associated with the greatest key in this map, ornull
if the map is empty.<K,V>
lowerEntry(K key)
Returns a key-value mapping associated with the greatest key strictly less than the given key, ornull
if there is no such key.K
lowerKey(K key)
Returns the greatest key strictly less than the given key, ornull
if there is no such key.<K>
navigableKeySet()
Returns a view of the keys contained in this map.<K,V>
pollFirstEntry()
Removes and returns a key-value mapping associated with the least key in this map, ornull
if the map is empty.<K,V>
pollLastEntry()
Removes and returns a key-value mapping associated with the greatest key in this map, ornull
if the map is empty.protected <K,V>
standardCeilingEntry(K key)
protected K
standardCeilingKey(K key)
A sensible definition ofceilingKey(K)
in terms ofceilingEntry
.protected <K>
standardDescendingKeySet()
protected <K,V>
standardFirstEntry()
protected K
standardFirstKey()
A sensible definition ofForwardingSortedMap.firstKey()
in terms offirstEntry
.protected <K,V>
standardFloorEntry(K key)
protected K
standardFloorKey(K key)
A sensible definition offloorKey(K)
in terms offloorEntry
.protected <K,V>
standardHeadMap(K toKey)
A sensible definition ofForwardingSortedMap.headMap(Object)
in terms ofheadMap(Object, boolean)
.protected <K,V>
standardHigherEntry(K key)
protected K
standardHigherKey(K key)
A sensible definition ofhigherKey(K)
in terms ofhigherEntry
.protected <K,V>
standardLastEntry()
A sensible definition oflastEntry()
in terms of theiterator()
of theForwardingMap.entrySet()
ofdescendingMap()
.protected K
standardLastKey()
A sensible definition ofForwardingSortedMap.lastKey()
in terms oflastEntry
.protected <K,V>
standardLowerEntry(K key)
protected K
standardLowerKey(K key)
A sensible definition oflowerKey(K)
in terms oflowerEntry
.protected <K,V>
standardPollFirstEntry()
protected <K,V>
standardPollLastEntry()
A sensible definition ofpollFirstEntry()
in terms of theiterator
of theentrySet
ofdescendingMap
.protected <K,V>
standardSubMap(K fromKey, K toKey)
A sensible definition ofForwardingSortedMap.subMap(Object, Object)
in terms ofsubMap(Object, boolean, Object, boolean)
.protected <K,V>
standardTailMap(K fromKey)
A sensible definition ofForwardingSortedMap.tailMap(Object)
in terms oftailMap(Object, boolean)
.<K,V>
subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
Returns a view of the portion of this map whose keys range fromfromKey
totoKey
.<K,V>
tailMap(K fromKey, boolean inclusive)
Returns a view of the portion of this map whose keys are greater than (or equal to, ifinclusive
is true)fromKey
.-
Methods inherited from class com.google.common.collect.ForwardingSortedMap
comparator, firstKey, headMap, lastKey, standardContainsKey, subMap, tailMap
-
Methods inherited from class com.google.common.collect.ForwardingMap
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, standardClear, standardContainsValue, standardEquals, standardHashCode, standardIsEmpty, standardPutAll, standardRemove, standardToString, values
-
Methods inherited from class com.google.common.collect.ForwardingObject
toString
-
-
-
-
Constructor Detail
-
ForwardingNavigableMap
protected ForwardingNavigableMap()
Constructor for use by subclasses.
-
-
Method Detail
-
delegate
protected abstract <K,V> delegate()
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 asForwardingSet.delegate()
. Concrete subclasses override this method to supply the instance being decorated.- Specified by:
delegate
in classForwardingSortedMap<K,V>
-
lowerEntry
public <K,V> lowerEntry(K key)
Description copied from interface:Returns a key-value mapping associated with the greatest key strictly less than the given key, ornull
if there is no such key.
-
standardLowerEntry
protected <K,V> standardLowerEntry(K key)
A sensible definition oflowerEntry(K)
in terms of thelastEntry()
ofheadMap(Object, boolean)
. If you overrideheadMap
, you may wish to overridelowerEntry
to forward to this implementation.
-
lowerKey
public K lowerKey(K key)
Description copied from interface:Returns the greatest key strictly less than the given key, ornull
if there is no such key.
-
standardLowerKey
protected K standardLowerKey(K key)
A sensible definition oflowerKey(K)
in terms oflowerEntry
. If you overridelowerEntry(K)
, you may wish to overridelowerKey
to forward to this implementation.
-
floorEntry
public <K,V> floorEntry(K key)
Description copied from interface:Returns a key-value mapping associated with the greatest key less than or equal to the given key, ornull
if there is no such key.
-
standardFloorEntry
protected <K,V> standardFloorEntry(K key)
A sensible definition offloorEntry(K)
in terms of thelastEntry()
ofheadMap(Object, boolean)
. If you overrideheadMap
, you may wish to overridefloorEntry
to forward to this implementation.
-
floorKey
public K floorKey(K key)
Description copied from interface:Returns the greatest key less than or equal to the given key, ornull
if there is no such key.
-
standardFloorKey
protected K standardFloorKey(K key)
A sensible definition offloorKey(K)
in terms offloorEntry
. If you overridefloorEntry
, you may wish to overridefloorKey
to forward to this implementation.
-
ceilingEntry
public <K,V> ceilingEntry(K key)
Description copied from interface:Returns a key-value mapping associated with the least key greater than or equal to the given key, ornull
if there is no such key.
-
standardCeilingEntry
protected <K,V> standardCeilingEntry(K key)
A sensible definition ofceilingEntry(K)
in terms of thefirstEntry()
oftailMap(Object, boolean)
. If you overridetailMap
, you may wish to overrideceilingEntry
to forward to this implementation.
-
ceilingKey
public K ceilingKey(K key)
Description copied from interface:Returns the least key greater than or equal to the given key, ornull
if there is no such key.
-
standardCeilingKey
protected K standardCeilingKey(K key)
A sensible definition ofceilingKey(K)
in terms ofceilingEntry
. If you overrideceilingEntry
, you may wish to overrideceilingKey
to forward to this implementation.
-
higherEntry
public <K,V> higherEntry(K key)
Description copied from interface:Returns a key-value mapping associated with the least key strictly greater than the given key, ornull
if there is no such key.
-
standardHigherEntry
protected <K,V> standardHigherEntry(K key)
A sensible definition ofhigherEntry(K)
in terms of thefirstEntry()
oftailMap(Object, boolean)
. If you overridetailMap
, you may wish to overridehigherEntry
to forward to this implementation.
-
higherKey
public K higherKey(K key)
Description copied from interface:Returns the least key strictly greater than the given key, ornull
if there is no such key.
-
standardHigherKey
protected K standardHigherKey(K key)
A sensible definition ofhigherKey(K)
in terms ofhigherEntry
. If you overridehigherEntry
, you may wish to overridehigherKey
to forward to this implementation.
-
firstEntry
public <K,V> firstEntry()
Description copied from interface:Returns a key-value mapping associated with the least key in this map, ornull
if the map is empty.
-
standardFirstEntry
protected <K,V> standardFirstEntry()
A sensible definition offirstEntry()
in terms of theiterator()
ofForwardingMap.entrySet()
. If you overrideentrySet
, you may wish to overridefirstEntry
to forward to this implementation.
-
standardFirstKey
protected K standardFirstKey()
A sensible definition ofForwardingSortedMap.firstKey()
in terms offirstEntry
. If you overridefirstEntry
, you may wish to overridefirstKey
to forward to this implementation.
-
lastEntry
public <K,V> lastEntry()
Description copied from interface:Returns a key-value mapping associated with the greatest key in this map, ornull
if the map is empty.
-
standardLastEntry
protected <K,V> standardLastEntry()
A sensible definition oflastEntry()
in terms of theiterator()
of theForwardingMap.entrySet()
ofdescendingMap()
. If you overridedescendingMap
, you may wish to overridelastEntry
to forward to this implementation.
-
standardLastKey
protected K standardLastKey()
A sensible definition ofForwardingSortedMap.lastKey()
in terms oflastEntry
. If you overridelastEntry
, you may wish to overridelastKey
to forward to this implementation.
-
pollFirstEntry
public <K,V> pollFirstEntry()
Description copied from interface:Removes and returns a key-value mapping associated with the least key in this map, ornull
if the map is empty.
-
standardPollFirstEntry
protected <K,V> standardPollFirstEntry()
A sensible definition ofpollFirstEntry()
in terms of theiterator
ofentrySet
. If you overrideentrySet
, you may wish to overridepollFirstEntry
to forward to this implementation.
-
pollLastEntry
public <K,V> pollLastEntry()
Description copied from interface:Removes and returns a key-value mapping associated with the greatest key in this map, ornull
if the map is empty.
-
standardPollLastEntry
protected <K,V> standardPollLastEntry()
A sensible definition ofpollFirstEntry()
in terms of theiterator
of theentrySet
ofdescendingMap
. If you overridedescendingMap
, you may wish to overridepollFirstEntry
to forward to this implementation.
-
descendingMap
public <K,V> descendingMap()
Description copied from interface:Returns 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 ownremove
operation), the results of the iteration are undefined.The returned map has an ordering equivalent to
(comparator())
. The expressionm.descendingMap().descendingMap()
returns a view ofm
essentially equivalent tom
.
-
navigableKeySet
public <K> navigableKeySet()
Description copied from interface:Returns a view 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 ownremove
operation), 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
, andclear
operations. It does not support theadd
oraddAll
operations.
-
descendingKeySet
public <K> descendingKeySet()
Description copied from interface:Returns a reverse order view 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 ownremove
operation), 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
, andclear
operations. It does not support theadd
oraddAll
operations.
-
standardDescendingKeySet
@Beta protected <K> standardDescendingKeySet()
A sensible definition ofdescendingKeySet()
as thenavigableKeySet
ofdescendingMap()
. (TheForwardingNavigableMap.StandardDescendingMap
implementation implementsnavigableKeySet
on its own, so as not to cause an infinite loop.) If you overridedescendingMap
, you may wish to overridedescendingKeySet
to forward to this implementation.
-
standardSubMap
protected <K,V> standardSubMap(K fromKey, K toKey)
A sensible definition ofForwardingSortedMap.subMap(Object, Object)
in terms ofsubMap(Object, boolean, Object, boolean)
. If you overridesubMap(K, boolean, K, boolean)
, you may wish to overridesubMap
to forward to this implementation.- Overrides:
standardSubMap
in classForwardingSortedMap<K,V>
-
subMap
public <K,V> subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
Description copied from interface:Returns a view of the portion of this map whose keys range fromfromKey
totoKey
. IffromKey
andtoKey
are equal, the returned map is empty unlessfromInclusive
andtoInclusive
are 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
IllegalArgumentException
on 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:
in interface
<K,V>
- Parameters:
fromKey
- low endpoint of the keys in the returned mapfromInclusive
-true
if the low endpoint is to be included in the returned viewtoKey
- high endpoint of the keys in the returned maptoInclusive
-true
if the high endpoint is to be included in the returned view- Returns:
- a view of the portion of this map whose keys range from
fromKey
totoKey
-
headMap
public <K,V> headMap(K toKey, boolean inclusive)
Description copied from interface:Returns a view of the portion of this map whose keys are less than (or equal to, ifinclusive
is 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
IllegalArgumentException
on an attempt to insert a key outside its range.
-
tailMap
public <K,V> tailMap(K fromKey, boolean inclusive)
Description copied from interface:Returns a view of the portion of this map whose keys are greater than (or equal to, ifinclusive
is 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
IllegalArgumentException
on an attempt to insert a key outside its range.
-
standardHeadMap
protected <K,V> standardHeadMap(K toKey)
A sensible definition ofForwardingSortedMap.headMap(Object)
in terms ofheadMap(Object, boolean)
. If you overrideheadMap(K, boolean)
, you may wish to overrideheadMap
to forward to this implementation.
-
standardTailMap
protected <K,V> standardTailMap(K fromKey)
A sensible definition ofForwardingSortedMap.tailMap(Object)
in terms oftailMap(Object, boolean)
. If you overridetailMap(K, boolean)
, you may wish to overridetailMap
to forward to this implementation.
-
-