Closed GoogleCodeExporter closed 9 years ago
Thanks for your submission. Have you looked at Multisets.frequencyOrder()? It
is
close to what you've implemented except that (a) it doesn't break ties between
elements with equal frequency and (b) it's intended for use with elements of a
Multiset, rather than Multiset.Entry instances.
With it, your max() example can be implemented as follows:
Multisets.frequencyOrder(multiset).max(multiset.elementSet())
If you do need to break ties, you could use Comparators.compound():
Comparators.compound(Multisets.frequencyOrder(multiset), Ordering.natural())
FYI, I believe the most recent snapshot has Constraints.notNull() implemented
as an
enum singleton, despite generics. You can look at the details there, but the
main
point is that we perform an "unsafe" cast that turns out to be safe. It
requires a
warning suppression, but it lets you create a real singleton.
Original comment by cpov...@google.com
on 24 Sep 2008 at 3:18
No, I somehow missed that. It's practically identical.
Thanks for the enum tips!
Original comment by dereklee...@gmail.com
on 25 Sep 2008 at 2:36
Closing, since the functionality is the same as Multisets.frequencyOrder().
Original comment by jared.l....@gmail.com
on 25 Sep 2008 at 8:19
Original issue reported on code.google.com by
dereklee...@gmail.com
on 24 Sep 2008 at 5:52Attachments: