public class WeakConcurrentMap<K,V> extends ReferenceQueue<K> implements Runnable, Iterable<Map.Entry<K,V>>
A thread-safe map with weak keys. Entries are based on a key's system hash code and keys are considered equal only by reference equality.
This class does not implement theMap
interface because this implementation is incompatible
with the map contract. While iterating over a map's entries, any key that has not passed iteration is referenced non-weakly.Modifier and Type | Class and Description |
---|---|
static class |
WeakConcurrentMap.WithInlinedExpunction<K,V>
A
WeakConcurrentMap where stale entries are removed as a side effect of interacting with this map. |
Modifier and Type | Field and Description |
---|---|
ConcurrentMap<org.mockito.internal.util.concurrent.WeakConcurrentMap.WeakKey<K>,V> |
target |
Constructor and Description |
---|
WeakConcurrentMap(boolean cleanerThread) |
Modifier and Type | Method and Description |
---|---|
int |
approximateSize()
Returns the approximate size of this map where the returned number is at least as big as the actual number of entries.
|
void |
clear()
Clears the entire map.
|
boolean |
containsKey(K key) |
protected V |
defaultValue(K key)
Creates a default value.
|
void |
expungeStaleEntries()
Cleans all unused references.
|
V |
get(K key) |
Thread |
getCleanerThread() |
Iterator<Map.Entry<K,V>> |
iterator() |
V |
put(K key,
V value) |
V |
remove(K key) |
void |
run() |
poll, remove, remove
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public final ConcurrentMap<org.mockito.internal.util.concurrent.WeakConcurrentMap.WeakKey<K>,V> target
public WeakConcurrentMap(boolean cleanerThread)
cleanerThread
- true
if a thread should be started that removes stale entries.public V get(K key)
key
- The key of the entry.public boolean containsKey(K key)
key
- The key of the entry.true
if the key already defines a value.public V put(K key, V value)
key
- The key of the entry.value
- The value of the entry.null
if it does not exist.public V remove(K key)
key
- The key of the entry.null
if it does not exist.public void clear()
protected V defaultValue(K key)
key
- The key for which to create a default value.null
for not defining a default value.public Thread getCleanerThread()
null
if no such thread was set.public void expungeStaleEntries()
public int approximateSize()
Copyright © 2019. All rights reserved.