clauchiorean / google-collections

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

TreeMultimap.create() requires key and value comparators. #200

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The TreeMultimap Javadocs indicate that you can provide just one of the 
key / value comparators (implying that the other will default to the 
natural ordering):

"When constructing a TreeMultimap, you may provide a Comparator for the 
keys, a Comparator for the values, both, or neither."

However, the TreeMultimap.create(..) methods don't seem to support this. 
The create(Comparator kc, Comparator vc) method checks for nulls, so it 
doesn't appear to be possible to only specify one comparator.

I think either the documentation should be updated (either explaining how 
to create a TreeMultimap with one comparator, or to remove the statement 
about using one or the other) and/or create() should allow null, and when 
given a null Comparator, default to the natural ordering.

One motivating use-case for single-comparator TreeMultimaps is to store 
sorted sets of entries that are associated with strings.  For example, I 
am storing wikipedia revisions: Each wikipedia page has a sorted set of 
revisions, sorted by date. Each of these sorted sets is keyed by the 
wikipedia page title (a String).  The natural ordering for strings is 
fine, but I can't specify a natural ordering for the revisions.

Original issue reported on code.google.com by cresw...@gmail.com on 24 Jun 2009 at 6:39

GoogleCodeExporter commented 9 years ago
The doc should be fixed -- you have to supply a comparator. You can supply 
Ordering.natural() to get natural order, and your code will be more readable 
besides.

Original comment by kevin...@gmail.com on 24 Jun 2009 at 6:44

GoogleCodeExporter commented 9 years ago
Fixed for rc3.

Original comment by kevin...@gmail.com on 12 Aug 2009 at 6:12