K
- The type of keys in the map.V
- The type of values in the map.public class CheckedHashMap<K,V> extends LinkedHashMap<K,V> implements Cloneable
Map
. Type checks are performed at run-time in addition of
compile-time checks. The synchronization lock can be modified at runtime by overriding the getLock()
method.
This class is similar to using the wrappers provided in Collections
, minus the cost of
indirection levels and with the addition of overrideable methods.
Collections#checkedMap
,
Collections#synchronizedMap
,
Serialized FormAbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
CheckedHashMap(Class<K> keyType,
Class<V> valueType)
Constructs a map of the specified type.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkWritePermission()
Checks if changes in this collection are allowed.
|
void |
clear()
Removes all of the elements from this map.
|
CheckedHashMap<K,V> |
clone()
Returns a shallow copy of this map.
|
boolean |
containsKey(Object key)
Returns
true if this map contains the specified key. |
boolean |
containsValue(Object value)
Returns
true if this map contains the specified value. |
boolean |
equals(Object o)
Compares the specified object with this map for equality.
|
V |
get(Object key)
Returns the value to which the specified key is mapped, or
null if none. |
protected Object |
getLock()
Returns the synchronization lock.
|
int |
hashCode()
Returns the hash code value for this map.
|
boolean |
isEmpty()
Returns
true if this map contains no elements. |
V |
put(K key,
V value)
Associates the specified value with the specified key in this map.
|
void |
putAll(Map<? extends K,? extends V> m)
Copies all of the mappings from the specified map to this map.
|
V |
remove(Object key)
Removes the mapping for the specified key from this map if present.
|
int |
size()
Returns the number of elements in this map.
|
String |
toString()
Returns a string representation of this map.
|
entrySet, forEach, getOrDefault, keySet, removeEldestEntry, replaceAll, values
compute, computeIfAbsent, computeIfPresent, merge, putIfAbsent, remove, replace, replace
compute, computeIfAbsent, computeIfPresent, merge, putIfAbsent, remove, replace, replace
protected void checkWritePermission() throws UnsupportedOperationException
UnsupportedOperationException
- if this collection is unmodifiable.protected Object getLock()
this
. Subclasses
that override this method should be careful to update the lock reference when this set is
cloned.public int size()
public boolean isEmpty()
true
if this map contains no elements.public boolean containsKey(Object key)
true
if this map contains the specified key.containsKey
in interface Map<K,V>
containsKey
in class HashMap<K,V>
public boolean containsValue(Object value)
true
if this map contains the specified value.containsValue
in interface Map<K,V>
containsValue
in class LinkedHashMap<K,V>
public V get(Object key)
null
if none.public V put(K key, V value) throws IllegalArgumentException, UnsupportedOperationException
put
in interface Map<K,V>
put
in class HashMap<K,V>
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.null
.IllegalArgumentException
- if the key or the value is not of the expected type.UnsupportedOperationException
- if this collection is unmodifiable.public void putAll(Map<? extends K,? extends V> m) throws UnsupportedOperationException
public V remove(Object key) throws UnsupportedOperationException
public void clear() throws UnsupportedOperationException
clear
in interface Map<K,V>
clear
in class LinkedHashMap<K,V>
UnsupportedOperationException
- if this collection is unmodifiable.public String toString()
toString
in class AbstractMap<K,V>
public boolean equals(Object o)
public int hashCode()
public CheckedHashMap<K,V> clone()
clone
in class HashMap<K,V>
Object.clone()
Copyright © 1996–2023 Geotools. All rights reserved.