K - the key typeV - the value typepublic class ImmutableMap<K,V> extends ImmutableBase<ImmutableMapEntry<K,V>> implements Map<K,V>
Map.| Modifier and Type | Class and Description |
|---|---|
static class |
ImmutableMap.KeyIterator<K,V>
Implementation of
Iterator to iterate over the contents of a ImmutableMap.KeySet. |
static class |
ImmutableMap.KeySet<K,V>
Implementation of the
Set interface to provide a view of the keys in the ImmutableMap. |
static class |
ImmutableMap.ValueCollection<K,V>
Implementation of the
Collection interface to provide a view of the values in the ImmutableMap. |
static class |
ImmutableMap.ValueIterator<K,V>
Implementation of
Iterator to iterate over the contents of a ImmutableMap.ValueCollection. |
| Modifier and Type | Field and Description |
|---|---|
static ImmutableMapEntry<?,?>[] |
emptyEntryArray |
| Constructor and Description |
|---|
ImmutableMap(ImmutableMapEntry<K,V>[] array)
Construct an
ImmutableList with the given array (using the entire array). |
ImmutableMap(ImmutableMapEntry<K,V>[] array,
int length)
Construct an
ImmutableMap with the given array (of ImmutableMapEntry) and length. |
ImmutableMap(Map<K,V> map)
Construct an
ImmutableMap from another Map (helps with deserializing). |
| Modifier and Type | Method and Description |
|---|---|
static <KK,VV> boolean |
containsKey(ImmutableMapEntry<KK,VV>[] array,
int length,
KK key)
Test whether an array of
ImmutableMapEntry contains the specified key. |
static <KK,VV> boolean |
containsKey(List<ImmutableMapEntry<KK,VV>> list,
KK key)
Test whether a
List of ImmutableMapEntry contains the specified key. |
boolean |
containsKey(Object key)
Test whether the map contains a key equal to the specified key (which may be
null). |
boolean |
containsValue(Object value)
Test whether the map contains a value equal to the specified value (which may be
null). |
static <KK,VV> ImmutableMapEntry<KK,VV>[] |
createArray(int length)
Create an array of
ImmutableMapEntry, of the specified length. |
static <KK,VV> ImmutableMap<KK,VV> |
emptyMap()
Get an empty
ImmutableMap. |
static <KK,VV> ImmutableMapEntry<KK,VV> |
entry(KK key,
VV value)
Create a
ImmutableMapEntry. |
ImmutableSet<Map.Entry<K,V>> |
entrySet()
Get a
Set of the entries in this map. |
boolean |
equals(Object other)
Compares the specified object with this map for equality.
|
static <KK,VV> int |
findKey(ImmutableMapEntry<KK,VV>[] array,
int length,
Object key)
Locate a key in an array of
ImmutableMapEntry. |
static <KK,VV> ImmutableMap<KK,VV> |
from(List<ImmutableMapEntry<KK,VV>> list)
|
V |
get(Object key)
Get the value corresponding to the supplied key.
|
int |
hashCode()
Returns the hash code value for this map.
|
ImmutableMap.KeySet<K,V> |
keySet()
Get a
Set of the keys in use in this map. |
static <KK,VV> ImmutableMap<KK,VV> |
mapOf(ImmutableMapEntry<KK,VV>[] array)
Create an
ImmutableMap from the supplied array of ImmutableMapEntry. |
static <KK,VV> ImmutableMap<KK,VV> |
mapOf(ImmutableMapEntry<KK,VV>[] array,
int length)
Create an
ImmutableMap from the supplied array of ImmutableMapEntry with the specified length. |
V |
put(K key,
V value)
Modifying operation - not allowed.
|
void |
putAll(Map<? extends K,? extends V> m)
Modifying operation - not allowed.
|
V |
remove(Object key)
Modifying operation - not allowed.
|
String |
toString()
Returns a string representation of this map.
|
ImmutableMap.ValueCollection<K,V> |
values()
Get a
Collection of the values in this map. |
clear, isEmpty, sizeclone, finalize, getClass, notify, notifyAll, wait, wait, waitclear, compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, isEmpty, merge, putIfAbsent, remove, replace, replace, replaceAll, sizepublic static ImmutableMapEntry<?,?>[] emptyEntryArray
public ImmutableMap(ImmutableMapEntry<K,V>[] array, int length)
ImmutableMap with the given array (of ImmutableMapEntry) and length.array - the array of ImmutableMapEntrylength - the length (the number of array items to be considered part of the map)IndexOutOfBoundsException - if the length is less than 0 or greater than the array lengthpublic ImmutableMap(ImmutableMapEntry<K,V>[] array)
ImmutableList with the given array (using the entire array).array - the array of ImmutableMapEntrypublic boolean containsKey(Object key)
null).containsKey in interface Map<K,V>key - the keytrue if the map contains the keypublic boolean containsValue(Object value)
null).containsValue in interface Map<K,V>value - the valuetrue if the map contains the valuepublic V get(Object key)
null is returned.public ImmutableMap.KeySet<K,V> keySet()
Set of the keys in use in this map. The set is backed by the original array, and retains the
original order.public ImmutableMap.ValueCollection<K,V> values()
Collection of the values in this map. The collection is backed by the original array, and retains
the original order.values in interface Map<K,V>Collectionpublic ImmutableSet<Map.Entry<K,V>> entrySet()
Set of the entries in this map. The set is backed by the original array, and retains the original
order.public boolean equals(Object other)
true if the given object is also a
map, the maps contains the same number of entries and for each key in one map, the values returned by both maps
are equal (either both are null, or they compare as equal using Object.equals(java.lang.Object)). This ensures
that the equals method works properly across different implementations of the Map interface.public int hashCode()
entrySet() view. This ensures that m1.equals(m2) implies that
m1.hashCode() == m2.hashCode() for any two maps m1 and m2, as required by the general
contract of Object.hashCode().public String toString()
String.valueOf(Object).public V put(K key, V value)
put in interface Map<K,V>UnsupportedOperationException - (in all cases)public V remove(Object key)
remove in interface Map<K,V>UnsupportedOperationException - (in all cases)public void putAll(Map<? extends K,? extends V> m)
putAll in interface Map<K,V>UnsupportedOperationException - (in all cases)public static <KK,VV> ImmutableMap<KK,VV> from(List<ImmutableMapEntry<KK,VV>> list)
KK - the key typeVV - the value typelist - the List of ImmutableMapEntryImmutableMappublic static <KK,VV> ImmutableMap<KK,VV> emptyMap()
ImmutableMap. This avoids a memory allocation if the list is empty.KK - the key typeVV - the value typepublic static <KK,VV> ImmutableMap<KK,VV> mapOf(ImmutableMapEntry<KK,VV>[] array)
ImmutableMap from the supplied array of ImmutableMapEntry.KK - the key typeVV - the value typearray - the array of ImmutableMapEntryImmutableMappublic static <KK,VV> ImmutableMap<KK,VV> mapOf(ImmutableMapEntry<KK,VV>[] array, int length)
ImmutableMap from the supplied array of ImmutableMapEntry with the specified length.KK - the key typeVV - the value typearray - the array of ImmutableMapEntrylength - the length (the number of array items to be considered part of the map)ImmutableMappublic static <KK,VV> ImmutableMapEntry<KK,VV> entry(KK key, VV value)
ImmutableMapEntry.KK - the key typeVV - the value typekey - the keyvalue - the valueImmutableMapEntrypublic static <KK,VV> ImmutableMapEntry<KK,VV>[] createArray(int length)
ImmutableMapEntry, of the specified length.KK - the key typeVV - the value typelength - the lengthpublic static <KK,VV> boolean containsKey(ImmutableMapEntry<KK,VV>[] array, int length, KK key)
ImmutableMapEntry contains the specified key. The ImmutableMap
constructor does not check for duplicate keys, so this function provides a means of checking prior to
construction.KK - the key typeVV - the value typearray - the arraylength - the length so far (the number of elements to be checked against)key - the new keytrue if the key exists in the arraypublic static <KK,VV> boolean containsKey(List<ImmutableMapEntry<KK,VV>> list, KK key)
List of ImmutableMapEntry contains the specified key. The ImmutableMap
constructor does not check for duplicate keys, so this function provides a means of checking prior to
construction.public static <KK,VV> int findKey(ImmutableMapEntry<KK,VV>[] array, int length, Object key)
ImmutableMapEntry. This is used both to check for duplicates prior to
construction, and to find a value corresponding to a key in a map.KK - the key typeVV - the value typearray - the arraylength - the length so far (the number of elements to be checked against)key - the new keyCopyright © 2022. All rights reserved.