K
- type of the map keysV
- type of the map valuespublic final class UnmodifiableHashMap<K,V>
extends java.lang.Object
implements java.util.Map<K,V>
Modifier and Type | Method and Description |
---|---|
void |
clear()
Deprecated.
Unsupported operation: this map is immutable. Use
empty() to get an empty UnmodifiableHashMap . |
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
static <K,V> UnmodifiableHashMap<K,V> |
empty()
Returns an empty
UnmodifiableHashMap with canonical equals/hashCode strategy. |
static <K,V> UnmodifiableHashMap<K,V> |
empty(<any> strategy)
Returns an empty
UnmodifiableHashMap with supplied strategy. |
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet() |
boolean |
equals(java.lang.Object obj) |
void |
forEach(java.util.function.BiConsumer<? super K,? super V> action) |
static <K,V> UnmodifiableHashMap<K,V> |
fromMap(<any> strategy,
java.util.Map<? extends K,? extends V> map)
Returns an
UnmodifiableHashMap which contains all the entries of the supplied map. |
static <K,V> UnmodifiableHashMap<K,V> |
fromMap(java.util.Map<K,V> map)
Returns an
UnmodifiableHashMap which contains all the entries of the supplied map. |
V |
get(java.lang.Object key) |
V |
getOrDefault(java.lang.Object key,
V defaultValue) |
int |
hashCode() |
boolean |
isEmpty() |
java.util.Set<K> |
keySet() |
V |
put(K key,
V value)
Deprecated.
Unsupported operation: this map is immutable. Use
with(Object, Object) to create a new
UnmodifiableHashMap with an additional element. |
void |
putAll(java.util.Map<? extends K,? extends V> m)
Deprecated.
Unsupported operation: this map is immutable. Use
withAll(Map) to create a new
UnmodifiableHashMap with additional elements from the specified Map. |
V |
remove(java.lang.Object key)
Deprecated.
Unsupported operation: this map is immutable. Use
without(Object) to create a new
UnmodifiableHashMap without some element. |
int |
size() |
java.lang.String |
toString() |
java.util.Collection<V> |
values() |
UnmodifiableHashMap<K,V> |
with(K key,
V value)
Returns an
UnmodifiableHashMap which contains all the entries as this map plus the supplied mapping |
UnmodifiableHashMap<K,V> |
withAll(java.util.Map<? extends K,? extends V> map)
Returns an
UnmodifiableHashMap which contains all the entries as this map plus all the mappings
of the supplied map. |
UnmodifiableHashMap<K,V> |
without(K key)
Returns an
UnmodifiableHashMap which contains all the entries as this map except the supplied key. |
public static <K,V> UnmodifiableHashMap<K,V> empty()
UnmodifiableHashMap
with canonical equals/hashCode strategy.K
- type of map keysV
- type of map valuesUnmodifiableHashMap
.TObjectHashingStrategy#CANONICAL
public static <K,V> UnmodifiableHashMap<K,V> empty(<any> strategy)
UnmodifiableHashMap
with supplied strategy.K
- type of map keysV
- type of map valuesstrategy
- strategy to compare keysUnmodifiableHashMap
.public static <K,V> UnmodifiableHashMap<K,V> fromMap(java.util.Map<K,V> map)
UnmodifiableHashMap
which contains all the entries of the supplied map.K
- type of map keysV
- type of map valuesmap
- map to copy values fromUnmodifiableHashMap
. Map return the supplied map if
it's already an UnmodifiableHashMap
which uses the same equals/hashCode strategy.public static <K,V> UnmodifiableHashMap<K,V> fromMap(<any> strategy, java.util.Map<? extends K,? extends V> map)
UnmodifiableHashMap
which contains all the entries of the supplied map. It's assumed that the supplied
map remains unchanged during the fromMap
call.K
- type of map keysV
- type of map valuesstrategy
- strategy to compare keysmap
- map to copy values fromUnmodifiableHashMap
. Map return the supplied map if
it's already an UnmodifiableHashMap
which uses the same equals/hashCode strategy.public UnmodifiableHashMap<K,V> without(K key)
UnmodifiableHashMap
which contains all the entries as this map except the supplied key.key
- a key to exclude from the resultUnmodifiableHashMap
which contains all the entries as this map except the supplied keypublic UnmodifiableHashMap<K,V> with(K key, V value)
UnmodifiableHashMap
which contains all the entries as this map plus the supplied mappingkey
- a key to add/replacevalue
- a value to associate with the keyUnmodifiableHashMap
which contains all the entries as this map plus the supplied mapping.
May return the same map if given key is already associated with the same value. Note however that if value is
not the same but equal object, the new map will be created as sometimes it's desired to replace the object with
another one which is equal to the old object.public UnmodifiableHashMap<K,V> withAll(java.util.Map<? extends K,? extends V> map)
UnmodifiableHashMap
which contains all the entries as this map plus all the mappings
of the supplied map.map
- to add entries fromUnmodifiableHashMap
which contains all the entries as this map plus all the mappings
of the supplied map. May (but not guaranteed) return the same map if the supplied map is empty or all its
mappings already exist in this map (assuming values are compared by reference). The equals/hashCode strategy
of the resulting map is the same as the strategy of this map.public boolean containsKey(java.lang.Object key)
public boolean containsValue(java.lang.Object value)
public int hashCode()
public boolean equals(java.lang.Object obj)
@Deprecated public V put(K key, V value)
with(Object, Object)
to create a new
UnmodifiableHashMap
with an additional element.@Deprecated public V remove(java.lang.Object key)
without(Object)
to create a new
UnmodifiableHashMap
without some element.@Deprecated public void putAll(java.util.Map<? extends K,? extends V> m)
withAll(Map)
to create a new
UnmodifiableHashMap
with additional elements from the specified Map.@Deprecated public void clear()
empty()
to get an empty UnmodifiableHashMap
.public java.lang.String toString()
toString
in class java.lang.Object