|
Rakesh API | |||||||||
| 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.rakeshv.utils.LinkedHashMap<K,V>
class LinkedHashMap<K,V>
A sub-class of java.util.LinkedHashMap used to
implement a size controlled Map. Implements the
removeEldestEntry( Map.Entry ) method to remove the
oldest entries if Map.size() > maxEntries.
Copyright 2004-2006 Rakesh Vidyadharan
| Nested Class Summary | |
|---|---|
(package private) static class |
LinkedHashMap.Statistics
An implementation of LinkedHashMap.Statistics used to
track cache performance. |
| Nested classes/interfaces inherited from interface java.util.Map |
|---|
java.util.Map.Entry<K,V> |
| Field Summary | |
|---|---|
(package private) static int |
DEFAULT_CAPACITY
The default size for the map. |
(package private) static float |
DEFAULT_LOAD_FACTOR
The default load-factor value. |
(package private) static boolean |
FIFO_CACHE
Flag to indicate insertion-order policy. |
private static java.util.logging.Logger |
logger
An instance of Logger used to log informational
messages. |
(package private) static boolean |
LRU_CACHE
Flag to indicate access-order policy. |
private int |
maxEntries
A variable used to keep track of the maximum number of entries to keep in the Map. |
private LinkedHashMap.Statistics |
statistics
An instance of LinkedHashMap.Statistics that is used to
track usage of the cache. |
| Constructor Summary | |
|---|---|
LinkedHashMap()
Default constructor. |
|
LinkedHashMap(int capacity)
Constructs a new instance with the specified initial capacity. |
|
LinkedHashMap(int capacity,
float loadFactor)
Constructs a new instance with the specified initial capacity and load factor. |
|
LinkedHashMap(int capacity,
float loadFactor,
boolean accessOrder)
Constructs an empty LinkedHashMap instance with the specified initial capacity, load factor and ordering mode. |
|
LinkedHashMap(java.util.Map<K,V> map)
Constructs an ordered LinkedHashMap instance with the same mappings as the specified map. |
|
| Method Summary | |
|---|---|
void |
clear()
Removes all mappings from this map. |
V |
get(java.lang.Object key)
Over-ridden to increment the values of LinkedHashMap.Statistics.totalRequests and if necessary, LinkedHashMap.Statistics.successfulRequests. |
int |
getMaxEntries()
Returns maxEntries. |
Map.Statistics |
getStatistics()
Returns statistics. |
private void |
init(int capacity)
Initialise the maxEntries and statistics. |
protected boolean |
removeEldestEntry(java.util.Map.Entry eldest)
Returns true if this map should remove its eldest
entry. |
void |
setMaxEntries(int maxEntries)
Set maxEntries. |
| Methods inherited from class java.util.LinkedHashMap |
|---|
containsValue |
| 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, containsValue, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, remove, size, values |
| Field Detail |
|---|
private static final java.util.logging.Logger logger
Logger used to log informational
messages. All logs are created using the Logger.info()
method.
static final int DEFAULT_CAPACITY
static final float DEFAULT_LOAD_FACTOR
static final boolean LRU_CACHE
static final boolean FIFO_CACHE
private volatile int maxEntries
private LinkedHashMap.Statistics statistics
LinkedHashMap.Statistics that is used to
track usage of the cache.
| Constructor Detail |
|---|
LinkedHashMap()
LinkedHashMap(int capacity)
capacity - The maximum size for this map.
LinkedHashMap(int capacity,
float loadFactor)
capacity - The maximum size for this map.loadFactor - The load-factor to use.
LinkedHashMap(int capacity,
float loadFactor,
boolean accessOrder)
capacity - The maximum size for this map.loadFactor - The load-factor to use.accessOrder - The ordering mode - LRU_CACHE for
access-order, FIFO_CACHE for insertion-order.LinkedHashMap(java.util.Map<K,V> map)
map - The map to use to create the new instance.
java.lang.NullPointerException - If the specified map is null.| Method Detail |
|---|
private void init(int capacity)
maxEntries and statistics.
public V get(java.lang.Object key)
LinkedHashMap.Statistics.totalRequests and if necessary, LinkedHashMap.Statistics.successfulRequests.
get in interface java.util.Map<K,V>get in class java.util.LinkedHashMap<K,V>key - key whose associated value is to be
returned.
value to which this map maps the
specified key, or null if the map
contains no mapping for this key.public void clear()
statistics.
clear in interface java.util.Map<K,V>clear in class java.util.LinkedHashMap<K,V>protected boolean removeEldestEntry(java.util.Map.Entry eldest)
true if this map should remove its eldest
entry. This method is invoked by put and putAll after inserting a
new entry into the map. Checks the HashMap.size() of the map
against maxEntries to determine the return value.
removeEldestEntry in class java.util.LinkedHashMap<K,V>eldest - The least recently accessed entry. This is the
entry that will be removed it this method returns
true. If the map was empty prior to the put
or putAll invocation resulting in this
invocation, this will be the entry that was just inserted; in
other words, if the map contains a single entry, the eldest
entry is also the newest.public final int getMaxEntries()
maxEntries.
public final void setMaxEntries(int maxEntries)
maxEntries. This can be used to dynamically change
the size of the cache.
maxEntries - The value to set.public final Map.Statistics getStatistics()
statistics. This may be used by client
applications to monitor cache usage.
|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||