org.tbee.cache.simple
Class LossyHashMap<K,V>

java.lang.Object
  extended by org.tbee.cache.simple.LossyHashMap<K,V>
All Implemented Interfaces:
Map<K,V>

public class LossyHashMap<K,V>
extends Object
implements Map<K,V>

This class is a HashMap (for fast access) but uses weak references for its values, so the garbage collecter may remove referenced values. The keys are strong references, so they are not cleaned. The weak references are hidden from the user, so the class behaves like a normal hashmap except for the fact that values can "dissappear". This class is useful for implementing caches of objects. If the system runs out of memory, the cache is automatically cleaned.

Version:
$Revision: 1.5 $
Author:
$Author: tom $

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
static char MODE_SOFT
           
static char MODE_STRONG
           
static char MODE_WEAK
           
static String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
 
Constructor Summary
LossyHashMap()
          extended HashMap constructor: adds the mode
LossyHashMap(char pMode)
          extended HashMap constructor: adds the mode
LossyHashMap(char pMode, int initialCapacity)
          extended HashMap constructor: adds the mode
LossyHashMap(char pMode, int initialCapacity, float loadFactor)
          extended HashMap constructor: adds the mode
LossyHashMap(char pMode, Map t)
          extended HashMap constructor: adds the mode
LossyHashMap(int initialCapacity)
          this constructor comes from the HashMap and assume STRONG mode
LossyHashMap(int initialCapacity, float loadFactor)
          this constructor comes from the HashMap and assume STRONG mode
LossyHashMap(Map t)
          this constructor comes from the HashMap and assume STRONG mode
 
Method Summary
 void addFinalizeListener(FinalizeListener pFinalizeListener)
           
 void addRemoveListener(RemoveListener pRemoveListener)
           
 void callFinalizeListener(org.tbee.cache.simple.FinalizeLogger pFinalizeLogger)
           
 void callRemoveListener(Object pKey, Object pValue)
           
 void clean()
          remove entries of which the reference was cleared (soft or weak references)
 void clear()
          removes all entries
 Object clone()
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set entrySet()
           
 V get(Object key)
           
 char getMode()
          get the active mode
 boolean isEmpty()
           
 Set<K> keySet()
           
 Object put(Object key, Object value)
           
 void putAll(Map t)
           
 V remove(Object key)
           
 void removeFinalizeListener(FinalizeListener pFinalizeListener)
           
 void removeRemoveListener(RemoveListener pRemoveListener)
           
 void removeValue(Object value)
           
 int size()
           
 String toString()
           
 Collection values()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

SOURCECODE_VERSION

public static final String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values

MODE_STRONG

public static char MODE_STRONG

MODE_SOFT

public static char MODE_SOFT

MODE_WEAK

public static char MODE_WEAK
Constructor Detail

LossyHashMap

public LossyHashMap()
extended HashMap constructor: adds the mode


LossyHashMap

public LossyHashMap(char pMode)
extended HashMap constructor: adds the mode


LossyHashMap

public LossyHashMap(char pMode,
                    int initialCapacity)
extended HashMap constructor: adds the mode


LossyHashMap

public LossyHashMap(char pMode,
                    int initialCapacity,
                    float loadFactor)
extended HashMap constructor: adds the mode


LossyHashMap

public LossyHashMap(char pMode,
                    Map t)
extended HashMap constructor: adds the mode


LossyHashMap

public LossyHashMap(int initialCapacity)
this constructor comes from the HashMap and assume STRONG mode


LossyHashMap

public LossyHashMap(int initialCapacity,
                    float loadFactor)
this constructor comes from the HashMap and assume STRONG mode


LossyHashMap

public LossyHashMap(Map t)
this constructor comes from the HashMap and assume STRONG mode

Method Detail

getMode

public char getMode()
get the active mode


addFinalizeListener

public void addFinalizeListener(FinalizeListener pFinalizeListener)

removeFinalizeListener

public void removeFinalizeListener(FinalizeListener pFinalizeListener)

callFinalizeListener

public void callFinalizeListener(org.tbee.cache.simple.FinalizeLogger pFinalizeLogger)

addRemoveListener

public void addRemoveListener(RemoveListener pRemoveListener)

callRemoveListener

public void callRemoveListener(Object pKey,
                               Object pValue)

removeRemoveListener

public void removeRemoveListener(RemoveListener pRemoveListener)

clean

public void clean()
remove entries of which the reference was cleared (soft or weak references)


clear

public void clear()
removes all entries

Specified by:
clear in interface Map<K,V>

clone

public Object clone()
Overrides:
clone in class Object

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<K,V>

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map<K,V>

entrySet

public Set entrySet()
Specified by:
entrySet in interface Map<K,V>

get

public V get(Object key)
Specified by:
get in interface Map<K,V>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<K,V>

keySet

public Set<K> keySet()
Specified by:
keySet in interface Map<K,V>

put

public Object put(Object key,
                  Object value)
Specified by:
put in interface Map<K,V>

putAll

public void putAll(Map t)
Specified by:
putAll in interface Map<K,V>

remove

public V remove(Object key)
Specified by:
remove in interface Map<K,V>

removeValue

public void removeValue(Object value)

size

public int size()
Specified by:
size in interface Map<K,V>

toString

public String toString()
Overrides:
toString in class Object

values

public Collection values()
Specified by:
values in interface Map<K,V>


Copyright © 2010 KnowledgePlaza. All Rights Reserved.