Closed GoogleCodeExporter closed 9 years ago
Kevin's answer to this old google-collections issue is slightly related:
http://code.google.com/p/google-collections/issues/detail?id=304
"With Iterators, you have similar options. This in particular is just not a
common
enough need to warrant all these methods in our API."
As I understand it, Guava's goal is to provide static factory methods for the
most common use cases. They avoid doing it for "less useful" (= rarely used)
factories, to avoid making the API too big (which makes it harder to find the
useful stuff).
That's why you may find multiple factory methods pertaining to HashSets, such
as Sets.newHashSet(Iterator), but no equivalent factory for the more rarely
used LinkedHashSet / TreeSet.
Original comment by nev...@gmail.com
on 28 Jan 2011 at 6:53
Well, I was sure I had already asked for it; I just couldn't find my post over
here... Obviously since it was in the old google-collections bug tracking
system.
Needs to be closed, then.
Original comment by ogregoire
on 28 Jan 2011 at 8:04
Thanks both of you.
Original comment by kevin...@gmail.com
on 28 Jan 2011 at 9:11
Wow, Olivier, I hadn't realized you were the reporter for the
google-collections issue I linked to above! I simply remembered reading about
this earlier, and searched the google-collections issue tracker when I couldn't
find it here. Funny coincidence.
I think I know how you feel: I also wish some utility methods were available in
Guava, but understand the need to keep the library focused, with a high
"power-to-weight" ratio.
I formulated this better in my answer to this StackOverflow question:
http://stackoverflow.com/questions/4542550/what-are-the-big-improvements-between
-guava-and-apache-equivalent-libraries (see "Guava has a high power-to-weight
ratio").
While these factory methods are absent from Guava, the Iterators class still
helps with the workaround:
Sets.newEnumSet(Iterator<E>, Class<E>)
-->
Set<Foo> foos = new EnumSet<Foo>(Foo.class);
Iterators.addAll(foos, fooIterator);
Sets.newLinkedHashSet(Iterator<E>)
-->
Set<Foo> foos = Sets.newLinkedHashSet();
Iterators.addAll(foos, fooIterator);
Sets.newTreeSet(Iterator<E>)
-->
Set<Foo> foos = Sets.newTreeSet();
Iterators.addAll(foos, fooIterator);
It's indeed more verbose... And it could be encapsulated in a project-specific
"Sets2" utility class. There might even be an opportunity to create some kind
of "guava-extensions" project that would build on Guava and provide these
"nice-to-have" utility methods.
Original comment by nev...@gmail.com
on 28 Jan 2011 at 11:10
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:15
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:09
Original issue reported on code.google.com by
ogregoire
on 28 Jan 2011 at 4:12