Package org.geotools.util
Class CheckedHashMap<K,V>
Object
AbstractMap<K,V>
HashMap<K,V>
LinkedHashMap<K,V>
CheckedHashMap<K,V>
- Type Parameters:
K
- The type of keys in the map.V
- The type of values in the map.
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<K,
,V> Cloneable
A checked and synchronized
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.
- Since:
- 2.1
- Author:
- Jody Garnett (Refractions Research), Martin Desruisseaux (IRD)
- See Also:
-
Collections#checkedMap
Collections#synchronizedMap
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
ConstructorsConstructorDescriptionCheckedHashMap
(Class<K> keyType, Class<V> valueType) Constructs a map of the specified type. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Checks if changes in this collection are allowed.void
clear()
Removes all of the elements from this map.clone()
Returns a shallow copy of this map.boolean
containsKey
(Object key) Returnstrue
if this map contains the specified key.boolean
containsValue
(Object value) Returnstrue
if this map contains the specified value.boolean
Compares the specified object with this map for equality.Returns the value to which the specified key is mapped, ornull
if none.protected Object
getLock()
Returns the synchronization lock.int
hashCode()
Returns the hash code value for this map.boolean
isEmpty()
Returnstrue
if this map contains no elements.Associates the specified value with the specified key in this map.void
Copies all of the mappings from the specified map to this map.Removes the mapping for the specified key from this map if present.int
size()
Returns the number of elements in this map.toString()
Returns a string representation of this map.Methods inherited from class LinkedHashMap
entrySet, forEach, getOrDefault, keySet, removeEldestEntry, replaceAll, values
Methods inherited from class HashMap
compute, computeIfAbsent, computeIfPresent, merge, putIfAbsent, remove, replace, replace
Methods inherited from interface Map
compute, computeIfAbsent, computeIfPresent, merge, putIfAbsent, remove, replace, replace
-
Constructor Details
-
CheckedHashMap
Constructs a map of the specified type.- Parameters:
keyType
- The key type (should not be null).valueType
- The value type (should not be null).
-
-
Method Details
-
checkWritePermission
Checks if changes in this collection are allowed. This method is automatically invoked after this collection got the lock and before any operation that may change the content. The default implementation does nothing (i.e. this collection is modifiable). Subclasses should override this method if they want to control write access.- Throws:
UnsupportedOperationException
- if this collection is unmodifiable.- Since:
- 2.5
-
getLock
Returns the synchronization lock. The default implementation returnsthis
. Subclasses that override this method should be careful to update the lock reference when this set is cloned.- Returns:
- The synchronization lock.
- Since:
- 2.5
-
size
public int size()Returns the number of elements in this map. -
isEmpty
public boolean isEmpty()Returnstrue
if this map contains no elements. -
containsKey
Returnstrue
if this map contains the specified key.- Specified by:
containsKey
in interfaceMap<K,
V> - Overrides:
containsKey
in classHashMap<K,
V>
-
containsValue
Returnstrue
if this map contains the specified value.- Specified by:
containsValue
in interfaceMap<K,
V> - Overrides:
containsValue
in classLinkedHashMap<K,
V>
-
get
Returns the value to which the specified key is mapped, ornull
if none. -
put
Associates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced.- Specified by:
put
in interfaceMap<K,
V> - Overrides:
put
in classHashMap<K,
V> - Parameters:
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.- Returns:
- previous value associated with specified key, or
null
. - Throws:
IllegalArgumentException
- if the key or the value is not of the expected type.UnsupportedOperationException
- if this collection is unmodifiable.
-
putAll
Copies all of the mappings from the specified map to this map. -
remove
Removes the mapping for the specified key from this map if present. -
clear
Removes all of the elements from this map.- Specified by:
clear
in interfaceMap<K,
V> - Overrides:
clear
in classLinkedHashMap<K,
V> - Throws:
UnsupportedOperationException
- if this collection is unmodifiable.
-
toString
Returns a string representation of this map.- Overrides:
toString
in classAbstractMap<K,
V>
-
equals
Compares the specified object with this map for equality. -
hashCode
public int hashCode()Returns the hash code value for this map. -
clone
Returns a shallow copy of this map.
-