K
- The type of keys in the map.V
- The type of values in the map.public final class LRULinkedHashMap<K,V> extends LinkedHashMap<K,V>
Map
with a fixed maximum size which removes the least recently used (LRU)
entry if an entry is added when full. This class implements a simple technique for LRU pooling of
objects.
This class is not thread-safe. Synchronizations (if wanted) are user's reponsability.
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
LRULinkedHashMap()
Constructs a
LRULinkedHashMap with default initial capacity, maximum size and load
factor. |
LRULinkedHashMap(int initialCapacity)
Constructs a
LRULinkedHashMap with default maximum size and load factor. |
LRULinkedHashMap(int initialCapacity,
float loadFactor)
Constructs a
LRULinkedHashMap with default maximum size. |
LRULinkedHashMap(int initialCapacity,
float loadFactor,
boolean accessOrder)
Constructs a
LRULinkedHashMap with default maximum size. |
LRULinkedHashMap(int initialCapacity,
float loadFactor,
boolean accessOrder,
int maximumSize)
Constructs a
LRULinkedHashMap with the specified maximum size. |
LRULinkedHashMap(Map<K,V> map)
Constructs a
LRULinkedHashMap with all entries from the specified map. |
LRULinkedHashMap(Map<K,V> map,
int maximumSize)
Constructs a
LRULinkedHashMap with all entries from the specified map and maximum
number of entries. |
Modifier and Type | Method and Description |
---|---|
static <K,V> LRULinkedHashMap<K,V> |
createForRecentAccess(int maximumSize)
Creates a map for the most recently accessed entries.
|
static <K,V> LRULinkedHashMap<K,V> |
createForRecentInserts(int maximumSize)
Creates a map for the most recently inserted entries.
|
int |
getMaximumSize()
Returns the maximal size allowed for this map.
|
protected boolean |
removeEldestEntry(Map.Entry<K,V> eldest)
Returns
true if this map should remove its eldest entry. |
void |
setMaximumSize(int max)
Sets the maximal size allowed for this map.
|
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, replaceAll, values
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
equals, hashCode, toString
compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
public LRULinkedHashMap()
LRULinkedHashMap
with default initial capacity, maximum size and load
factor.public LRULinkedHashMap(int initialCapacity)
LRULinkedHashMap
with default maximum size and load factor.initialCapacity
- The initial capacity.public LRULinkedHashMap(int initialCapacity, float loadFactor)
LRULinkedHashMap
with default maximum size.initialCapacity
- The initial capacity.loadFactor
- The load factor.public LRULinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder)
LRULinkedHashMap
with default maximum size.initialCapacity
- The initial capacity.loadFactor
- The load factor.accessOrder
- The ordering mode: true
for access-order, false
for
insertion-order.public LRULinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder, int maximumSize)
LRULinkedHashMap
with the specified maximum size.initialCapacity
- The initial capacity.loadFactor
- The load factor.accessOrder
- The ordering mode: true
for access-order, false
for
insertion-order.maximumSize
- Maximum number of entries for this LRU map.public LRULinkedHashMap(Map<K,V> map)
LRULinkedHashMap
with all entries from the specified map. The
maximum size is set to the given map size.map
- The map whose mappings are to be placed in this map.public LRULinkedHashMap(Map<K,V> map, int maximumSize)
LRULinkedHashMap
with all entries from the specified map and maximum
number of entries.map
- The map whose mappings are to be placed in this map.maximumSize
- Maximum number of entries for this LRU map.public static <K,V> LRULinkedHashMap<K,V> createForRecentAccess(int maximumSize)
maximumSize
is very large.K
- The type of keys in the map.V
- The type of values in the map.maximumSize
- Maximum number of entries for this LRU map.maximumSize
most recently accessed entries.public static <K,V> LRULinkedHashMap<K,V> createForRecentInserts(int maximumSize)
maximumSize
is very large.K
- The type of keys in the map.V
- The type of values in the map.maximumSize
- Maximum number of entries for this LRU map.maximumSize
most recently inserted entries.public int getMaximumSize()
public void setMaximumSize(int max)
max
- The new maximal size.IllegalArgumentException
- if the given size is negative.protected boolean removeEldestEntry(Map.Entry<K,V> eldest)
true
if this map should remove its eldest entry. The default implementation
returns true
if the number of entries in this map has reached the
maximum number of entries specified at construction time.removeEldestEntry
in class LinkedHashMap<K,V>
eldest
- The least recently inserted entry in the map, or if this is an access-ordered
map, the least recently accessed entry. This is the entry that will be removed it this
method returns true
.true
if the eldest entry should be removed from the map; false
if it
should be retained.Copyright © 1996–2019 Geotools. All rights reserved.