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

public final Class ImmutableSortedMap<K, V>

extends ImmutableSortedMapFauxverideShim<K, V>
implements NavigableMap<K, V>
Class Inheritance
All Implemented Interfaces
java.util.NavigableMap, java.util.SortedMap, java.util.SequencedMap, java.util.Map
Annotations
@GwtCompatible
serializable:true
emulated:true
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull, com.google.common.collect.CollectPreconditions.checkEntryNotNull, .Maps.keyOrNull, java.util.Objects.requireNonNull

A NavigableMap whose contents will never change, with many other important properties detailed at ImmutableCollection.

Warning

as with any sorted collection, you are strongly advised not to use a Comparator or Comparable type whose comparison behavior is inconsistent with equals. That is, a.compareTo(b) or comparator.compare(a, b) should equal zero if and only if a.equals(b). If this advice is not followed, the resulting map will not correctly obey its specification.

See the Guava User Guide article on immutable collections.

Authors
Jared Levy, Louis Wasserman
Since
2.0 (implements NavigableMap since 12.0)

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ImmutableSortedMap.Builder<K, V>

A builder for creating immutable sorted map instances, especially public static final maps ("constant maps").

private static class
ImmutableSortedMap.SerializedForm<K, V>

Serialized type for all ImmutableSortedMap instances.

Field Summary

Modifier and TypeField and Description
private transient ImmutableSortedMap<K, V>
private final transient RegularImmutableSortedSet<K>
private static final ImmutableSortedMap<Comparable<T>, Object>
private static final Comparator<Comparable<T>>
private static final long
private final transient ImmutableList<V>

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv
ImmutableSortedMap(RegularImmutableSortedSet<K> keySet, ImmutableList<V> valueList, ImmutableSortedMap<K, V> descendingMap)

Method Summary

Modifier and TypeMethod and Description
public Map.Entry<K, V>
ceilingEntry(K
the key
key
)

Implements java.util.NavigableMap.ceilingEntry.

Returns a key-value mapping associated with the least key greater than or equal to the given key, or null if there is no such key.
public K
ceilingKey(K
the key
key
)

Implements java.util.NavigableMap.ceilingKey.

Returns the least key greater than or equal to the given key, or null if there is no such key.
public Comparator<? super K>
comparator()

Implements java.util.SortedMap.comparator.

Returns the comparator that orders the keys, which is Ordering#natural() when the natural ordering of the keys is used.
public static <K, V> ImmutableSortedMap<K, V>
copyOf(Map<? extends K, ? extends V>
a Map from which entries are drawn, must be non-null
map
)

Hides com.google.common.collect.ImmutableMap.copyOf, java.util.Map.copyOf.

Returns an immutable map containing the same entries as map, sorted by the natural ordering of the keys.
public static <K, V> ImmutableSortedMap<K, V>
copyOf(Map<? extends K, ? extends V> map, Comparator<? super K> comparator)

Returns an immutable map containing the same entries as map, with keys sorted by the provided comparator.

public static <K, V> ImmutableSortedMap<K, V>
copyOf(Iterable<? extends Map.Entry<? extends K, ? extends V>> entries)

Hides com.google.common.collect.ImmutableMap.copyOf.

Returns an immutable map containing the given entries, with keys sorted by their natural ordering.
public static <K, V> ImmutableSortedMap<K, V>
copyOf(Iterable<? extends Map.Entry<? extends K, ? extends V>> entries, Comparator<? super K> comparator)

Returns an immutable map containing the given entries, with keys sorted by the provided comparator.

private static <K, V> ImmutableSortedMap<K, V>
copyOfInternal(Map<? extends K, ? extends V> map, Comparator<? super K> comparator)

public static <K, V> ImmutableSortedMap<K, V>
copyOfSorted(SortedMap<K, ? extends V> map)

Returns an immutable map containing the same entries as the provided sorted map, with the same ordering.

pack-priv ImmutableSet<Map.Entry<K, V>>
pack-priv ImmutableSet<K>
pack-priv ImmutableCollection<V>
public ImmutableSortedSet<K>
descendingKeySet()

Implements java.util.NavigableMap.descendingKeySet.

Returns a reverse order NavigableSet view of the keys contained in this map.
public ImmutableSortedMap<K, V>
descendingMap()

Implements java.util.NavigableMap.descendingMap.

Returns a reverse order view of the mappings contained in this map.
pack-priv static <K, V> ImmutableSortedMap<K, V>
emptyMap(Comparator<? super K> comparator)

