org.apache.commons.collections

Class SoftRefHashMap

Implemented Interfaces:
Map

public class SoftRefHashMap
extends java.lang.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.

Authors:
James.Dodd
James Strachan
Since:
1.0
See Also:
Bug#9571

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(java.util.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

Constructor Details

SoftRefHashMap

public SoftRefHashMap()

Method Details

clear

public void clear()
Clears all mappings

containsKey

public boolean containsKey(Object key)
Answers whether the argument is in the domain of the mappings

containsValue

public boolean containsValue(Object value)
Answers whether the argument is a Referenced value

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

equals

public boolean equals(Object object)
Answers whether this map and the argument are 'the same'

get

public Object get(Object key)
Retrieves the referent of the Referenced value
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

isEmpty

public boolean isEmpty()
Answers whether there are any mappings

keySet

public Set keySet()
Returns the domain of the mappings

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

putAll

public void putAll(java.util.Map map)
Put all of the mappings in the argument into this wrapped map

remove

public Object remove(Object key)
Removes a mapping from this map

size

public int size()
Returns the number of mappings in this map

values

public Collection values()
Returns a collection of the Referenced values

Copyright © 2001-2004 Apache Software Foundation. Documenation generated ${TODAY}.