common
Class DefaultReferenceHistogram

java.lang.Object
  extended by common.DefaultReferenceHistogram
All Implemented Interfaces:
ReferenceHistogram, java.io.Serializable

public class DefaultReferenceHistogram
extends java.lang.Object
implements ReferenceHistogram, java.io.Serializable

Default implementation of the ReferenceHistogram interface. It uses a HashMap to store the mapping from objects to numbers of references.

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface common.ReferenceHistogram
EMPTY_HISTOGRAM
 
Constructor Summary
DefaultReferenceHistogram()
          Creates a new DefaultReferenceHistogram with no references (and hence no referenced objects).
 
Method Summary
 void addReference(java.lang.Long obj)
          Adds to this histogram a reference referring to the given object.
 void changeReference(java.lang.Long oldObj, java.lang.Long newObj)
          Takes one of the references in this histogram that refers to oldObj, and makes it refer to newObj instead.
 int getNumReferences(java.lang.Long obj)
          Returns the number of references for the given object.
 java.util.Iterator iterator()
          Allows iteration over the objects that have at least one reference.
 int numReferencedObjects()
          Returns the number of objects with at least one reference.
 void removeReference(java.lang.Long obj)
          Removes from this histogram a reference referring to the given object.
 int totalReferences()
          Returns the total number of references in this histogram.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultReferenceHistogram

public DefaultReferenceHistogram()
Creates a new DefaultReferenceHistogram with no references (and hence no referenced objects).

Method Detail

addReference

public void addReference(java.lang.Long obj)
Adds to this histogram a reference referring to the given object. This adds 1 to the number of references for the given object.

Parameters:
obj - a Long value representing the ID of the object that the added reference refers to

removeReference

public void removeReference(java.lang.Long obj)
Removes from this histogram a reference referring to the given object. This subtracts 1 from the number of references for the given object. If the histogram contains no reference referring to the object, an IllegalStateException is thrown.

Parameters:
obj - a Long value representing the ID of the object that the removed citation refers to

changeReference

public void changeReference(java.lang.Long oldObj,
                            java.lang.Long newObj)
Takes one of the references in this histogram that refers to oldObj, and makes it refer to newObj instead. Throws an IllegalStateException if the histogram contains no reference that refers to oldObj.


numReferencedObjects

public int numReferencedObjects()
Description copied from interface: ReferenceHistogram
Returns the number of objects with at least one reference.

Specified by:
numReferencedObjects in interface ReferenceHistogram

totalReferences

public int totalReferences()
Description copied from interface: ReferenceHistogram
Returns the total number of references in this histogram.

Specified by:
totalReferences in interface ReferenceHistogram

getNumReferences

public int getNumReferences(java.lang.Long obj)
Description copied from interface: ReferenceHistogram
Returns the number of references for the given object. If the object has no references, the method returns zero (rather than throwing an exception or something like that).

Specified by:
getNumReferences in interface ReferenceHistogram
Parameters:
obj - a Long object representing an object ID

iterator

public java.util.Iterator iterator()
Description copied from interface: ReferenceHistogram
Allows iteration over the objects that have at least one reference.

Specified by:
iterator in interface ReferenceHistogram
Returns:
an Iterator over Long objects representing object IDs