DODS 5.1 API

org.enhydra.dods.cache
Class LRUCache

java.lang.Object
  |
  +--java.util.AbstractMap
        |
        +--java.util.HashMap
              |
              +--java.util.LinkedHashMap
                    |
                    +--org.enhydra.dods.cache.LRUCache
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class LRUCache
extends java.util.LinkedHashMap

LRUCache class implements LRU cache for storing DO objects.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
protected  int maxEntries
          Maximal number of entries in LRUCache.
 
Constructor Summary
LRUCache()
          Constructs an empty access-ordered LRUCache instance with a default capacity (16) and load factor (0.75).
LRUCache(int maxEnt)
          Constructs an empty access-ordered LRUCache instance with a default capacity (16) and load factor (0.75) and with maximal number of entries.
LRUCache(int initialCapacity, float loadFactor)
          Constructs an empty access-ordered LRUCache instance with the specified initial capacity and load factor.
LRUCache(int initialCapacity, float loadFactor, int maxEnt)
          Constructs an empty access-ordered LRUCache instance with the specified initial capacity, load factor and maximal number of entries.
LRUCache(java.util.Map m)
          Constructs an access-ordered LRUCache instance with the same mappings as the specified map.
LRUCache(java.util.Map m, int maxEnt)
          Constructs an access-ordered LRUCache instance with the same mappings as the specified map.
 
Method Summary
 java.lang.Object add(java.lang.Object key, java.lang.Object value)
          Adds a pair (key, value) to the cache.
 int getMaxEntries()
          Returns maximal number of entries in LRUCache.
 void setMaxEntries(int max)
          Sets maximal number of entries in LRUCache.
 java.lang.String toString()
          For debug reason.
 
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, get, removeEldestEntry
 
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
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

maxEntries

protected int maxEntries
Maximal number of entries in LRUCache. 1024 is default value of this variable.

Constructor Detail

LRUCache

public LRUCache(int initialCapacity,
                float loadFactor,
                int maxEnt)
Constructs an empty access-ordered LRUCache instance with the specified initial capacity, load factor and maximal number of entries.

Parameters:
initialCapacity - the initial capacity.
loadFactor - the load factor.
maxEnt - maximal number of entries in LRUCache.

LRUCache

public LRUCache(int initialCapacity,
                float loadFactor)
Constructs an empty access-ordered LRUCache instance with the specified initial capacity and load factor.

Parameters:
initialCapacity - the initial capacity.
loadFactor - the load factor.

LRUCache

public LRUCache(int maxEnt)
Constructs an empty access-ordered LRUCache instance with a default capacity (16) and load factor (0.75) and with maximal number of entries.

Parameters:
maxEnt - maximal number of entries in LRUCache.

LRUCache

public LRUCache()
Constructs an empty access-ordered LRUCache instance with a default capacity (16) and load factor (0.75).


LRUCache

public LRUCache(java.util.Map m,
                int maxEnt)
Constructs an access-ordered LRUCache instance with the same mappings as the specified map. The LRUCache instance is created with maximal number of entries, default load factor (0.75) and an initial capacity sufficient to hold the mappings in the specified map.

Parameters:
m - the map whose mappings are to be placed in this map.
maxEnt - maximal number of entries in LRUCache.

LRUCache

public LRUCache(java.util.Map m)
Constructs an access-ordered LRUCache instance with the same mappings as the specified map. The LRUCache instance is created with default load factor (0.75) and an initial capacity sufficient to hold the mappings in the specified map.

Parameters:
m - the map whose mappings are to be placed in this map.
Method Detail

add

public java.lang.Object add(java.lang.Object key,
                            java.lang.Object value)
Adds a pair (key, value) to the cache. If key already exists, the method returns previous value asociated with this key. If maximum number of entries is achieved, the eldest entry will be removed and returned.

Parameters:
key - key asociated with the value.
value - value that will be added to the cache.
Returns:
previous value asociated with this key, if the key already exists, or the eldest entry which is removed, if maximum number of entries is achieved, otherwise null.

getMaxEntries

public int getMaxEntries()
Returns maximal number of entries in LRUCache.

Returns:
maximal number of entries in LRUCache.

setMaxEntries

public void setMaxEntries(int max)
Sets maximal number of entries in LRUCache.

Parameters:
max - new value of maximal number of entries in LRU Cache.

toString

public java.lang.String toString()
For debug reason.

Overrides:
toString in class java.util.AbstractMap

DODS 5.1 API