org.apache.commons.collections
Class SoftRefHashMap

java.lang.Object
  |
  +--org.apache.commons.collections.SoftRefHashMap
All Implemented Interfaces:
Map

public class SoftRefHashMap
extends Object
implements Map

HashMap with SoftReference links to values which allows the values of the Map to be garbage collected by the JVM if it becomes low on memory. Derive from this class and override the factory method createReference() method to make a Map wrapped in other types of Reference.

A synchronized version can be obtained with: Collections.synchronizedMap( theMapToSynchronize )

WARNING the values() and entrySet() methods require optimisation like the standard HashMap implementations so that iteration over this Map is efficient.

Author:
James.Dodd, James Strachan

Inner classes inherited from class java.util.Map
Map.Entry
 
Constructor Summary
SoftRefHashMap()
           
 
Method Summary
 void clear()
          Clears all mappings
 boolean containsKey(Object key)
          Answers whether the argument is in the domain of the mappings
 boolean containsValue(Object value)
          Answers whether the argument is a Referenced value
protected  Reference createReference(Object referent)
          Returns a reference to the argument.
 Set entrySet()
          Returns a set view of the mappings in the wrapped map
 boolean equals(Object object)
          Answers whether this map and the argument are 'the same'
 Object get(Object key)
          Retrieves the referent of the Referenced value
protected  Map getMap()
          Retrieves the wrapped HashMap
 int hashCode()
          Calculates the hash code for this map
 boolean isEmpty()
          Answers whether there are any mappings
 Set keySet()
          Returns the domain of the mappings
 void purge()
          Removes References that have had their referents garbage collected
 Object put(Object key, Object value)
          Adds a key-value mapping, wrapping the value in a Reference
 void putAll(Map map)
          Put all of the mappings in the argument into this wrapped map
 Object remove(Object key)
          Removes a mapping from this map
 int size()
          Returns the number of mappings in this map
 Collection values()
          Returns a collection of the Referenced values
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SoftRefHashMap

public SoftRefHashMap()
Method Detail

clear

public void clear()
Clears all mappings
Specified by:
clear in interface Map

containsKey

public boolean containsKey(Object key)
Answers whether the argument is in the domain of the mappings
Specified by:
containsKey in interface Map

containsValue

public boolean containsValue(Object value)
Answers whether the argument is a Referenced value
Specified by:
containsValue in interface Map

createReference

protected Reference createReference(Object referent)
Returns a reference to the argument. Override this method to make wrapped maps for other Reference types

entrySet

public Set entrySet()
Returns a set view of the mappings in the wrapped map
Specified by:
entrySet in interface Map

equals

public boolean equals(Object object)
Answers whether this map and the argument are 'the same'
Specified by:
equals in interface Map
Overrides:
equals in class Object

get

public Object get(Object key)
Retrieves the referent of the Referenced value
Specified by:
get in interface Map
Parameters:
key - The key with which to retrieve the value

getMap

protected Map getMap()
Retrieves the wrapped HashMap
Returns:
The wrapped HashMap

hashCode

public int hashCode()
Calculates the hash code for this map
Specified by:
hashCode in interface Map
Overrides:
hashCode in class Object

isEmpty

public boolean isEmpty()
Answers whether there are any mappings
Specified by:
isEmpty in interface Map

keySet

public Set keySet()
Returns the domain of the mappings
Specified by:
keySet in interface Map

purge

public void purge()
Removes References that have had their referents garbage collected

put

public Object put(Object key,
                  Object value)
Adds a key-value mapping, wrapping the value in a Reference
Specified by:
put in interface Map

putAll

public void putAll(Map map)
Put all of the mappings in the argument into this wrapped map
Specified by:
putAll in interface Map

remove

public Object remove(Object key)
Removes a mapping from this map
Specified by:
remove in interface Map

size

public int size()
Returns the number of mappings in this map
Specified by:
size in interface Map

values

public Collection values()
Returns a collection of the Referenced values
Specified by:
values in interface Map


Copyright © 2001 Apache Software Foundation. Documenation generated April 2 2002.