public ImmutableSet<Map.Entry<K, V>>
entrySet()

Overrides com.google.common.collect.ImmutableMap.entrySet.

Implements java.util.SortedMap.entrySet, java.util.Map.entrySet.

Returns an immutable set of the mappings in this map, sorted by the key ordering.
public Map.Entry<K, V>
firstEntry()

Implements java.util.NavigableMap.firstEntry.

Returns a key-value mapping associated with the least key in this map, or null if the map is empty.
public K
firstKey()

Implements java.util.SortedMap.firstKey.

Returns the first (lowest) key currently in this map.
public Map.Entry<K, V>
floorEntry(K
the key
key
)

Implements java.util.NavigableMap.floorEntry.

Returns a key-value mapping associated with the greatest key less than or equal to the given key, or null if there is no such key.
public K
floorKey(K
the key
key
)

Implements java.util.NavigableMap.floorKey.

Returns the greatest key less than or equal to the given key, or null if there is no such key.
public void
forEach(BiConsumer<? super K, ? super V>
The action to be performed for each entry
action
)

Overrides default java.util.Map.forEach.

Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.
private static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V>
fromEntries(Map.Entry<K, V>... entries)

private static <K, V> ImmutableSortedMap<K, V>
fromEntries(Comparator<? super K> comparator, boolean sameComparator, Iterable<? extends Map.Entry<? extends K, ? extends V>> entries)

Accepts a collection of possibly-null entries.

private static <K, V> ImmutableSortedMap<K, V>
fromEntries(final Comparator<? super K> comparator, boolean sameComparator, @Nullable Map.Entry<K, V>[] entryArray, int size)

public V
get(Object
the key whose associated value is to be returned
key
)

Implements abstract com.google.common.collect.ImmutableMap.get.

Implements java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
private ImmutableSortedMap<K, V>
getSubMap(int fromIndex, int toIndex)

public ImmutableSortedMap<K, V>
headMap(K
high endpoint (exclusive) of the keys in the returned map
toKey
)

Implements java.util.NavigableMap.headMap.

This method returns a ImmutableSortedMap, consisting of the entries whose keys are less than toKey.
public ImmutableSortedMap<K, V>
headMap(K
high endpoint of the keys in the returned map
toKey
,
boolean
true if the high endpoint is to be included in the returned view
inclusive
)

Implements java.util.NavigableMap.headMap.

This method returns a ImmutableSortedMap, consisting of the entries whose keys are less than (or equal to, if inclusive) toKey.
public Map.Entry<K, V>
higherEntry(K
the key
key
)

Implements java.util.NavigableMap.higherEntry.

Returns a key-value mapping associated with the least key strictly greater than the given key, or null if there is no such key.
public K
higherKey(K
the key
key
)

Implements java.util.NavigableMap.higherKey.

Returns the least key strictly greater than the given key, or null if there is no such key.
pack-priv boolean
public ImmutableSortedSet<K>
keySet()

Overrides com.google.common.collect.ImmutableMap.keySet.

Implements java.util.SortedMap.keySet, java.util.Map.keySet.

Returns an immutable sorted set of the keys in this map.
public Map.Entry<K, V>
lastEntry()

Implements java.util.NavigableMap.lastEntry.

Returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.
public K
lastKey()

Implements java.util.SortedMap.lastKey.

Returns the last (highest) key currently in this map.
public Map.Entry<K, V>
lowerEntry(K
the key
key
)

Implements java.util.NavigableMap.lowerEntry.

Returns a key-value mapping associated with the greatest key strictly less than the given key, or null if there is no such key.
public K
lowerKey(K
the key
key
)

Implements java.util.NavigableMap.lowerKey.

Returns the greatest key strictly less than the given key, or null if there is no such key.
public static <K extends Comparable<?>, V> ImmutableSortedMap.Builder<K, V>
naturalOrder()

Returns a builder that creates immutable sorted maps whose keys are ordered by their natural ordering.

public static <K, V> ImmutableSortedMap<K, V>
of()

Hides com.google.common.collect.ImmutableMap.of, java.util.Map.of.

Returns the empty sorted map.
public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V>
of(K
the mapping's key
k1
,
V
the mapping's value
v1
)

Hides com.google.common.collect.ImmutableSortedMapFauxverideShim.of, java.util.Map.of.

Returns an immutable map containing a single entry.
private static <K, V> ImmutableSortedMap<K, V>
of(Comparator<? super K> comparator, K k1, V v1)

