DaveAKing / guava-libraries

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

Create overloaded operations for SortedMultiset #1695

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In order to do the sum/union of two SortedMultiset (or any other set operation) 
I can write:

SortedMultiset<Integer> set1 = ImmutableSortedMultiset.of(1, 2, 2, 3, 3, 3);
SortedMultiset<Integer> set2 = ImmutableSortedMultiset.of(1, 1, 2, 4);
SortedMultiset<Integer> sum = 
ImmutableSortedMultiset.copyOf(Multisets.sum(set1, set2));

And similarly for the other methods (union, intersection, difference, etc.).

It shouldn't be too difficult to add convenience methods to perform these 
operations (possibly using views instead of copying the whole collection). They 
might probably have to live in their own convenience class, say SortedMultisets.

Original issue reported on code.google.com by amojo...@gmail.com on 13 Mar 2014 at 9:09

GoogleCodeExporter commented 9 years ago
FWIW, precedent is that these overloads would not go into a separate 
SortedMultisets utility class, but would stay in Multisets.  (See e.g. Maps, 
which keeps its SortedMap and BiMap overloads in the same place.)

Original comment by lowas...@google.com on 13 Mar 2014 at 9:11

GoogleCodeExporter commented 9 years ago
That makes sense. I didn't realize that was a common paradigm in the library. I 
guess the user will have to force which overloaded version to use.

Original comment by amojo...@gmail.com on 13 Mar 2014 at 9:44

GoogleCodeExporter commented 9 years ago
The user shouldn't need to force anything. As long as the types of the two 
arguments to the method are both SortedMultiset (or a subtype of it), the 
overload that takes two SortedMultisets will be selected as the most specific 
overload by the compiler.

Original comment by cgdecker@google.com on 13 Mar 2014 at 9:53

GoogleCodeExporter commented 9 years ago
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:09

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:17

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:07