SoftHashMap Class

com.beasys.commerce.util
SoftHashMap Class

public class SoftHashMap

    extends AbstractMap
    implements Cloneable, Map, Serializable

A map implemented using SoftReferences to store the values.

Unlike the java.util.WeakHashMap implementation, this does not utilize a ReferenceQueue, therefore, the References are cleared immediately, rather than only after a modification to the Map. Additionally, since this uses SoftReferences by default, the Map shouldn't be immediately cleared. Finally, this is also cloneable and serializable.


Hierarchy
Object
  AbstractMap
    SoftHashMap
All Implemented Interfaces

Cloneable, Map, Serializable

Constructor Summary

SoftHashMap()

Constructs a new, empty SoftHashMap with the default capacity and the default load factor, which is 0.75.
SoftHashMap(int initialCapacity, float loadFactor)

Constructs a new, empty SoftHashMap with the given initial capacity and the given load factor.
SoftHashMap(int initialCapacity)

Constructs a new, empty SoftHashMap with the given initial capacity and the default load factor, which is 0.75.
SoftHashMap(Map map)

Constructs a new SoftHashMap from the specified Map.
 

Method Summary

public void
clear()
Removes all mappings from this map.
public Object
clone()
Return a shallow clone of this map.
public boolean
containsKey(Object key)
Returns true if this map contains a mapping for the specified key.
public boolean
containsValue(Object value)
Returns true if this map contains the specified value.
protected Reference
createReference(Object data)
Create a Reference object containing the specified object.
public Set
entrySet()
Returns a Set view of the mappings in this map.
public Object
get(Object key)
Returns the value to which this map maps the specified key.
public boolean
isEmpty()
Returns true if this map contains no key-value mappings.
public Object
put(Object key, Object value)
Updates this map so that the given key maps to the given value.
public Object
remove(Object key)
Removes the mapping for the given key from this map, if present.
public int
size()
Returns the number of key-value mappings in this map.
 
Methods from  java.util.AbstractMap
equals, hashCode, keySet, putAll, toString, values
 
Methods from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
   
Methods from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Constructor Detail

SoftHashMap

public SoftHashMap()
Constructs a new, empty SoftHashMap with the default capacity and the default load factor, which is 0.75.

SoftHashMap

public SoftHashMap(int initialCapacity, 
                   float loadFactor)
Constructs a new, empty SoftHashMap with the given initial capacity and the given load factor.

SoftHashMap

public SoftHashMap(int initialCapacity)
Constructs a new, empty SoftHashMap with the given initial capacity and the default load factor, which is 0.75.

SoftHashMap

public SoftHashMap(Map map)
Constructs a new SoftHashMap from the specified Map.
 

Method Detail

clear() Method

public void clear()
Removes all mappings from this map.

Overrides
AbstractMap.clear()

clone() Method

public Object clone()
Return a shallow clone of this map.

Overrides
AbstractMap.clone()

containsKey(Object) Method

public boolean containsKey(Object key)
Returns true if this map contains a mapping for the specified key.

Overrides
AbstractMap.containsKey(Object)

Parameters

key
The key whose presence in this map is to be tested

containsValue(Object) Method

public boolean containsValue(Object value)
Returns true if this map contains the specified value.

Overrides
AbstractMap.containsValue(Object)

createReference(Object) Method

protected Reference createReference(Object data)
Create a Reference object containing the specified object.

This implementation returns SoftReferences. Subclasses can override to return other Reference types.

Parameters

data
the object (can be null).

Returns

a Reference (can be null if data is null).

entrySet() Method

public Set entrySet()
Returns a Set view of the mappings in this map.

Overrides
AbstractMap.entrySet()

get(Object) Method

public Object get(Object key)
Returns the value to which this map maps the specified key. If this map does not contain a value for this key, then return null.

Overrides
AbstractMap.get(Object)

Parameters

key
The key whose associated value, if any, is to be returned

isEmpty() Method

public boolean isEmpty()
Returns true if this map contains no key-value mappings.

Overrides
AbstractMap.isEmpty()

put(Object, Object) Method

public Object put(Object key, 
                  Object value)
Updates this map so that the given key maps to the given value. If the map previously contained a mapping for key then that mapping is replaced and the previous value is returned.

Overrides
AbstractMap.put(Object, Object)

Parameters

key
The key that is to be mapped to the given value
value
The value to which the given key is to be mapped

Returns

The previous value to which this key was mapped, or null if if there was no mapping for the key

remove(Object) Method

public Object remove(Object key)
Removes the mapping for the given key from this map, if present.

Overrides
AbstractMap.remove(Object)

Parameters

key
The key whose mapping is to be removed

Returns

The value to which this key was mapped, or null if there was no mapping for the key

size() Method

public int size()
Returns the number of key-value mappings in this map. Note: In contrast with most implementations of the Map interface, the time required by this operation is linear in the size of the map.

Overrides
AbstractMap.size()