Returns an immutable map containing a single entry.

public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V>
of(K
the first mapping's key
k1
,
V
the first mapping's value
v1
,
K
the second mapping's key
k2
,
V
the second mapping's value
v2
)

Hides com.google.common.collect.ImmutableSortedMapFauxverideShim.of, java.util.Map.of.

Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.
public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V>
of(K
the first mapping's key
k1
,
V
the first mapping's value
v1
,
K
the second mapping's key
k2
,
V
the second mapping's value
v2
,
K
the third mapping's key
k3
,
V
the third mapping's value
v3
)

Hides com.google.common.collect.ImmutableSortedMapFauxverideShim.of, java.util.Map.of.

Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.
public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V>
of(K
the first mapping's key
k1
,
V
the first mapping's value
v1
,
K
the second mapping's key
k2
,
V
the second mapping's value
v2
,
K
the third mapping's key
k3
,
V
the third mapping's value
v3
,
K
the fourth mapping's key
k4
,
V
the fourth mapping's value
v4
)

Hides com.google.common.collect.ImmutableSortedMapFauxverideShim.of, java.util.Map.of.

Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.
public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V>
of(K
the first mapping's key
k1
,
V
the first mapping's value
v1
,
K
the second mapping's key
k2
,
V
the second mapping's value
v2
,
K
the third mapping's key
k3
,
V
the third mapping's value
v3
,
K
the fourth mapping's key
k4
,
V
the fourth mapping's value
v4
,
K
the fifth mapping's key
k5
,
V
the fifth mapping's value
v5
)

Hides com.google.common.collect.ImmutableSortedMapFauxverideShim.of, java.util.Map.of.

Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.
public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V>
of(K
the first mapping's key
k1
,
V
the first mapping's value
v1
,
K
the second mapping's key
k2
,
V
the second mapping's value
v2
,
K
the third mapping's key
k3
,
V
the third mapping's value
v3
,
K
the fourth mapping's key
k4
,
V
the fourth mapping's value
v4
,
K
the fifth mapping's key
k5
,
V
the fifth mapping's value
v5
,
K
the sixth mapping's key
k6
,
V
the sixth mapping's value
v6
)

Hides com.google.common.collect.ImmutableSortedMapFauxverideShim.of, java.util.Map.of.

Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.
public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V>
of(K
the first mapping's key
k1
,
V
the first mapping's value
v1
,
K
the second mapping's key
k2
,
V
the second mapping's value
v2
,
K
the third mapping's key
k3
,
V
the third mapping's value
v3
,
K
the fourth mapping's key
k4
,
V
the fourth mapping's value
v4
,
K
the fifth mapping's key
k5
,
V
the fifth mapping's value
v5
,
K
the sixth mapping's key
k6
,
V
the sixth mapping's value
v6
,
K
the seventh mapping's key
k7
,
V
the seventh mapping's value
v7
)

Hides com.google.common.collect.ImmutableSortedMapFauxverideShim.of, java.util.Map.of.

Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.
public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V>
of(K
the first mapping's key
k1
,
V
the first mapping's value
v1
,
K
the second mapping's key
k2
,
V
the second mapping's value
v2
,
K
the third mapping's key
k3
,
V
the third mapping's value
v3
,
K
the fourth mapping's key
k4
,
V
the fourth mapping's value
v4
,
K
the fifth mapping's key
k5
,
V
the fifth mapping's value
v5
,
K
the sixth mapping's key
k6
,
V
the sixth mapping's value
v6
,
K
the seventh mapping's key
k7
,
V
the seventh mapping's value
v7
,
K
the eighth mapping's key
k8
,
V
the eighth mapping's value
v8
)

Hides com.google.common.collect.ImmutableSortedMapFauxverideShim.of, java.util.Map.of.

Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.
public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V>
of(K
the first mapping's key
k1
,
V
the first mapping's value
v1
,
K
the second mapping's key
k2
,
V
the second mapping's value
v2
,
K
the third mapping's key
k3
,
V
the third mapping's value
v3
,
K
the fourth mapping's key
k4
,
V
the fourth mapping's value
v4
,
K
the fifth mapping's key
k5
,
V
the fifth mapping's value
v5
,
K
the sixth mapping's key
k6
,
V
the sixth mapping's value
v6
,
K
the seventh mapping's key
k7
,
V
the seventh mapping's value
v7
,
K
the eighth mapping's key
k8
,
V
the eighth mapping's value
v8
,
K
the ninth mapping's key
k9
,
V
the ninth mapping's value
v9
)

