K - T - public class RefCountingMap<K,T> extends Object
The same (key,value) pair can be added to the map several times and then removed several times. A reference count is incremented for each addition and, provided the count is greater than 0, decremented on removal.
The pair is removed from the map when a remove decrements the reference count to 0.
This class is thread safe.
| Constructor and Description |
|---|
RefCountingMap() |
| Modifier and Type | Method and Description |
|---|---|
void |
add(K key,
T value)
Add a key value pair to the map.
|
void |
clear()
Clear the map of all keys regardless of reference counts.
|
boolean |
contains(K key) |
boolean |
containsKey(Object key) |
T |
get(Object key)
Return the value associated with a key in the map.
|
boolean |
isEmpty() |
Collection<K> |
keys() |
Set<K> |
keySet() |
int |
refCount(K key)
Return the reference count for the entry corresponding to a key in the map.
|
void |
remove(K key)
Decrement the reference count for a key, and remove the corresponding entry from the map
if the result is 0.
|
void |
removeAll(K key)
Remove the entry corresponding to the key from the map completely.
|
int |
size() |
public boolean contains(K key)
public Collection<K> keys()
public int size()
public boolean isEmpty()
public void clear()
public boolean containsKey(Object key)
public void add(K key, T value)
if there is no entry in the map for the key, then a key value pair is added to the map with a reference count of 1.
If there is already an entry in the map for the same key and value, the reference count for that entry is incremented.
if there is an entry in the map for the key, but with a different value, then that entry is replaced with a new entry for the key and value with a reference count of 1.
key - value - public void remove(K key)
Do nothing if there is no entry in the map corresponding to the key.
key - public void removeAll(K key)
This method ignores the reference count.
key - public int refCount(K key)
Returns 0 if there is no entry in the map corresponding to the key.
key - Licenced under the Apache License, Version 2.0