K - the key typeV - the value typepublic class CountableHashMap<K,V> extends HashMap<K,V> implements Serializable
HashMap handling multiple instances of the same key, all mapped on the same value.
This extension behaves as follows:
put(Object, Object) or a putAll(Map) are invoked, if the given key exists,
a counter for the key is increased, otherwise the element is added to the CountableHashMap object and a new counter is created.
remove(Object) is invoked, the key is removed only if the related counter value is 1.
HashMap,
Map,
Serialized FormAbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>| Constructor and Description |
|---|
CountableHashMap() |
CountableHashMap(int initialCapacity) |
CountableHashMap(int initialCapacity,
float loadFactor) |
CountableHashMap(Map<K,V> m) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
int |
countablePut(K key,
V value)
Associates the specified value with the specified key in this map.
|
Map<? extends K,Integer> |
countablePutAll(Map<? extends K,? extends V> m)
Copies all of the mappings from the specified map to this map
These mappings will replace any mappings that
this map had for any of the keys currently in the specified map.
|
int |
countableRemove(Object key)
Removes the mapping for this key from this CountableHashMap if present
|
int |
getCounter(Object key)
Gets the key counter of the given element
|
V |
put(K key,
V value) |
void |
putAll(Map<? extends K,? extends V> m) |
V |
remove(Object key) |
clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, size, valuesequals, hashCode, toStringpublic CountableHashMap()
public CountableHashMap(int initialCapacity)
public CountableHashMap(int initialCapacity,
float loadFactor)
public void clear()
public int countableRemove(Object key)
key - key whose mapping is to be removed from the mappublic int countablePut(K key, V value)
key - key with which the specified value is to be associatedvalue - value to be associated with the specified keypublic Map<? extends K,Integer> countablePutAll(Map<? extends K,? extends V> m)
m - mappings to be stored in this map.NullPointerException - if the specified map is null.public int getCounter(Object key)
key - the key to countCopyright © 2015. All Rights Reserved.