Top Description Inners Constructors Methods
com.google.common.collect

public abstract Class ForwardingSortedMap<K extends @Nullable Object, V extends @Nullable Object>

extends ForwardingMap<K extends @Nullable Object, V extends @Nullable Object>
implements SortedMap<K extends @Nullable Object, V extends @Nullable Object>
Class Inheritance
All Implemented Interfaces
java.util.SortedMap, java.util.SequencedMap, java.util.Map
Known Direct Subclasses
com.google.common.collect.Maps.UnmodifiableNavigableMap, com.google.common.collect.ForwardingNavigableMap
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument

A sorted map which forwards all its method calls to another sorted map. Subclasses should override one or more methods to modify the behavior of the backing sorted map as desired per the decorator pattern.

Warning

The methods of ForwardingSortedMap forward indiscriminately to the methods of the delegate. For example, overriding put alone will not change the behavior of putAll, which can lead to unexpected behavior. In this case, you should override putAll as well, either providing your own implementation, or delegating to the provided standardPutAll 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 ForwardingSortedMap.

Each of the standard methods, where appropriate, use the comparator of the map to test equality for both keys and values, unlike ForwardingMap.

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.

Authors
Mike Bostock, Louis Wasserman
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
ForwardingSortedMap.StandardKeySet

A sensible implementation of SortedMap#keySet in terms of the methods of ForwardingSortedMap.

Constructor Summary

AccessConstructor and Description
protected
ForwardingSortedMap()

Constructor for use by subclasses.

Method Summary

Modifier and TypeMethod and Description
public Comparator<? super K>
comparator()

Implements java.util.SortedMap.comparator.

Returns the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys.
protected abstract SortedMap<K, V>
delegate()

Implements abstract com.google.common.collect.ForwardingMap.delegate.

Returns the backing delegate instance that methods are forwarded to.
public K
firstKey()

Implements java.util.SortedMap.firstKey.

Returns the first (lowest) key currently in this map.
public SortedMap<K, V>
headMap(K
high endpoint (exclusive) of the keys in the returned map
toKey
)

Implements java.util.SortedMap.headMap.

Returns a view of the portion of this map whose keys are strictly less than toKey.
public K
lastKey()

Implements java.util.SortedMap.lastKey.

Returns the last (highest) key currently in this map.
protected boolean
standardContainsKey(Object key)

Overrides com.google.common.collect.ForwardingMap.standardContainsKey.

A sensible definition of containsKey in terms of the firstKey() method of tailMap.
protected SortedMap<K, V>
standardSubMap(K fromKey, K toKey)

A sensible default implementation of subMap(Object, Object) in terms of headMap(Object) and tailMap(Object).

public SortedMap<K, V>
subMap(K
low endpoint (inclusive) of the keys in the returned map
fromKey
,
K
high endpoint (exclusive) of the keys in the returned map
toKey
)

Implements java.util.SortedMap.subMap.

Returns a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive.
public SortedMap<K, V>
tailMap(K
low endpoint (inclusive) of the keys in the returned map
fromKey
)

Implements java.util.SortedMap.tailMap.

Returns a view of the portion of this map whose keys are greater than or equal to fromKey.
pack-priv static int
unsafeCompare(Comparator<?> comparator, Object o1, Object o2)

Inherited from com.google.common.collect.ForwardingMap:
clearcontainsKeycontainsValueentrySetequalsgethashCodeisEmptykeySetputputAllremovesizestandardClearstandardContainsValuestandardEqualsstandardHashCodestandardIsEmptystandardPutAllstandardRemovestandardToStringvalues

Constructor Detail

ForwardingSortedMapback to summary
protected ForwardingSortedMap()

Constructor for use by subclasses.

Method Detail

comparatorback to summary
public Comparator<? super K> comparator()

Implements java.util.SortedMap.comparator.

Doc from java.util.SortedMap.comparator.

Returns the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys.

Returns:Comparator<? super K>

the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys

Annotations
@Override
@CheckForNull
delegateback to summary
protected abstract SortedMap<K, V> delegate()

Implements abstract com.google.common.collect.ForwardingMap.delegate.

Doc from com.google.common.collect.ForwardingObject.delegate.

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.

Annotations
@Override
firstKeyback to summary
public K firstKey()

Implements java.util.SortedMap.firstKey.

Doc from java.util.SortedMap.firstKey.

Returns the first (lowest) key currently in this map.

Returns:K

the first (lowest) key currently in this map

Annotations
@Override
@ParametricNullness
headMapback to summary
public SortedMap<K, V> headMap(K toKey)

Implements java.util.SortedMap.headMap.

Doc from java.util.SortedMap.headMap.

Returns a view of the portion of this map whose keys are strictly less than 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.

Parameters
toKey:K

high endpoint (exclusive) of the keys in the returned map

Returns:SortedMap<K, V>

a view of the portion of this map whose keys are strictly less than toKey

Annotations
@Override
lastKeyback to summary
public K lastKey()

Implements java.util.SortedMap.lastKey.

Doc from java.util.SortedMap.lastKey.

Returns the last (highest) key currently in this map.

Returns:K

the last (highest) key currently in this map

Annotations
@Override
@ParametricNullness
standardContainsKeyback to summary
protected boolean standardContainsKey(Object key)

Overrides com.google.common.collect.ForwardingMap.standardContainsKey.

A sensible definition of containsKey in terms of the firstKey() method of tailMap. If you override tailMap, you may wish to override containsKey to forward to this implementation.

Annotations
@Override
Since
7.0
standardSubMapback to summary
protected SortedMap<K, V> standardSubMap(K fromKey, K toKey)

A sensible default implementation of subMap(Object, Object) in terms of headMap(Object) and tailMap(Object). In some situations, you may wish to override subMap(Object, Object) to forward to this implementation.

Since
7.0
subMapback to summary
public SortedMap<K, V> subMap(K fromKey, K toKey)

Implements java.util.SortedMap.subMap.

Doc from java.util.SortedMap.subMap.

Returns a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive. (If fromKey and toKey are 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 IllegalArgumentException on an attempt to insert a key outside its range.

Parameters
fromKey:K

low endpoint (inclusive) of the keys in the returned map

toKey:K

high endpoint (exclusive) of the keys in the returned map

Returns:SortedMap<K, V>

a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive

Annotations
@Override
tailMapback to summary
public SortedMap<K, V> tailMap(K fromKey)

Implements java.util.SortedMap.tailMap.

Doc from java.util.SortedMap.tailMap.

Returns a view of the portion of this map whose keys are greater than or equal to 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.

Parameters
fromKey:K

low endpoint (inclusive) of the keys in the returned map

Returns:SortedMap<K, V>

a view of the portion of this map whose keys are greater than or equal to fromKey

Annotations
@Override
unsafeCompareback to summary
pack-priv static int unsafeCompare(Comparator<?> comparator, Object o1, Object o2)
Annotations
@SuppressWarnings:unchecked, nullness
com.google.common.collect back to summary

protected Class ForwardingSortedMap.StandardKeySet

extends Maps.SortedKeySet<K extends @Nullable Object, V extends @Nullable Object>
Class Inheritance

A sensible implementation of SortedMap#keySet in terms of the methods of ForwardingSortedMap. In many cases, you may wish to override ForwardingSortedMap#keySet to forward to this implementation or a subclass thereof.
Since
15.0

Constructor Summary

AccessConstructor and Description
public
StandardKeySet()

Constructor for use by subclasses.

Method Summary

Inherited from com.google.common.collect.Maps.SortedKeySet:
comparatorfirstheadSetlastmapsubSettailSet

Constructor Detail

StandardKeySetback to summary
public StandardKeySet()

Constructor for use by subclasses.