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
What's the use case for that?
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;
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.
point taken, I know that the Builder implementation uses an arraylist
underneath.. Just
seems like making ImmutableXXX.Builder follow the same hierarchy as
ImmutableXXX
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.
Comment #6 on issue 197 by kevinb9n: Consider creating a
ImmutableCollection.Builder base class.
http://code.google.com/p/google-collections/issues/detail?id=197
(No comment was entered for this change.)
Comment #7 on issue 197 by kevinb9n: Consider creating a
ImmutableCollection.Builder base class.
http://code.google.com/p/google-collections/issues/detail?id=197
We decided we are not going to have a public ImmutableCollection.Builder
class unless
compelling use cases emerge.