You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Stephen Colebourne <sc...@btopenworld.com> on 2006/06/16 01:13:19 UTC

Re: [collections] Decorator suggestion

Eric Jablow wrote:
> Brian Goetz, in an article last year for IBM DeveloperWorks,
> suggested writing a set wrapper that would allow initialization
> code like:
> 
>     private final static Set COMMANDS =
>         new UnmodifiableSetBuilder(new HashSet())
>             .append("Save")
>             .append("Revert")
>             .append("Close")
>             .unmodifiableSet();
> 
> instead of the wordier but normal
> 
>     private final static Set COMMANDS; // Blank final
>     static {
>         Set tempCommands = new HashSet();
>         tempCommands.add("Save");
>         tempCommands.add("Revert");
>         tempCommands.add("Close");
>         COMMANDS = Collections.unmodifiableSet(tempCommands);
>     }

This is an interesting idea. I would have thought that a single 
SetBuilder that could produce a modifiable as well as an unmodifiable 
set would make more sense.

My concern is whether this is too specific for commons-collections, or 
whether it is in fact exactly the kind of feature that we should 
provide. Opinions?

Stephen

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


RE: [collections] Decorator suggestion

Posted by Eric Jablow <er...@praxiseng.com>.


Stephen Colebourne [mailto:scolebourne@btopenworld.com] wrote:
> I wrote:
>> Brian Goetz, in an article last year for IBM DeveloperWorks,
>> suggested writing a set wrapper that would allow initialization
>> code like:
>> 
>>     private final static Set COMMANDS =
>>         new UnmodifiableSetBuilder(new HashSet())
>>             .append("Save")
>>             .append("Revert")
>>             .append("Close")
>>             .unmodifiableSet();
>> ... 
> instead of the wordier but normal
>
>This is an interesting idea. I would have thought that a single 
>SetBuilder that could produce a modifiable as well as an unmodifiable 
>set would make more sense.
> ...

Perhaps the collections project could use some of
the backlogged code already contributed for it.
Fred Loney, as part of JIRA issue COLLECTIONS-183,
contributed an AppendableList class.  Copy and
paste methods to get AppendableXXX decorators,
subclass them to get builder classes like the one above,
and we'll have a good start.  As I said, I'm willing to help.

The Goetz article is available at:

http://www-128.ibm.com/developerworks/java/library/j-jtp04275.html

Respectfully,
Eric Jablow