commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jack, Paul" <>
Subject RE: [Collections][SUBMIT] WeakHashSet
Date Fri, 26 Apr 2002 22:33:56 GMT

I have a few thoughts regarding your WeakHashSet...

My first thought was to somehow integrate it with the
whole Transformer/Predicate collections we've been 
discussing in another thread.  So you'd have a Transformer
that converted an object into a WeakReference before 
storing it in the set.  However, you'd need *another* 
Transformer to convert those WeakReferences back into
their referents when taking the objects out of the set.
>From what I understand, the proposed Transformer collections
only transform when objects are added.  Furthermore it's
unclear whether a two-Transformer based implementation would
work in all the algorithms for weak references (you'd still
need to empty the ReferenceQueue on a regular basis...)

My second thought is, the two Set implementations in the JDK
are backed by Map implementations.  WeakHashSet could be 
implemented as a Set that's backed by a WeakHashMap.  I'm 
thinking of having a static wrapper method in CollectionUtils
that would provide a Set backed by *any* map:

  // Creates a Set backed by the given map.  Given
  // map must be empty.
  public static Set createSet(Map map);

  public static SortedSet createSortedSet(SortedMap map);

This way, a user could get a weak hash set by calling 
CollectionUtils.createSet(new java.util.WeakHashMap()).
Or, they could use soft references instead of weak 
references in their set by calling 

This also limits the number of classes we'd have to develop
to provide the Predicate and Transformer collections...

What do you think?


-----Original Message-----
From: Jeff Keyser []
Sent: Tuesday, April 23, 2002 6:40 PM
To: 'Jakarta Commons Developers List'
Subject: [Collections][SUBMIT] WeakHashSet

Trying again...  Perhaps my wrapping the source code into a jar was
confusing.  This time I'm just attaching the source files.

> -----Original Message-----
> From: Jeff Keyser []
> Sent: Saturday, April 13, 2002 8:10 PM
> To: Jakarta Commons Developers List (E-mail)
> Subject: [SUBMIT] WeakHashSet
> Attached is a jar containing the three source code files for
> the WeakHashSet
> I mentioned I would like to contribute.  It subclasses the
> Java 1.2 HashSet
> class, and works exactly the same except that the elements
> are held in the
> set with weak references.
> Thanks!

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message