public abstract class AbstractWeakConcurrentMap<K,V,L> 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 offers an abstract-base implementation that allows to override methods.
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 |
AbstractWeakConcurrentMap.WeakKey<K> |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractWeakConcurrentMap() |
protected |
AbstractWeakConcurrentMap(ConcurrentMap<AbstractWeakConcurrentMap.WeakKey<K>,V> target) |
| 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) |
V |
getIfPresent(K key) |
protected abstract L |
getLookupKey(K key)
Override with care as it can cause lookup failures if done incorrectly.
|
Iterator<Map.Entry<K,V>> |
iterator() |
V |
put(K key,
V value) |
V |
putIfAbsent(K key,
V value) |
V |
putIfProbablyAbsent(K key,
V value) |
V |
remove(K key) |
protected abstract void |
resetLookupKey(L lookupKey)
Resets any reusable state in the lookup key.
|
void |
run() |
String |
toString() |
poll, remove, removeclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforEach, spliteratorprotected AbstractWeakConcurrentMap()
protected AbstractWeakConcurrentMap(ConcurrentMap<AbstractWeakConcurrentMap.WeakKey<K>,V> target)
target - ConcurrentMap implementation that this class wraps.protected abstract L getLookupKey(K key)
Object.hashCode() as the input and be equal to
a weak reference of the key. When overriding this, also override resetLookupKey(L).protected abstract void resetLookupKey(L lookupKey)
public V get(K key)
key - The key of the entry.public V getIfPresent(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 putIfAbsent(K key, V value)
key - The key of the entry.value - The value of the entry.null if it does not exist.public V putIfProbablyAbsent(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 void expungeStaleEntries()
public int approximateSize()
Copyright © 2016–2020. All rights reserved.