Class PrivateMaxEntriesMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- com.fasterxml.jackson.databind.util.internal.PrivateMaxEntriesMap<K,V>
-
- Type Parameters:
K
- the type of keys maintained by this mapV
- the type of mapped values
- All Implemented Interfaces:
java.io.Serializable
,java.util.concurrent.ConcurrentMap<K,V>
,java.util.Map<K,V>
public final class PrivateMaxEntriesMap<K,V> extends java.util.AbstractMap<K,V> implements java.util.concurrent.ConcurrentMap<K,V>, java.io.Serializable
A hash table supporting full concurrency of retrievals, adjustable expected concurrency for updates, and a maximum capacity to bound the map by. This implementation differs fromConcurrentHashMap
in that it maintains a page replacement algorithm that is used to evict an entry when the map has exceeded its capacity. Unlike the Java Collections Framework, this map does not have a publicly visible constructor and instances are created through aPrivateMaxEntriesMap.Builder
.An entry is evicted from the map when the entry size exceeds its maximum capacity threshold.
An
EvictionListener
may be supplied for notification when an entry is evicted from the map. This listener is invoked on a caller's thread and will not block other threads from operating on the map. An implementation should be aware that the caller's thread will not expect long execution times or failures as a side effect of the listener being notified. Execution safety and a fast turn around time can be achieved by performing the operation asynchronously, such as by submitting a task to anExecutorService
.The concurrency level determines the number of threads that can concurrently modify the table. Using a significantly higher or lower value than needed can waste space or lead to thread contention, but an estimate within an order of magnitude of the ideal value does not usually have a noticeable impact. Because placement in hash tables is essentially random, the actual concurrency will vary.
This class and its views and iterators implement all of the optional methods of the
Map
andIterator
interfaces.Like
Hashtable
but unlikeHashMap
, this class does not allow null to be used as a key or value. UnlikeLinkedHashMap
, this class does not provide predictable iteration order. A snapshot of the keys and entries may be obtained in ascending and descending order of retention.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PrivateMaxEntriesMap.Builder<K,V>
A builder that createsPrivateMaxEntriesMap
instances.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
capacity()
Retrieves the maximum capacity of the map.void
clear()
boolean
containsKey(java.lang.Object key)
boolean
containsValue(java.lang.Object value)
java.util.Set<java.util.Map.Entry<K,V>>
entrySet()
V
get(java.lang.Object key)
boolean
isEmpty()
java.util.Set<K>
keySet()
V
put(K key, V value)
V
putIfAbsent(K key, V value)
V
remove(java.lang.Object key)
boolean
remove(java.lang.Object key, java.lang.Object value)
V
replace(K key, V value)
boolean
replace(K key, V oldValue, V newValue)
void
setCapacity(long capacity)
Sets the maximum capacity of the map and eagerly evicts entries until it shrinks to the appropriate size.int
size()
java.util.Collection<V>
values()
-
-
-
Method Detail
-
capacity
public long capacity()
Retrieves the maximum capacity of the map.- Returns:
- the maximum capacity
-
setCapacity
public void setCapacity(long capacity)
Sets the maximum capacity of the map and eagerly evicts entries until it shrinks to the appropriate size.- Parameters:
capacity
- the maximum capacity of the map- Throws:
java.lang.IllegalArgumentException
- if the capacity is negative
-
isEmpty
public boolean isEmpty()
-
size
public int size()
-
clear
public void clear()
-
containsKey
public boolean containsKey(java.lang.Object key)
-
containsValue
public boolean containsValue(java.lang.Object value)
-
get
public V get(java.lang.Object key)
-
remove
public V remove(java.lang.Object key)
-
remove
public boolean remove(java.lang.Object key, java.lang.Object value)
-
keySet
public java.util.Set<K> keySet()
-
values
public java.util.Collection<V> values()
-
-