rcf.core.util.reference
Class ReferenceTypeAdapter<T,R extends Reference<T>>

java.lang.Object
  extended by rcf.core.util.adapter.AbstractTypeAdapter<T,R>
      extended by rcf.core.util.reference.ReferenceTypeAdapter<T,R>
Type Parameters:
T - The type of the objects being referenced.
All Implemented Interfaces:
rcf.core.util.adapter.TypeAdapter<T,R>, rcf.core.util.adapter.TypeAdapterA<T,R>, rcf.core.util.adapter.TypeAdapterB<T,R>

@Revision(value="$Revision: 1.7 $",
          date="$Date: 2006/11/10 00:09:47 $",
          tag="$Name:  $")
public class ReferenceTypeAdapter<T,R extends Reference<T>>
extends rcf.core.util.adapter.AbstractTypeAdapter<T,R>

TODO: Javadoc An adapter from objects to references to those objects, which can be used in conjunction with rcf.core.util.collections and rcf.core.util.adapter.AdapterHelpers#cast(Object, Class, Object, TypeAdapter[]) to create collections of weak, soft or phantom references. At it's core this adapter simply wraps and unwraps the objects with the appropriate references as determined by the _refClass parameter to ReferenceTypeAdapter(Class, Collection). In addition, this class includes the update() method which will remove all (now) garbage collection references created using this adapter from the optional collection which was specified to ReferenceTypeAdapter(Class, Collection). Note that the update method is called at every adaptation, allowing it's use to be fully automatic.

TODO: Unit tests, Code review, Javadoc review, Seal/Finalize

Version:
$Revision: 1.7 $
Author:
Greg Gibeling

Field Summary
protected  rcf.core.util.collection.Collection<R> collection
          TODO: Javadoc The collection which this adapter is managing the contents of.
protected  ReferenceQueue<T> queue
          TODO: Javadoc The reference queue which garbage collected objects are put into.
protected  Constructor<R> refConstructor
          TODO: Javadoc The constructor to use when constructing reference objects.
 
Fields inherited from class rcf.core.util.adapter.AbstractTypeAdapter
adapterInverse
 
Constructor Summary
ReferenceTypeAdapter(Class<R> _refClass, rcf.core.util.collection.Collection<R> _collection)
          TODO: Javadoc Consruct a new reference adapter, which will wrap objects in references of the given class, and which will remove garbage collection references from the given collection.
 
Method Summary
 boolean equals(Object o)
           
 int hashCode()
           
 R mapA(T a)
           
 T mapB(R b)
           
 String toString()
           
 void update()
          TODO: Javadoc Remove all of the garbage collected references which were generated by this adapter from the collection which was specified to ReferenceTypeAdapter(Class, Collection).
 
Methods inherited from class rcf.core.util.adapter.AbstractTypeAdapter
typeAdapterInverse
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

collection

protected final rcf.core.util.collection.Collection<R extends Reference<T>> collection
TODO: Javadoc The collection which this adapter is managing the contents of.


queue

protected final ReferenceQueue<T> queue
TODO: Javadoc The reference queue which garbage collected objects are put into.


refConstructor

protected final Constructor<R extends Reference<T>> refConstructor
TODO: Javadoc The constructor to use when constructing reference objects.

Constructor Detail

ReferenceTypeAdapter

public ReferenceTypeAdapter(Class<R> _refClass,
                            rcf.core.util.collection.Collection<R> _collection)
TODO: Javadoc Consruct a new reference adapter, which will wrap objects in references of the given class, and which will remove garbage collection references from the given collection. Note that the choice of reference class will affect when and how the wrapped objects are garbage collected.

Parameters:
_refClass - The reference class to wrap objects in.
_collection - The collection which calls to update() (and the adapter methods) will remove garbage collected references from.
Method Detail

mapA

public R mapA(T a)

mapB

public T mapB(R b)

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

update

public void update()
TODO: Javadoc Remove all of the garbage collected references which were generated by this adapter from the collection which was specified to ReferenceTypeAdapter(Class, Collection). If no collection was specified, this method will do nothing. Furthermore, this method will only remove references created by this reference type adapter!