org.gcube.common.vremanagement.deployer.impl.state
Class CountableHashMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by org.gcube.common.vremanagement.deployer.impl.state.CountableHashMap<K,V>
Type Parameters:
K - the key type
V - the value type
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>

public class CountableHashMap<K,V>
extends HashMap<K,V>
implements Serializable

An extension of the standard HashMap handling multiple instances of the same key, all mapped on the same value. This extension behaves as follows:

Author:
Manuele Simi (ISTI-CNR)
See Also:
HashMap, Map, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
CountableHashMap()
          
CountableHashMap(int initialCapacity)
          
CountableHashMap(int initialCapacity, float loadFactor)
          
CountableHashMap(Map<K,V> m)
          
 
Method Summary
 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)
          
 
Methods inherited from class java.util.HashMap
clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

CountableHashMap

public CountableHashMap()


CountableHashMap

public CountableHashMap(int initialCapacity)


CountableHashMap

public CountableHashMap(Map<K,V> m)


CountableHashMap

public CountableHashMap(int initialCapacity,
                        float loadFactor)

Method Detail

clear

public void clear()

Specified by:
clear in interface Map<K,V>
Overrides:
clear in class HashMap<K,V>

put

public V put(K key,
             V value)

Specified by:
put in interface Map<K,V>
Overrides:
put in class HashMap<K,V>

putAll

public void putAll(Map<? extends K,? extends V> m)

Specified by:
putAll in interface Map<K,V>
Overrides:
putAll in class HashMap<K,V>

remove

public V remove(Object key)

Specified by:
remove in interface Map<K,V>
Overrides:
remove in class HashMap<K,V>

countableRemove

public int countableRemove(Object key)
Removes the mapping for this key from this CountableHashMap if present

Parameters:
key - key whose mapping is to be removed from the map
Returns:
the remaining number of instances of the key still in the map

countablePut

public int countablePut(K key,
                        V value)
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.

Parameters:
key - key with which the specified value is to be associated
value - value to be associated with the specified key
Returns:
the number of instances of the key in the map

countablePutAll

public 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.

Parameters:
m - mappings to be stored in this map.
Returns:
the number of instances of each key in the map
Throws:
NullPointerException - if the specified map is null.

getCounter

public int getCounter(Object key)
Gets the key counter of the given element

Parameters:
key - the key to count
Returns:
the key counter


Copyright © 2012. All Rights Reserved.