com.miginfocom.util
Class MRUSoftCacheMap

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by java.util.LinkedHashMap
              extended by com.miginfocom.util.MRUSoftCacheMap
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map

public class MRUSoftCacheMap
extends java.util.LinkedHashMap

Generic implementation of an access-order MRU-map that holds all values in SoftReferences.
Some methods, mostly those which returns a collection that this class can't filter, throws an UnsupportedOperationException.
Having the refenence in a SoftReference means it will go away of memory gets low in the virtual machine. It is therefore used as a cache for objects that is good to have around but should be garbage collected to avoid out-of-memory problems.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
MRUSoftCacheMap(int maxCount, boolean accessOrder)
           
 
Method Summary
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
          Not supported! Throws UnsupportedOperationException
 java.util.Set entrySet()
          Not supported! Throws UnsupportedOperationException
protected  void flushEmptyRefs()
          Checks all references and deletes those entries which has no referring object.
 java.lang.Object get(java.lang.Object key)
           
 boolean isEmpty()
          Not supported! Throws UnsupportedOperationException
 java.util.Set keySet()
          Not supported! Throws UnsupportedOperationException
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 boolean removeEldestEntry(java.util.Map.Entry entry)
           
 int size()
           
 java.lang.String toString()
           
 java.util.Collection values()
          Not supported! Throws UnsupportedOperationException
 
Methods inherited from class java.util.LinkedHashMap
clear
 
Methods inherited from class java.util.HashMap
clone, putAll, remove
 
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, putAll, remove
 

Constructor Detail

MRUSoftCacheMap

public MRUSoftCacheMap(int maxCount,
                       boolean accessOrder)
Method Detail

removeEldestEntry

public boolean removeEldestEntry(java.util.Map.Entry entry)
Overrides:
removeEldestEntry in class java.util.LinkedHashMap

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map
Overrides:
put in class java.util.HashMap

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map
Overrides:
containsKey in class java.util.HashMap

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map
Overrides:
get in class java.util.LinkedHashMap

flushEmptyRefs

protected void flushEmptyRefs()
Checks all references and deletes those entries which has no referring object.


containsValue

public boolean containsValue(java.lang.Object value)
Not supported! Throws UnsupportedOperationException

Specified by:
containsValue in interface java.util.Map
Overrides:
containsValue in class java.util.LinkedHashMap

entrySet

public java.util.Set entrySet()
Not supported! Throws UnsupportedOperationException

Specified by:
entrySet in interface java.util.Map
Overrides:
entrySet in class java.util.HashMap

keySet

public java.util.Set keySet()
Not supported! Throws UnsupportedOperationException

Specified by:
keySet in interface java.util.Map
Overrides:
keySet in class java.util.HashMap

values

public java.util.Collection values()
Not supported! Throws UnsupportedOperationException

Specified by:
values in interface java.util.Map
Overrides:
values in class java.util.HashMap

isEmpty

public boolean isEmpty()
Not supported! Throws UnsupportedOperationException

Specified by:
isEmpty in interface java.util.Map
Overrides:
isEmpty in class java.util.HashMap

size

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

toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractMap


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.