Class ImmutableSortedMap<K,V>
- All Implemented Interfaces:
Serializable,Map<K,,V> NavigableMap<K,,V> SequencedMap<K,,V> SortedMap<K,V>
SortedMap. Does not permit null keys or values.
Unlike Collections.unmodifiableSortedMap(java.util.SortedMap<K, ? extends V>), which is a view
of a separate map which can still change, an instance of
ImmutableSortedMap contains its own data and will never change.
ImmutableSortedMap is convenient for public static final maps
("constant maps") and also lets you easily make a "defensive copy" of a map
provided to your class by a caller.
Note: Although this class is not final, it cannot be subclassed as it has no public or protected constructors. Thus, instances of this class are guaranteed to be immutable.
See the Guava User Guide article on immutable collections.
- Since:
- 2.0 (imported from Google Collections Library; implements
NavigableMapsince 12.0) - See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDeprecated.The Google Guava Core Libraries are deprecated and will not be part of the AEM SDK after April 2023 -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> ImmutableSortedMap.Builder <K, V> builder()Deprecated.UsenaturalOrder(), which offers better type-safety.ceilingEntry(K key) Deprecated.ceilingKey(K key) Deprecated.Comparator<? super K> Deprecated.Returns the comparator that orders the keys, which isOrdering.natural()when the natural ordering of the keys is used.booleancontainsValue(Object value) Deprecated.static <K,V> ImmutableSortedMap <K, V> Deprecated.Returns an immutable map containing the same entries asmap, sorted by the natural ordering of the keys.static <K,V> ImmutableSortedMap <K, V> copyOf(Map<? extends K, ? extends V> map, Comparator<? super K> comparator) Deprecated.Returns an immutable map containing the same entries asmap, with keys sorted by the provided comparator.static <K,V> ImmutableSortedMap <K, V> copyOfSorted(SortedMap<K, ? extends V> map) Deprecated.Returns an immutable map containing the same entries as the provided sorted map, with the same ordering.Deprecated.Deprecated.entrySet()Deprecated.Returns an immutable set of the mappings in this map, sorted by the key ordering.Deprecated.firstKey()Deprecated.floorEntry(K key) Deprecated.Deprecated.Deprecated.This method returns aImmutableSortedMap, consisting of the entries whose keys are less thantoKey.abstract ImmutableSortedMap<K, V> Deprecated.This method returns aImmutableSortedMap, consisting of the entries whose keys are less than (or equal to, ifinclusive)toKey.higherEntry(K key) Deprecated.Deprecated.abstract ImmutableSortedSet<K> keySet()Deprecated.Returns an immutable sorted set of the keys in this map.Deprecated.lastKey()Deprecated.lowerEntry(K key) Deprecated.Deprecated.static <K extends Comparable<?>,V>
ImmutableSortedMap.Builder<K, V> Deprecated.Returns a builder that creates immutable sorted maps whose keys are ordered by their natural ordering.Deprecated.static <K,V> ImmutableSortedMap <K, V> of()Deprecated.Returns the empty sorted map.static <K extends Comparable<? super K>,V>
ImmutableSortedMap<K, V> of(K k1, V v1) Deprecated.Returns an immutable map containing a single entry.static <K,V> ImmutableSortedMap <K, V> of(K k1, V v1) Deprecated.Pass a key of typeComparableto useof(Comparable, Object).static <K extends Comparable<? super K>,V>
ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2) Deprecated.Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.static <K,V> ImmutableSortedMap <K, V> of(K k1, V v1, K k2, V v2) Deprecated.Pass keys of typeComparableto useof(Comparable, Object, Comparable, Object).static <K extends Comparable<? super K>,V>
ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) Deprecated.Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.static <K,V> ImmutableSortedMap <K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) Deprecated.Pass keys of typeComparableto useof(Comparable, Object, Comparable, Object, Comparable, Object).static <K extends Comparable<? super K>,V>
ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) Deprecated.Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.static <K,V> ImmutableSortedMap <K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) Deprecated.Pass keys of typeComparableto useof(Comparable, Object, Comparable, Object, Comparable, Object, Comparable, Object).static <K extends Comparable<? super K>,V>
ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) Deprecated.Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.static <K,V> ImmutableSortedMap <K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) Deprecated.Pass keys of typeComparableto useof(Comparable, Object, Comparable, Object, Comparable, Object, Comparable, Object, Comparable, Object).static <K,V> ImmutableSortedMap.Builder <K, V> orderedBy(Comparator<K> comparator) Deprecated.Returns a builder that creates immutable sorted maps with an explicit comparator.Deprecated.Unsupported operation.Deprecated.Unsupported operation.static <K extends Comparable<?>,V>
ImmutableSortedMap.Builder<K, V> Deprecated.Returns a builder that creates immutable sorted maps whose keys are ordered by the reverse of their natural ordering.intsize()Deprecated.Deprecated.This method returns aImmutableSortedMap, consisting of the entries whose keys ranges fromfromKeytotoKey, inclusive or exclusive as indicated by the boolean flags.Deprecated.This method returns aImmutableSortedMap, consisting of the entries whose keys ranges fromfromKey, inclusive, totoKey, exclusive.Deprecated.This method returns aImmutableSortedMap, consisting of the entries whose keys are greater than or equals tofromKey.abstract ImmutableSortedMap<K, V> Deprecated.This method returns aImmutableSortedMap, consisting of the entries whose keys are greater than (or equal to, ifinclusive)fromKey.abstract ImmutableCollection<V> values()Deprecated.Returns an immutable collection of the values in this map, sorted by the ordering of the corresponding keys.Methods inherited from class com.google.common.collect.ImmutableMap
asMultimap, clear, containsKey, equals, get, hashCode, isEmpty, put, putAll, remove, toStringMethods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, equals, forEach, get, getOrDefault, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAllMethods inherited from interface java.util.NavigableMap
reversedMethods inherited from interface java.util.SequencedMap
sequencedEntrySet, sequencedKeySet, sequencedValues
-
Method Details
-
of
Deprecated.Returns the empty sorted map. -
of
Deprecated.Returns an immutable map containing a single entry. -
of
public static <K extends Comparable<? super K>,V> ImmutableSortedMap<K,V> of(K k1, V v1, K k2, V v2) Deprecated.Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.- Throws:
IllegalArgumentException- if the two keys are equal according to their natural ordering
-
of
public static <K extends Comparable<? super K>,V> ImmutableSortedMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3) Deprecated.Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.- Throws:
IllegalArgumentException- if any two keys are equal according to their natural ordering
-
of
public static <K extends Comparable<? super K>,V> ImmutableSortedMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) Deprecated.Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.- Throws:
IllegalArgumentException- if any two keys are equal according to their natural ordering
-
of
public static <K extends Comparable<? super K>,V> ImmutableSortedMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) Deprecated.Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.- Throws:
IllegalArgumentException- if any two keys are equal according to their natural ordering
-
copyOf
Deprecated.Returns an immutable map containing the same entries asmap, sorted by the natural ordering of the keys.Despite the method name, this method attempts to avoid actually copying the data when it is safe to do so. The exact circumstances under which a copy will or will not be performed are undocumented and subject to change.
This method is not type-safe, as it may be called on a map with keys that are not mutually comparable.
- Throws:
ClassCastException- if the keys inmapare not mutually comparableNullPointerException- if any key or value inmapis nullIllegalArgumentException- if any two keys are equal according to their natural ordering
-
copyOf
public static <K,V> ImmutableSortedMap<K,V> copyOf(Map<? extends K, ? extends V> map, Comparator<? super K> comparator) Deprecated.Returns an immutable map containing the same entries asmap, with keys sorted by the provided comparator.Despite the method name, this method attempts to avoid actually copying the data when it is safe to do so. The exact circumstances under which a copy will or will not be performed are undocumented and subject to change.
- Throws:
NullPointerException- if any key or value inmapis nullIllegalArgumentException- if any two keys are equal according to the comparator
-
copyOfSorted
Deprecated.Returns an immutable map containing the same entries as the provided sorted map, with the same ordering.Despite the method name, this method attempts to avoid actually copying the data when it is safe to do so. The exact circumstances under which a copy will or will not be performed are undocumented and subject to change.
- Throws:
NullPointerException- if any key or value inmapis null
-
naturalOrder
Deprecated.Returns a builder that creates immutable sorted maps whose keys are ordered by their natural ordering. The sorted maps useOrdering.natural()as the comparator. -
orderedBy
Deprecated.Returns a builder that creates immutable sorted maps with an explicit comparator. If the comparator has a more general type than the map's keys, such as creating aSortedMap<Integer, String>with aComparator<Number>, use theImmutableSortedMap.Builderconstructor instead.- Throws:
NullPointerException- ifcomparatoris null
-
reverseOrder
Deprecated.Returns a builder that creates immutable sorted maps whose keys are ordered by the reverse of their natural ordering. -
size
public int size()Deprecated. -
containsValue
Deprecated.- Specified by:
containsValuein interfaceMap<K,V> - Overrides:
containsValuein classImmutableMap<K,V>
-
entrySet
Deprecated.Returns an immutable set of the mappings in this map, sorted by the key ordering. -
keySet
Deprecated.Returns an immutable sorted set of the keys in this map. -
values
Deprecated.Returns an immutable collection of the values in this map, sorted by the ordering of the corresponding keys. -
comparator
Deprecated.Returns the comparator that orders the keys, which isOrdering.natural()when the natural ordering of the keys is used. Note that its behavior is not consistent withTreeMap.comparator(), which returnsnullto indicate natural ordering.- Specified by:
comparatorin interfaceSortedMap<K,V>
-
firstKey
Deprecated. -
lastKey
Deprecated. -
headMap
Deprecated.This method returns aImmutableSortedMap, consisting of the entries whose keys are less thantoKey.The
SortedMap.headMap(K)documentation states that a submap of a submap throws anIllegalArgumentExceptionif passed atoKeygreater than an earliertoKey. However, this method doesn't throw an exception in that situation, but instead keeps the originaltoKey. -
headMap
Deprecated.This method returns aImmutableSortedMap, consisting of the entries whose keys are less than (or equal to, ifinclusive)toKey.The
SortedMap.headMap(K)documentation states that a submap of a submap throws anIllegalArgumentExceptionif passed atoKeygreater than an earliertoKey. However, this method doesn't throw an exception in that situation, but instead keeps the originaltoKey.- Specified by:
headMapin interfaceNavigableMap<K,V> - Since:
- 12.0
-
subMap
Deprecated.This method returns aImmutableSortedMap, consisting of the entries whose keys ranges fromfromKey, inclusive, totoKey, exclusive.The
SortedMap.subMap(K, K)documentation states that a submap of a submap throws anIllegalArgumentExceptionif passed afromKeyless than an earlierfromKey. However, this method doesn't throw an exception in that situation, but instead keeps the originalfromKey. Similarly, this method keeps the originaltoKey, instead of throwing an exception, if passed atoKeygreater than an earliertoKey. -
subMap
public ImmutableSortedMap<K,V> subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) Deprecated.This method returns aImmutableSortedMap, consisting of the entries whose keys ranges fromfromKeytotoKey, inclusive or exclusive as indicated by the boolean flags.The
SortedMap.subMap(K, K)documentation states that a submap of a submap throws anIllegalArgumentExceptionif passed afromKeyless than an earlierfromKey. However, this method doesn't throw an exception in that situation, but instead keeps the originalfromKey. Similarly, this method keeps the originaltoKey, instead of throwing an exception, if passed atoKeygreater than an earliertoKey.- Specified by:
subMapin interfaceNavigableMap<K,V> - Since:
- 12.0
-
tailMap
Deprecated.This method returns aImmutableSortedMap, consisting of the entries whose keys are greater than or equals tofromKey.The
SortedMap.tailMap(K)documentation states that a submap of a submap throws anIllegalArgumentExceptionif passed afromKeyless than an earlierfromKey. However, this method doesn't throw an exception in that situation, but instead keeps the originalfromKey. -
tailMap
Deprecated.This method returns aImmutableSortedMap, consisting of the entries whose keys are greater than (or equal to, ifinclusive)fromKey.The
SortedMap.tailMap(K)documentation states that a submap of a submap throws anIllegalArgumentExceptionif passed afromKeyless than an earlierfromKey. However, this method doesn't throw an exception in that situation, but instead keeps the originalfromKey.- Specified by:
tailMapin interfaceNavigableMap<K,V> - Since:
- 12.0
-
lowerEntry
Deprecated.- Specified by:
lowerEntryin interfaceNavigableMap<K,V>
-
lowerKey
Deprecated.- Specified by:
lowerKeyin interfaceNavigableMap<K,V>
-
floorEntry
Deprecated.- Specified by:
floorEntryin interfaceNavigableMap<K,V>
-
floorKey
Deprecated.- Specified by:
floorKeyin interfaceNavigableMap<K,V>
-
ceilingEntry
Deprecated.- Specified by:
ceilingEntryin interfaceNavigableMap<K,V>
-
ceilingKey
Deprecated.- Specified by:
ceilingKeyin interfaceNavigableMap<K,V>
-
higherEntry
Deprecated.- Specified by:
higherEntryin interfaceNavigableMap<K,V>
-
higherKey
Deprecated.- Specified by:
higherKeyin interfaceNavigableMap<K,V>
-
firstEntry
Deprecated.- Specified by:
firstEntryin interfaceNavigableMap<K,V> - Specified by:
firstEntryin interfaceSequencedMap<K,V>
-
lastEntry
Deprecated.- Specified by:
lastEntryin interfaceNavigableMap<K,V> - Specified by:
lastEntryin interfaceSequencedMap<K,V>
-
pollFirstEntry
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the map unmodified.- Specified by:
pollFirstEntryin interfaceNavigableMap<K,V> - Specified by:
pollFirstEntryin interfaceSequencedMap<K,V> - Throws:
UnsupportedOperationException- always
-
pollLastEntry
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the map unmodified.- Specified by:
pollLastEntryin interfaceNavigableMap<K,V> - Specified by:
pollLastEntryin interfaceSequencedMap<K,V> - Throws:
UnsupportedOperationException- always
-
descendingMap
Deprecated.- Specified by:
descendingMapin interfaceNavigableMap<K,V>
-
descendingKeySet
Deprecated.- Specified by:
descendingKeySetin interfaceNavigableMap<K,V>
-
builder
Deprecated.UsenaturalOrder(), which offers better type-safety.Not supported. UsenaturalOrder(), which offers better type-safety, instead. This method exists only to hideImmutableMap.builder()from consumers ofImmutableSortedMap.- Throws:
UnsupportedOperationException- always
-
of
Deprecated.Pass a key of typeComparableto useof(Comparable, Object).Not supported. You are attempting to create a map that may contain a non-Comparablekey. Proper calls will resolve to the version inImmutableSortedMap, not this dummy version.- Throws:
UnsupportedOperationException- always
-
of
Deprecated.Pass keys of typeComparableto useof(Comparable, Object, Comparable, Object).Not supported. You are attempting to create a map that may contain non-Comparablekeys. Proper calls will resolve to the version inImmutableSortedMap, not this dummy version.- Throws:
UnsupportedOperationException- always
-
of
Deprecated.Pass keys of typeComparableto useof(Comparable, Object, Comparable, Object, Comparable, Object).Not supported. You are attempting to create a map that may contain non-Comparablekeys. Proper calls to will resolve to the version inImmutableSortedMap, not this dummy version.- Throws:
UnsupportedOperationException- always
-
of
@Deprecated public static <K,V> ImmutableSortedMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) Deprecated.Pass keys of typeComparableto useof(Comparable, Object, Comparable, Object, Comparable, Object, Comparable, Object).Not supported. You are attempting to create a map that may contain non-Comparablekeys. Proper calls will resolve to the version inImmutableSortedMap, not this dummy version.- Throws:
UnsupportedOperationException- always
-
of
@Deprecated public static <K,V> ImmutableSortedMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) Deprecated.Pass keys of typeComparableto useof(Comparable, Object, Comparable, Object, Comparable, Object, Comparable, Object, Comparable, Object).Not supported. You are attempting to create a map that may contain non-Comparablekeys. Proper calls will resolve to the version inImmutableSortedMap, not this dummy version.- Throws:
UnsupportedOperationException- always
-