com.atlassian.jira.util.collect
Class LRUMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<K,V>
com.atlassian.jira.util.collect.LRUMap<K,V>
- Type Parameters:
K
- key typeV
- value type
- All Implemented Interfaces:
- Serializable, Cloneable, Map<K,V>
@NotThreadSafe
public class LRUMap<K,V>
- extends LinkedHashMap<K,V>
- implements Map<K,V>
A subclass of LinkedHashMap
that is access ordered AND constrained in size.
It is very important that any multi-threaded access to this class be externally synchronised
as even non mutative operations such as LinkedHashMap.get(Object)
will cause internal modifications
to the map order.
- See Also:
LinkedHashMap
,
Serialized Form
Nested classes/interfaces inherited from interface java.util.Map |
Map.Entry<K,V> |
Method Summary |
static
|
newLRUMap(int capacity)
Get a map that is access ordered and has the specified capacity. |
protected boolean |
removeEldestEntry(Map.Entry<K,V> eldest)
|
static
|
synchronizedLRUMap(int capacity)
Get a map that is access ordered and has the specified capacity that is thread-safe. |
Methods inherited from interface java.util.Map |
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values |
newLRUMap
public static <K,V> Map<K,V> newLRUMap(int capacity)
- Get a map that is access ordered and has the specified capacity.
- Type Parameters:
K
- the key typeV
- the value type- Parameters:
capacity
- the maximum capacity
- Returns:
- an instance of LRUMap
synchronizedLRUMap
public static <K,V> Map<K,V> synchronizedLRUMap(int capacity)
- Get a map that is access ordered and has the specified capacity that is thread-safe.
- Type Parameters:
K
- the key typeV
- the value type- Parameters:
capacity
- the maximum capacity
- Returns:
- an instance of LRUMap wrapped in a synchronized map.
removeEldestEntry
protected final boolean removeEldestEntry(Map.Entry<K,V> eldest)
- Overrides:
removeEldestEntry
in class LinkedHashMap<K,V>
Copyright © 2002-2013 Atlassian. All Rights Reserved.