|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<K,V>
org.geotools.util.LRULinkedHashMap<K,V>
K
- The type of keys in the map.V
- The type of values in the map.public final class LRULinkedHashMap<K,V>
A 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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.util.AbstractMap |
---|
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V> |
Constructor Summary | |
---|---|
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(java.util.Map<K,V> map)
Constructs a LRULinkedHashMap with all entries from the specified map. |
|
LRULinkedHashMap(java.util.Map<K,V> map,
int maximumSize)
Constructs a LRULinkedHashMap with all entries from the specified map
and maximum number of entries. |
Method Summary | ||
---|---|---|
static
|
createForRecentAccess(int maximumSize)
Creates a map for the most recently accessed entries. |
|
static
|
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(java.util.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. |
Methods inherited from class java.util.LinkedHashMap |
---|
clear, containsValue, get |
Methods inherited from class java.util.HashMap |
---|
clone, containsKey, entrySet, isEmpty, keySet, put, putAll, remove, size, values |
Methods inherited from class java.util.AbstractMap |
---|
equals, hashCode, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
containsKey, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, remove, size, values |
Constructor Detail |
---|
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(java.util.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(java.util.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.Method Detail |
---|
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.
java.lang.IllegalArgumentException
- if the given size is negative.protected boolean removeEldestEntry(java.util.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 java.util.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.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |