Issue 197 in google-collections: Consider creating a ImmutableCollection.Builder base class.

4 views
Skip to first unread message

codesite...@google.com

unread,
Jun 22, 2009, 9:20:39 PM6/22/09
to google-coll...@googlegroups.com
Status: New
Owner: ----

New issue 197 by lindner.profile: Consider creating a
ImmutableCollection.Builder base class.
http://code.google.com/p/google-collections/issues/detail?id=197

An abstract ImmutableCollection.Builder base class would allow creation of
common routines that could add() to all varieties of Builders, like so

private void addMe(ImmutableCollection.Builder<T> foo, T o) {
foo.add(o);
}

etc..


--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

codesite...@google.com

unread,
Jun 23, 2009, 12:58:37 PM6/23/09
to google-coll...@googlegroups.com

Comment #1 on issue 197 by jared.l.levy: Consider creating a

What's the use case for that?

codesite...@google.com

unread,
Jun 23, 2009, 1:17:04 PM6/23/09
to google-coll...@googlegroups.com

Comment #2 on issue 197 by lindner.profile: Consider creating a

I was refactoring this code to use ImmutableSet/ImmutableList, it would be
nice if I
could pass in the Builder for the appropriate immutable collection..

Is there a better way to do this?


private Collection<Object> convertToCollection(JSONArray in,
Collection<Object>
out, Type type) {
for (int i = 0, j = in.length(); i < j; ++i) {
out.add(convertToObject(in.opt(i), type));
}
return out;

codesite...@google.com

unread,
Jun 23, 2009, 2:14:46 PM6/23/09
to google-coll...@googlegroups.com

Comment #3 on issue 197 by cpov...@google.com: Consider creating a

For a case like yours, I'd recommend just creating an ArrayList in your
method,
returning it, and passing the result to
ImmutableList/ImmutableSet.copyOf(). The
builder classes are designed primarily for constants, not general use:

public static final ImmutableList<Color> GOOGLE_COLORS
= new ImmutableList.Builder<Color>()
.addAll(WEBSAFE_COLORS)
.add(new Color(0, 191, 255))
.build();

Specifically, there's no performance advantage to using builder.build() over
copyOf(): As currently implemented, ImmutableList.Builder and
ImmutableSet.Builder
use an ArrayList internally and call copyOf() on it.

codesite...@google.com

unread,
Jun 23, 2009, 4:04:13 PM6/23/09
to google-coll...@googlegroups.com

Comment #4 on issue 197 by lindner.profile: Consider creating a

point taken, I know that the Builder implementation uses an arraylist
underneath.. Just
seems like making ImmutableXXX.Builder follow the same hierarchy as
ImmutableXXX

codesite...@google.com

unread,
Aug 12, 2009, 2:12:07 PM8/12/09
to google-coll...@googlegroups.com

Comment #5 on issue 197 by kevinb9n: Consider creating a

Use cases or not, it does seem like the proper relationship, so I will try
it out, and
if it goes quietly, then, why not.

codesite...@google.com

unread,
Aug 12, 2009, 2:15:31 PM8/12/09
to google-coll...@googlegroups.com
Updates:
Status: Accepted
Labels: 1.0

Comment #6 on issue 197 by kevinb9n: Consider creating a

(No comment was entered for this change.)

codesite...@google.com

unread,
Aug 18, 2009, 9:32:01 PM8/18/09
to google-coll...@googlegroups.com
Updates:
Status: WontFix

Comment #7 on issue 197 by kevinb9n: Consider creating a

We decided we are not going to have a public ImmutableCollection.Builder
class unless
compelling use cases emerge.

codesite...@google.com

unread,
Dec 8, 2009, 12:27:24 PM12/8/09
to google-coll...@googlegroups.com

Comment #8 on issue 197 by kev...@google.com: Consider creating a
Issue 298 has been merged into this issue.

codesite...@google.com

unread,
Dec 8, 2009, 2:21:07 PM12/8/09
to google-coll...@googlegroups.com

Comment #9 on issue 197 by bl...@orcaware.com: Consider creating a
Was the use case in 298 not sufficient to make Builder public so that the
Scala
builders can extend it?
Reply all
Reply to author
Forward
0 new messages