ACMNexus / google-collections

Automatically exported from code.google.com/p/google-collections
Apache License 2.0
0 stars 0 forks source link

Missing varargs factory methods in HashMultiset and TreeMultiset #125

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Previous releases had a factory method for HashMultisets in the Multisets
class, the method Multisets.newHashMultiset(E... elements).  In the 0.9
release, the factory methods have moved to HashMultiset (which makes
sense), but there's no overloaded create method that takes varargs.

This makes it a real pain to upgrade to the 0.9 release unfortunately.  I
hope this extra factory method could be added to HashMultiset (and
TreeMultiset) for an upcoming release.

Original issue reported on code.google.com by jan.ste...@gmail.com on 27 Feb 2009 at 5:02

GoogleCodeExporter commented 8 years ago
If your multiset doesn't change after construction, you should use an
ImmutableMultiset, which has a factory method that takes varargs.

http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/col
lect/ImmutableMultiset.html#of(E...)

In most cases when people previously called Multisets.newHashMultiset(E... 
elements),
the multiset is constant. 

Otherwise, the following workaround isn't too cumbersome.
  HashMultiset.create(Arrays.asList(elements));

With those alternatives available, we can't justify keeping
Multisets.newHashMultiset(E... elements)

Original comment by jared.l....@gmail.com on 27 Feb 2009 at 5:45

GoogleCodeExporter commented 8 years ago
Jan -- I'm sorry.  We've had so much trouble with varargs methods causing 
problems
that we're scaling back their use as much as we can.  Also, we've found that the
*vast* majority of users of these varargs collection-creation methods really 
did not
need a mutable collection.  You may be in the minority, in which case I'm sorry 
for
your trouble, but you should use the Arrays.asList() workaround.  Even better, 
if you
don't have nulls, use ImmutableList.of() because we're going to add enough
faux-varargs overloads to it that you can avoid warnings more of the time.

Original comment by kev...@google.com on 27 Feb 2009 at 6:31

GoogleCodeExporter commented 8 years ago
Thanks for your explanations.  I wasn't aware of the new of(...) methods in 
ImmutableMultiset etc., I think these 
will work fine for most of our use cases.  It's interesting that you've had 
problems with varargs methods, do you 
have a link to discussions about this?  They do seem really useful to me, we've 
ended up using these in quite a 
lot of places in our code; it is a nice workaround for the lack of a literal 
syntax for collections in Java.

Original comment by jan.ste...@gmail.com on 27 Feb 2009 at 11:16