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
 
 public class CheckedHashMap<K,V> extends LinkedHashMap<K,V> implements Cloneable A checked and synchronizedMap. Type checks are performed at run-time in addition of compile-time checks. The synchronization lock can be modified at runtime by overriding thegetLock()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 AbstractMapAbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
 
- 
 - 
Constructor SummaryConstructors Constructor Description CheckedHashMap(Class<K> keyType, Class<V> valueType)Constructs a map of the specified type.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckWritePermission()Checks if changes in this collection are allowed.voidclear()Removes all of the elements from this map.CheckedHashMap<K,V>clone()Returns a shallow copy of this map.booleancontainsKey(Object key)Returnstrueif this map contains the specified key.booleancontainsValue(Object value)Returnstrueif this map contains the specified value.booleanequals(Object o)Compares the specified object with this map for equality.Vget(Object key)Returns the value to which the specified key is mapped, ornullif none.protected ObjectgetLock()Returns the synchronization lock.inthashCode()Returns the hash code value for this map.booleanisEmpty()Returnstrueif this map contains no elements.Vput(K key, V value)Associates the specified value with the specified key in this map.voidputAll(Map<? extends K,? extends V> m)Copies all of the mappings from the specified map to this map.Vremove(Object key)Removes the mapping for the specified key from this map if present.intsize()Returns the number of elements in this map.StringtoString()Returns a string representation of this map.- 
Methods inherited from class LinkedHashMapentrySet, forEach, getOrDefault, keySet, removeEldestEntry, replaceAll, values
 - 
Methods inherited from class HashMapcompute, computeIfAbsent, computeIfPresent, merge, putIfAbsent, remove, replace, replace
 - 
Methods inherited from interface Mapcompute, computeIfAbsent, computeIfPresent, merge, putIfAbsent, remove, replace, replace
 
- 
 
- 
- 
- 
Method Detail- 
checkWritePermissionprotected void checkWritePermission() throws UnsupportedOperationExceptionChecks 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
 
 - 
getLockprotected Object 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
 
 - 
sizepublic int size() Returns the number of elements in this map.
 - 
isEmptypublic boolean isEmpty() Returnstrueif this map contains no elements.
 - 
containsKeypublic boolean containsKey(Object key) Returnstrueif this map contains the specified key.- Specified by:
- containsKeyin interface- Map<K,V>
- Overrides:
- containsKeyin class- HashMap<K,V>
 
 - 
containsValuepublic boolean containsValue(Object value) Returnstrueif this map contains the specified value.- Specified by:
- containsValuein interface- Map<K,V>
- Overrides:
- containsValuein class- LinkedHashMap<K,V>
 
 - 
getpublic V get(Object key) Returns the value to which the specified key is mapped, ornullif none.
 - 
putpublic V put(K key, V value) throws IllegalArgumentException, UnsupportedOperationException 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:
- putin interface- Map<K,V>
- Overrides:
- putin class- HashMap<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.
 
 - 
putAllpublic void putAll(Map<? extends K,? extends V> m) throws UnsupportedOperationException Copies all of the mappings from the specified map to this map.
 - 
removepublic V remove(Object key) throws UnsupportedOperationException Removes the mapping for the specified key from this map if present.
 - 
clearpublic void clear() throws UnsupportedOperationExceptionRemoves all of the elements from this map.- Specified by:
- clearin interface- Map<K,V>
- Overrides:
- clearin class- LinkedHashMap<K,V>
- Throws:
- UnsupportedOperationException- if this collection is unmodifiable.
 
 - 
toStringpublic String toString() Returns a string representation of this map.- Overrides:
- toStringin class- AbstractMap<K,V>
 
 - 
equalspublic boolean equals(Object o) Compares the specified object with this map for equality.
 - 
hashCodepublic int hashCode() Returns the hash code value for this map.
 - 
clonepublic CheckedHashMap<K,V> clone() Returns a shallow copy of this map.
 
- 
 
-