K
- the type of keys maintained by this mapV
- the type of mapped valuespublic final class PrivateMaxEntriesMap<K,V> extends AbstractMap<K,V> implements ConcurrentMap<K,V>, Serializable
ConcurrentHashMap
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 a PrivateMaxEntriesMap.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 an
ExecutorService
.
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
and Iterator
interfaces.
Like Hashtable
but unlike HashMap
, this class
does not allow null to be used as a key or value. Unlike
LinkedHashMap
, 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.
Modifier and Type | Class and Description |
---|---|
static class |
PrivateMaxEntriesMap.Builder<K,V>
A builder that creates
PrivateMaxEntriesMap instances. |
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier and Type | Method and Description |
---|---|
Set<K> |
ascendingKeySet()
Returns a unmodifiable snapshot
Set view of the keys contained in
this map. |
Set<K> |
ascendingKeySetWithLimit(int limit)
Returns an unmodifiable snapshot
Set view of the keys contained in
this map. |
Map<K,V> |
ascendingMap()
Returns an unmodifiable snapshot
Map view of the mappings contained
in this map. |
Map<K,V> |
ascendingMapWithLimit(int limit)
Returns an unmodifiable snapshot
Map view of the mappings contained
in this map. |
long |
capacity()
Retrieves the maximum capacity of the map.
|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<K> |
descendingKeySet()
Returns an unmodifiable snapshot
Set view of the keys contained in
this map. |
Set<K> |
descendingKeySetWithLimit(int limit)
Returns an unmodifiable snapshot
Set view of the keys contained in
this map. |
Map<K,V> |
descendingMap()
Returns an unmodifiable snapshot
Map view of the mappings contained
in this map. |
Map<K,V> |
descendingMapWithLimit(int limit)
Returns an unmodifiable snapshot
Map view of the mappings contained
in this map. |
Set<Map.Entry<K,V>> |
entrySet() |
V |
get(Object key) |
V |
getQuietly(Object key)
Returns the value to which the specified key is mapped, or
null
if this map contains no mapping for the key. |
boolean |
isEmpty() |
Set<K> |
keySet() |
V |
put(K key,
V value) |
V |
putIfAbsent(K key,
V value) |
V |
remove(Object key) |
boolean |
remove(Object key,
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() |
Collection<V> |
values() |
long |
weightedSize()
Returns the weighted size of this map.
|
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, replaceAll
public long capacity()
public void setCapacity(long capacity)
capacity
- the maximum capacity of the mapIllegalArgumentException
- if the capacity is negativepublic boolean isEmpty()
public int size()
public long weightedSize()
public void clear()
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
containsKey
in class AbstractMap<K,V>
public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
containsValue
in class AbstractMap<K,V>
public V getQuietly(Object key)
null
if this map contains no mapping for the key. This method differs from
get(Object)
in that it does not record the operation with the
page replacement policy.key
- the key whose associated value is to be returnednull
if this map contains no mapping for the keyNullPointerException
- if the specified key is nullpublic V putIfAbsent(K key, V value)
putIfAbsent
in interface ConcurrentMap<K,V>
putIfAbsent
in interface Map<K,V>
public Set<K> ascendingKeySet()
Set
view of the keys contained in
this map. The set's iterator returns the keys whose order of iteration is
the ascending order in which its entries are considered eligible for
retention, from the least-likely to be retained to the most-likely.
Beware that, unlike in keySet()
, obtaining the set is NOT
a constant-time operation. Because of the asynchronous nature of the page
replacement policy, determining the retention ordering requires a traversal
of the keys.
public Set<K> ascendingKeySetWithLimit(int limit)
Set
view of the keys contained in
this map. The set's iterator returns the keys whose order of iteration is
the ascending order in which its entries are considered eligible for
retention, from the least-likely to be retained to the most-likely.
Beware that, unlike in keySet()
, obtaining the set is NOT
a constant-time operation. Because of the asynchronous nature of the page
replacement policy, determining the retention ordering requires a traversal
of the keys.
limit
- the maximum size of the returned setIllegalArgumentException
- if the limit is negativepublic Set<K> descendingKeySet()
Set
view of the keys contained in
this map. The set's iterator returns the keys whose order of iteration is
the descending order in which its entries are considered eligible for
retention, from the most-likely to be retained to the least-likely.
Beware that, unlike in keySet()
, obtaining the set is NOT
a constant-time operation. Because of the asynchronous nature of the page
replacement policy, determining the retention ordering requires a traversal
of the keys.
public Set<K> descendingKeySetWithLimit(int limit)
Set
view of the keys contained in
this map. The set's iterator returns the keys whose order of iteration is
the descending order in which its entries are considered eligible for
retention, from the most-likely to be retained to the least-likely.
Beware that, unlike in keySet()
, obtaining the set is NOT
a constant-time operation. Because of the asynchronous nature of the page
replacement policy, determining the retention ordering requires a traversal
of the keys.
limit
- the maximum size of the returned setIllegalArgumentException
- if the limit is negativepublic Collection<V> values()
public Map<K,V> ascendingMap()
Map
view of the mappings contained
in this map. The map's collections return the mappings whose order of
iteration is the ascending order in which its entries are considered
eligible for retention, from the least-likely to be retained to the
most-likely.
Beware that obtaining the mappings is NOT a constant-time operation. Because of the asynchronous nature of the page replacement policy, determining the retention ordering requires a traversal of the entries.
public Map<K,V> ascendingMapWithLimit(int limit)
Map
view of the mappings contained
in this map. The map's collections return the mappings whose order of
iteration is the ascending order in which its entries are considered
eligible for retention, from the least-likely to be retained to the
most-likely.
Beware that obtaining the mappings is NOT a constant-time operation. Because of the asynchronous nature of the page replacement policy, determining the retention ordering requires a traversal of the entries.
limit
- the maximum size of the returned mapIllegalArgumentException
- if the limit is negativepublic Map<K,V> descendingMap()
Map
view of the mappings contained
in this map. The map's collections return the mappings whose order of
iteration is the descending order in which its entries are considered
eligible for retention, from the most-likely to be retained to the
least-likely.
Beware that obtaining the mappings is NOT a constant-time operation. Because of the asynchronous nature of the page replacement policy, determining the retention ordering requires a traversal of the entries.
public Map<K,V> descendingMapWithLimit(int limit)
Map
view of the mappings contained
in this map. The map's collections return the mappings whose order of
iteration is the descending order in which its entries are considered
eligible for retention, from the most-likely to be retained to the
least-likely.
Beware that obtaining the mappings is NOT a constant-time operation. Because of the asynchronous nature of the page replacement policy, determining the retention ordering requires a traversal of the entries.
limit
- the maximum size of the returned mapIllegalArgumentException
- if the limit is negativeCopyright © 2008–2022 FasterXML. All rights reserved.