You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Bastian Helfert <ba...@web.de> on 2004/12/20 00:38:59 UTC

[collections] Classes that decorate collections with References?

If wished and/or needed, I would like to contribute by writing some 
classes that decorate Collections, Lists, Maps and/or Sets with 
Soft-/WeakReferences. These Decorators shall make the Reference handling 
transparent to the user. Besides having  
org.apache.commons.collections.map.AbstractReferenceMap and 
java.util.WeakHashMap, I could imagine that having i.e. Lists that 
contain WeakReferences to listener objects would be useful. What do you 
think?

Bastian

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [collections] Classes that decorate collections with References?

Posted by Chris Lambrou <ma...@chrislambrou.com>.
Stephen Colebourne wrote:

> I am unsure as to the use case for a ReferenceList/ReferenceSet. We 
> already have ReferenceMap, which is very useful for building caches, 
> but why would you need a List/Set? How would they operate?

Well, here's an example, off the top of my head. A weakly referencing 
list could be useful for implementing the observer pattern in a 
situation where you don't want the listeners to be strongly referenced 
by the event source. If the event source uses such a list to hold its 
listeners, then as long as the listeners remain strongly referenced, 
they will continue to receive events from the source. There will be no 
need to explicitly unregister the listeners, as once they become weakly 
referenced, then they will effectively be removed from the event 
listener list automatically.

Chris

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [collections] Classes that decorate collections with References?

Posted by Chris Lambrou <ma...@chrislambrou.com>.
Stephen Colebourne wrote:

> I am unsure as to the use case for a ReferenceList/ReferenceSet. We 
> already have ReferenceMap, which is very useful for building caches, 
> but why would you need a List/Set? How would they operate?

Well, here's an example, of the top of my head. A weakly referencing 
list could be useful for implementing the observer pattern in a 
situation where you don't want the listeners to be strongly referenced 
by the event source. If the event source uses such a list to hold its 
listeners, then as long as the listeners remain strongly referenced, 
they will continue to receive events from the source. There will be no 
need to explicitly unregister the listeners, as once they become weakly 
referenced, then they will effectively be removed from the event 
listener list automatically.

Chris

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [collections] Classes that decorate collections with References?

Posted by Stephen Colebourne <sc...@btopenworld.com>.
I am unsure as to the use case for a ReferenceList/ReferenceSet. We already 
have ReferenceMap, which is very useful for building caches, but why would 
you need a List/Set? How would they operate?

Stephen


----- Original Message ----- 
From: "Bastian Helfert" <ba...@web.de>
> If wished and/or needed, I would like to contribute by writing some 
> classes that decorate Collections, Lists, Maps and/or Sets with 
> Soft-/WeakReferences. These Decorators shall make the Reference handling 
> transparent to the user. Besides having 
> org.apache.commons.collections.map.AbstractReferenceMap and 
> java.util.WeakHashMap, I could imagine that having i.e. Lists that contain 
> WeakReferences to listener objects would be useful. What do you think?
>
> Bastian
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org