K
- the map key typeV
- the map value typepublic abstract class CapacityLimitedHashtable<K,V> extends ConcurrentHashMap<K,V>
Map that will eject its least-recently-accessed values to remain within a specified capacity.
The type of capacity is determined by implementations of this abstract class's getObjectSize method - for example, an implementation that returns 1 would count capacity as the number of items in the map, while a different implementation might return the object's byte size and make capacity a maximum amount of memory.
Useful for caching.
ConcurrentHashMap.KeySetView<K,V>
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
CapacityLimitedHashtable(long capacity) |
Modifier and Type | Method and Description |
---|---|
int |
currentSize()
Return the current size of all of the table's values as judged by the implementation of getObjectSize.
|
V |
get(Object key)
Retrieve a value from the map.
|
abstract long |
getObjectSize(V obj)
Return the size this object will be inside of this hashtable.
|
V |
put(K key,
V value)
Maps the specified key to the specified value in this table.
|
V |
remove(Object key)
Removes the key (and its corresponding value) from this map.
|
clear, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, forEach, forEach, forEachEntry, forEachEntry, forEachKey, forEachKey, forEachValue, forEachValue, getOrDefault, hashCode, isEmpty, keys, keySet, keySet, mappingCount, merge, newKeySet, newKeySet, putAll, putIfAbsent, reduce, reduceEntries, reduceEntries, reduceEntriesToDouble, reduceEntriesToInt, reduceEntriesToLong, reduceKeys, reduceKeys, reduceKeysToDouble, reduceKeysToInt, reduceKeysToLong, reduceToDouble, reduceToInt, reduceToLong, reduceValues, reduceValues, reduceValuesToDouble, reduceValuesToInt, reduceValuesToLong, remove, replace, replace, replaceAll, search, searchEntries, searchKeys, searchValues, size, toString, values
public CapacityLimitedHashtable(long capacity)
capacity
- The maximum capacity the map will allow before ejecting values. What this value means depends on
the implementation of getObjectSize.public int currentSize()
public abstract long getObjectSize(V obj)
Return the size this object will be inside of this hashtable. The implementation of this method will determine how the hash's capacity will work; for example, returning 1 for every object will make the capacity a simple length limit, while returning the object's byte size will make capacity a memory size limitation.
obj
- An object to sizepublic V remove(Object key)
remove
in interface Map<K,V>
remove
in class ConcurrentHashMap<K,V>
key
- the key that needs to be removedkey
, or
null
if there was no mapping for key
NullPointerException
- if the specified key is nullpublic V put(K key, V value)
Maps the specified key to the specified value in this table. Neither the key nor the value can be null.
If adding this value puts the table above its maximum capacity, objects that were accessed least recently will be removed from the table until it is back at capacity.
put
in interface Map<K,V>
put
in class ConcurrentHashMap<K,V>
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keykey
, or
null
if there was no mapping for key
NullPointerException
- if the specified key or value is nullConcurrentHashMap.put(java.lang.Object, java.lang.Object)
public V get(Object key)
get
in interface Map<K,V>
get
in class ConcurrentHashMap<K,V>
key
- the key the value was stored withConcurrentHashMap.get(java.lang.Object)
Copyright © 2020 Snowbound Software Corporation. All rights reserved.