|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectAbstractMap<K,V>
HashMap<K,V>
LinkedHashMap<K,V>
CheckedHashMap<K,V>
K
- The type of keys in the map.V
- The type of values in the map.public class CheckedHashMap<K,V>
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.
Collections#checkedMap
,
Collections#synchronizedMap
,
Serialized Form
Constructor Summary | |
---|---|
CheckedHashMap(Class<K> keyType,
Class<V> valueType)
Constructs a map of the specified type. |
Method Summary | |
---|---|
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. |
Methods inherited from class LinkedHashMap |
---|
removeEldestEntry |
Methods inherited from class HashMap |
---|
entrySet, keySet, values |
Methods inherited from class Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface Map |
---|
entrySet, keySet, values |
Constructor Detail |
---|
public CheckedHashMap(Class<K> keyType, Class<V> valueType)
keyType
- The key type (should not be null).valueType
- The value type (should not be null).Method Detail |
---|
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()
size
in interface Map<K,V>
size
in class HashMap<K,V>
public boolean isEmpty()
true
if this map contains no elements.
isEmpty
in interface Map<K,V>
isEmpty
in class HashMap<K,V>
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.
get
in interface Map<K,V>
get
in class LinkedHashMap<K,V>
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
putAll
in interface Map<K,V>
putAll
in class HashMap<K,V>
UnsupportedOperationException
- if this collection is unmodifiable.public V remove(Object key) throws UnsupportedOperationException
remove
in interface Map<K,V>
remove
in class HashMap<K,V>
UnsupportedOperationException
- if this collection is unmodifiable.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)
equals
in interface Map<K,V>
equals
in class AbstractMap<K,V>
public int hashCode()
hashCode
in interface Map<K,V>
hashCode
in class AbstractMap<K,V>
public CheckedHashMap<K,V> clone()
clone
in class HashMap<K,V>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |