org.datanucleus.util
Class ReferenceValueMap

java.lang.Object
  extended by org.datanucleus.util.ReferenceValueMap
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map
Direct Known Subclasses:
SoftValueMap, WeakValueMap

public abstract class ReferenceValueMap
extends java.lang.Object
implements java.util.Map, java.lang.Cloneable

A java.util.Map implementation using reference values.

The values are stored in the map as references. If the garbage collector clears the reference, the corresponding key is automatically removed from the map.

See Also:
Reference

Nested Class Summary
static interface ReferenceValueMap.ValueReference
          References returned by newValueReference must implement this interface to provide the corresponding map key for the value.
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
ReferenceValueMap()
          Default Constructor.
ReferenceValueMap(int initial_capacity)
          Constructor taking initial capacity.
ReferenceValueMap(int initial_capacity, float load_factor)
          Constructor taking initial capacity and load factor.
ReferenceValueMap(java.util.Map m)
          Constructor taking initial Map.
 
Method Summary
 void clear()
          Method to empty the HashMap.
 java.lang.Object clone()
          Clone method.
 boolean containsKey(java.lang.Object obj)
          Accessor for whether the Map contains the specified Key
 boolean containsValue(java.lang.Object obj)
          Accessor for whether the Map contains the specified value.
 java.util.Set entrySet()
          Accessor for the entry set.
 boolean equals(java.lang.Object o)
          Equality operator.
 java.lang.Object get(java.lang.Object key)
          Method to get a value for a key.
 int hashCode()
          Hashcode generator for this object.
 boolean isEmpty()
          Accessor for whether the Map is empty.
 java.util.Set keySet()
          Accessor for the Set of keys in the Map.
protected abstract  ReferenceValueMap.ValueReference newValueReference(java.lang.Object key, java.lang.Object value, java.lang.ref.ReferenceQueue queue)
          Returns a new Reference object to be inserted into the map.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Method to add an object to the Map.
 void putAll(java.util.Map m)
          Method to add the contents of a Map.
 void reap()
          Utility method to reap objects.
 java.lang.Object remove(java.lang.Object key)
          Method to remove an object for the specified key.
 int size()
          Accessor for the size of the HashMap.
 java.util.Collection values()
          Accessor for the values from the Map.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReferenceValueMap

public ReferenceValueMap()
Default Constructor.


ReferenceValueMap

public ReferenceValueMap(int initial_capacity)
Constructor taking initial capacity.

Parameters:
initial_capacity - Initial Capacity of HashMap

ReferenceValueMap

public ReferenceValueMap(int initial_capacity,
                         float load_factor)
Constructor taking initial capacity and load factor.

Parameters:
initial_capacity - Initial Capacity of HashMap
load_factor - Load Factor of HashMap

ReferenceValueMap

public ReferenceValueMap(java.util.Map m)
Constructor taking initial Map.

Parameters:
m - Map to initial with.
Method Detail

clone

public java.lang.Object clone()
Clone method.

Overrides:
clone in class java.lang.Object
Returns:
Clone of this object.

newValueReference

protected abstract ReferenceValueMap.ValueReference newValueReference(java.lang.Object key,
                                                                      java.lang.Object value,
                                                                      java.lang.ref.ReferenceQueue queue)
Returns a new Reference object to be inserted into the map. Subclasses must implement this method to construct Reference objects of the desired type (e.g. SoftReference, etc.).

Parameters:
key - The key that will be inserted.
value - The associated value to be referenced.
queue - The ReferenceQueue with which to register the new Reference object.
Returns:
The new ValueReference

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Method to add an object to the Map.

Specified by:
put in interface java.util.Map
Parameters:
key - Key for object
value - Value of object
Returns:
The Object.

putAll

public void putAll(java.util.Map m)
Method to add the contents of a Map.

Specified by:
putAll in interface java.util.Map
Parameters:
m - Map

get

public java.lang.Object get(java.lang.Object key)
Method to get a value for a key.

Specified by:
get in interface java.util.Map
Parameters:
key - The Key
Returns:
The Value

clear

public void clear()
Method to empty the HashMap.

Specified by:
clear in interface java.util.Map

size

public int size()
Accessor for the size of the HashMap.

Specified by:
size in interface java.util.Map
Returns:
The size

containsKey

public boolean containsKey(java.lang.Object obj)
Accessor for whether the Map contains the specified Key

Specified by:
containsKey in interface java.util.Map
Parameters:
obj - The key
Returns:
Whether the key exists

containsValue

public boolean containsValue(java.lang.Object obj)
Accessor for whether the Map contains the specified value.

Specified by:
containsValue in interface java.util.Map
Parameters:
obj - The value
Returns:
Whether the Map contains the value.

isEmpty

public boolean isEmpty()
Accessor for whether the Map is empty.

Specified by:
isEmpty in interface java.util.Map
Returns:
Whether the Map is empty.

keySet

public java.util.Set keySet()
Accessor for the Set of keys in the Map.

Specified by:
keySet in interface java.util.Map
Returns:
The Set of keys

values

public java.util.Collection values()
Accessor for the values from the Map.

Specified by:
values in interface java.util.Map
Returns:
The Values.

entrySet

public java.util.Set entrySet()
Accessor for the entry set.

Specified by:
entrySet in interface java.util.Map
Returns:
The Set.

remove

public java.lang.Object remove(java.lang.Object key)
Method to remove an object for the specified key.

Specified by:
remove in interface java.util.Map
Parameters:
key - The Key
Returns:
The Object removed

hashCode

public int hashCode()
Hashcode generator for this object.

Specified by:
hashCode in interface java.util.Map
Overrides:
hashCode in class java.lang.Object
Returns:
The Hashcode

equals

public boolean equals(java.lang.Object o)
Equality operator.

Specified by:
equals in interface java.util.Map
Overrides:
equals in class java.lang.Object
Parameters:
o - THe object to compare against.
Returns:
Whether it is equal.

reap

public void reap()
Utility method to reap objects.



Copyright © 2010. All Rights Reserved.