DODS 7.1 API

org.enhydra.dods.cache.hash
Class LinkedHashCache

java.lang.Object
  extended by org.enhydra.dods.cache.hash.LinkedHashCache
All Implemented Interfaces:
java.util.Map
Direct Known Subclasses:
DODSLinkedHashCache

public class LinkedHashCache
extends java.lang.Object
implements java.util.Map

Version:
2.0 07.01.2003.
Author:
Tanja Jovanovic LinkedHashCache class implements LRU cache for storing objects.

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
protected  int maxEntries
          Maximal number of objects in LinkedHashCache - 1024 is default value of this variable.
 
Constructor Summary
LinkedHashCache()
          Constructor ().
LinkedHashCache(int maxEnt)
          Constructor (int).
LinkedHashCache(int initialCapacity, float loadFactor)
          Constructor (int, float).
LinkedHashCache(int initialCapacity, float loadFactor, int maxEnt)
          Constructor (int, float, int).
LinkedHashCache(java.util.Map m)
          Constructor (Map).
LinkedHashCache(java.util.Map m, int maxEnt)
          Constructor (Map, int).
 
Method Summary
 java.lang.Object add(java.lang.Object key, java.lang.Object value)
          Adds a pair (key, value) to the cache.
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set entrySet()
           
 boolean equals(java.lang.Object o)
           
 java.lang.Object get(java.lang.Object key)
           
 int getMaxEntries()
          Returns maximal number of objects in LinkedHashCache.
 int hashCode()
           
 boolean isEmpty()
           
 java.util.Set keySet()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 void putAll(java.util.Map t)
           
 java.lang.Object remove(java.lang.Object key)
           
 void setMaxEntries(int max)
          Sets maximal number of objects in LinkedHashCache.
 int size()
           
 java.lang.String toString()
          For debug reason.
 java.util.Collection values()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

maxEntries

protected int maxEntries
Maximal number of objects in LinkedHashCache - 1024 is default value of this variable.

Constructor Detail

LinkedHashCache

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

Parameters:
initialCapacity - The initial capacity.
loadFactor - The load factor.
maxEnt - Maximal number of objects in LinkedHashCache.

LinkedHashCache

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

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

LinkedHashCache

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

Parameters:
maxEnt - Maximal number of objects in LinkedHashCache.

LinkedHashCache

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


LinkedHashCache

public LinkedHashCache(java.util.Map m,
                       int maxEnt)
Constructor (Map, int). Constructs an access-ordered LinkedHashCache instance with the same mappings as the specified map. The LinkedHashCache instance is created with maximal number of objects, 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 objects in LinkedHashCache.

LinkedHashCache

public LinkedHashCache(java.util.Map m)
Constructor (Map). Constructs an access-ordered LinkedHashCache instance with the same mappings as the specified map. The LinkedHashCache 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 objects 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 objects is achieved, otherwise null.

getMaxEntries

public int getMaxEntries()
Returns maximal number of objects in LinkedHashCache.

Returns:
Maximal number of objects in LinkedHashCache.

setMaxEntries

public void setMaxEntries(int max)
Sets maximal number of objects in LinkedHashCache.

Parameters:
max - New value of maximal number of objects in LinkedHashCache.

toString

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

Overrides:
toString in class java.lang.Object

size

public int size()
Specified by:
size in interface java.util.Map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object key)
                    throws java.lang.ClassCastException,
                           java.lang.NullPointerException
Specified by:
containsKey in interface java.util.Map
Throws:
java.lang.ClassCastException
java.lang.NullPointerException

containsValue

public boolean containsValue(java.lang.Object value)
                      throws java.lang.ClassCastException,
                             java.lang.NullPointerException
Specified by:
containsValue in interface java.util.Map
Throws:
java.lang.ClassCastException
java.lang.NullPointerException

get

public java.lang.Object get(java.lang.Object key)
                     throws java.lang.ClassCastException,
                            java.lang.NullPointerException
Specified by:
get in interface java.util.Map
Throws:
java.lang.ClassCastException
java.lang.NullPointerException

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
                     throws java.lang.ClassCastException,
                            java.lang.NullPointerException,
                            java.lang.UnsupportedOperationException,
                            java.lang.IllegalArgumentException
Specified by:
put in interface java.util.Map
Throws:
java.lang.ClassCastException
java.lang.NullPointerException
java.lang.UnsupportedOperationException
java.lang.IllegalArgumentException

remove

public java.lang.Object remove(java.lang.Object key)
                        throws java.lang.ClassCastException,
                               java.lang.NullPointerException,
                               java.lang.UnsupportedOperationException
Specified by:
remove in interface java.util.Map
Throws:
java.lang.ClassCastException
java.lang.NullPointerException
java.lang.UnsupportedOperationException

putAll

public void putAll(java.util.Map t)
            throws java.lang.ClassCastException,
                   java.lang.NullPointerException,
                   java.lang.UnsupportedOperationException,
                   java.lang.IllegalArgumentException
Specified by:
putAll in interface java.util.Map
Throws:
java.lang.ClassCastException
java.lang.NullPointerException
java.lang.UnsupportedOperationException
java.lang.IllegalArgumentException

clear

public void clear()
           throws java.lang.UnsupportedOperationException
Specified by:
clear in interface java.util.Map
Throws:
java.lang.UnsupportedOperationException

keySet

public java.util.Set keySet()
Specified by:
keySet in interface java.util.Map

values

public java.util.Collection values()
Specified by:
values in interface java.util.Map

entrySet

public java.util.Set entrySet()
Specified by:
entrySet in interface java.util.Map

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Map
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Map
Overrides:
hashCode in class java.lang.Object

DODS 7.1 API