Hides com.google.common.collect.ImmutableSortedMapFauxverideShim.of, java.util.Map.of.

Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.
public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V>
of(K
the first mapping's key
k1
,
V
the first mapping's value
v1
,
K
the second mapping's key
k2
,
V
the second mapping's value
v2
,
K
the third mapping's key
k3
,
V
the third mapping's value
v3
,
K
the fourth mapping's key
k4
,
V
the fourth mapping's value
v4
,
K
the fifth mapping's key
k5
,
V
the fifth mapping's value
v5
,
K
the sixth mapping's key
k6
,
V
the sixth mapping's value
v6
,
K
the seventh mapping's key
k7
,
V
the seventh mapping's value
v7
,
K
the eighth mapping's key
k8
,
V
the eighth mapping's value
v8
,
K
the ninth mapping's key
k9
,
V
the ninth mapping's value
v9
,
K
the tenth mapping's key
k10
,
V
the tenth mapping's value
v10
)

Hides com.google.common.collect.ImmutableSortedMapFauxverideShim.of, java.util.Map.of.

Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.
public static <K, V> ImmutableSortedMap.Builder<K, V>
orderedBy(Comparator<K> comparator)

Returns a builder that creates immutable sorted maps with an explicit comparator.

public final Map.Entry<K, V>
pollFirstEntry()

Implements java.util.NavigableMap.pollFirstEntry.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the map unmodified.
public final Map.Entry<K, V>
pollLastEntry()

Implements java.util.NavigableMap.pollLastEntry.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the map unmodified.
private void
public static <K extends Comparable<?>, V> ImmutableSortedMap.Builder<K, V>
reverseOrder()

Returns a builder that creates immutable sorted maps whose keys are ordered by the reverse of their natural ordering.

public int
size()

Implements java.util.Map.size.

Returns the number of key-value mappings in this map.
public ImmutableSortedMap<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.NavigableMap.subMap.

This method returns a ImmutableSortedMap, consisting of the entries whose keys ranges from fromKey, inclusive, to toKey, exclusive.
public ImmutableSortedMap<K, V>
subMap(K
low endpoint of the keys in the returned map
fromKey
,
boolean
true if the low endpoint is to be included in the returned view
fromInclusive
,
K
high endpoint of the keys in the returned map
toKey
,
boolean
true if the high endpoint is to be included in the returned view
toInclusive
)

Implements java.util.NavigableMap.subMap.

This method returns a ImmutableSortedMap, consisting of the entries whose keys ranges from fromKey to toKey, inclusive or exclusive as indicated by the boolean flags.
public ImmutableSortedMap<K, V>
tailMap(K
low endpoint (inclusive) of the keys in the returned map
fromKey
)

Implements java.util.NavigableMap.tailMap.

This method returns a ImmutableSortedMap, consisting of the entries whose keys are greater than or equals to fromKey.
public ImmutableSortedMap<K, V>
tailMap(K
low endpoint of the keys in the returned map
fromKey
,
boolean
true if the low endpoint is to be included in the returned view
inclusive
)

Implements java.util.NavigableMap.tailMap.

This method returns a ImmutableSortedMap, consisting of the entries whose keys are greater than (or equal to, if inclusive) fromKey.
public static <T extends @Nullable Object, K, V> Collector<T, ?, ImmutableSortedMap<K, V>>
toImmutableSortedMap(Comparator<? super K> comparator, Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction)

Returns a Collector that accumulates elements into an ImmutableSortedMap whose keys and values are the result of applying the provided mapping functions to the input elements.

public static <T extends @Nullable Object, K, V> Collector<T, ?, ImmutableSortedMap<K, V>>
toImmutableSortedMap(Comparator<? super K> comparator, Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction, BinaryOperator<V> mergeFunction)

Returns a Collector that accumulates elements into an ImmutableSortedMap whose keys and values are the result of applying the provided mapping functions to the input elements.

public ImmutableCollection<V>
values()

Overrides com.google.common.collect.ImmutableMap.values.

Implements java.util.SortedMap.values, java.util.Map.values.

Returns an immutable collection of the values in this map, sorted by the ordering of the corresponding keys.
pack-priv Object
writeReplace()

Overrides com.google.common.collect.ImmutableMap.writeReplace.

Returns a serializable form of this object.
Inherited from com.google.common.collect.ImmutableSortedMapFauxverideShim:
builderbuilderWithExpectedSizeofEntriestoImmutableMaptoImmutableMap