org.deduced
Class ReferenceMap

java.lang.Object
  extended by org.deduced.ReferenceMap

public class ReferenceMap
extends java.lang.Object

ReferenceMap is used to hold a map of all the references between property collections

Author:
Steve McDuff

Field Summary
private static java.util.Map<PropertyCollection<?,?>,java.util.List<Reference>> REFERENCE_MAP
          This map holds a weak reference to its keys and keys are compared by identity.
 
Constructor Summary
ReferenceMap()
           
 
Method Summary
private static void cleanReferenceList(java.util.List<Reference> refList)
          clean a list of reference to remove those that have been emptied because of the garbage collector
private static java.util.List<Reference> cloneReferenceList(java.util.List<Reference> existingRefList)
          clone a reference list
static void deleteObject(PropertyCollection<?,?> objectToDelete)
          function called when an object was deleted.
protected static void deleteReference(Reference currentReference)
          delete a Reference between two collection by either removing the property or by setting it to null.
static java.util.List<Reference> getAllReferences(PropertyCollection<?,?> referencedCollection)
          Fetch all the references to a referenced collection.
private static java.util.List<Reference> getReferencedList(PropertyCollection<?,?> referencedCollection)
          get the list of all the reference that point to the referenced collection in the reference map.
static boolean isCollectionReferenced(PropertyCollection<?,?> referencedCollection)
          check if a collection is referenced or not.
static void registerReference(PropertyCollection<?,?> referencedCollection, PropertyCollection<?,?> referencer, java.lang.Object key)
          register a Reference
static void removeReferenceRegistration(PropertyCollection<?,?> referencedCollection, PropertyCollection<?,?> referencer, java.lang.Object key)
          remove a Reference registration
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REFERENCE_MAP

private static java.util.Map<PropertyCollection<?,?>,java.util.List<Reference>> REFERENCE_MAP
This map holds a weak reference to its keys and keys are compared by identity. The resulting map is fully synchronized.

Constructor Detail

ReferenceMap

public ReferenceMap()
Method Detail

registerReference

public static void registerReference(PropertyCollection<?,?> referencedCollection,
                                     PropertyCollection<?,?> referencer,
                                     java.lang.Object key)
register a Reference

Parameters:
referencedCollection - the referenced collection
referencer - the referencer
key - the key under which the reference is stored

getReferencedList

private static java.util.List<Reference> getReferencedList(PropertyCollection<?,?> referencedCollection)
get the list of all the reference that point to the referenced collection in the reference map.

Parameters:
referencedCollection - the referenced collection
Returns:
the list of all the reference that point to the referenced collection

removeReferenceRegistration

public static void removeReferenceRegistration(PropertyCollection<?,?> referencedCollection,
                                               PropertyCollection<?,?> referencer,
                                               java.lang.Object key)
remove a Reference registration

Parameters:
referencedCollection - the referenced collection
referencer - the previous referencer
key - the key under which the reference is stored

cleanReferenceList

private static void cleanReferenceList(java.util.List<Reference> refList)
clean a list of reference to remove those that have been emptied because of the garbage collector

Parameters:
refList - the reference list to clean.

isCollectionReferenced

public static boolean isCollectionReferenced(PropertyCollection<?,?> referencedCollection)
check if a collection is referenced or not.

Parameters:
referencedCollection - the possibly referenced collection
Returns:
true if the collection is referenced. False otherwise.

getAllReferences

public static java.util.List<Reference> getAllReferences(PropertyCollection<?,?> referencedCollection)
Fetch all the references to a referenced collection.

Parameters:
referencedCollection - the referenced collection
Returns:
the list of all the references pointing to this collection. Note that references use weak pointers and might point to null objects.

cloneReferenceList

private static java.util.List<Reference> cloneReferenceList(java.util.List<Reference> existingRefList)
clone a reference list

Parameters:
existingRefList - the list of reference to clone
Returns:
the cloned list

deleteObject

public static void deleteObject(PropertyCollection<?,?> objectToDelete)
function called when an object was deleted. Removes all the references to the specified collection.

Parameters:
objectToDelete - the deleted object

deleteReference

protected static void deleteReference(Reference currentReference)
delete a Reference between two collection by either removing the property or by setting it to null.

Parameters:
currentReference - the reference that currently points to the object to delete