|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.svrCore.MemoryTools.SimpleLRUMap<K,V>
public static final class MemoryTools.SimpleLRUMap<K,V>
Simplified thread-safe map with fixed capacity that discards excess items in LRU (Least Recently Used) order. This provides a map with a fixed upper size. Attempts to insert more items than the capacity will result in old items being removed in LRU order, thus leaving the newest items in the cache.
Each put() or get() makes its key/value pair the most-recently used and thus the last to be removed from the map of current key/value pairs when a series of put()s forces the map to overflow.
Thread-safe.
A lock can be held on instances of this object to make compound operations atomic.
Does not support the full Map interface.
| Field Summary | |
|---|---|
private static float |
defaultLoadFactor
Default load factor. |
private java.util.LinkedHashMap<K,V> |
lhm
Underlying (non-thread-safe) LinkedHashMap on which this is based; never null. |
private java.lang.String |
name
Optional name for diagnostics; can be null. |
| Constructor Summary | |
|---|---|
MemoryTools.SimpleLRUMap(int maxCapacity,
float loadFactor,
java.lang.String name)
Create an instance with given (positive) maximum size and load factor. |
|
MemoryTools.SimpleLRUMap(int maxCapacity,
java.lang.String name)
Create an instance with given (positive) maximum size and the default load factor. |
|
| Method Summary | |
|---|---|
void |
clear()
Clear the map. |
V |
get(K key)
Get an entry from the map, making it the Most Recently Used; null if no such element. |
java.util.Map<K,V> |
getCopy()
Take a copy of the map contents, which does not alter LRU; never null. |
V |
put(K key,
V value)
Put an entry in the map, making it the Most Recently Used, returning previous value if any. |
V |
remove(K key)
Remove an entry from the map and return the removed value, if any, else null. |
int |
size()
Return the number of entries in the map; non-negative. |
java.lang.String |
toString()
Provide a human-readable summary of status. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private static final float defaultLoadFactor
private final java.util.LinkedHashMap<K,V> lhm
private final java.lang.String name
| Constructor Detail |
|---|
public MemoryTools.SimpleLRUMap(int maxCapacity,
java.lang.String name)
public MemoryTools.SimpleLRUMap(int maxCapacity,
float loadFactor,
java.lang.String name)
| Method Detail |
|---|
public V get(K key)
public V put(K key,
V value)
public V remove(K key)
public void clear()
public java.util.Map<K,V> getCopy()
public int size()
public java.lang.String toString()
toString in class java.lang.Object
|
DHD Multimedia Gallery V1.53.0 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||