TimurMahammadov / google-collections

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

Comparators.reverse(Comparator) #39

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be useful to have a method in Comparators for creating a
"reversed" comparator, i.e. a comparator that produces order that is
reverse of the comparator given as an argument.

Original issue reported on code.google.com by stac...@gmail.com on 25 Nov 2007 at 3:11

GoogleCodeExporter commented 9 years ago
We're trying not to duplicate what's already in Java's Collections class:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collections.html#reverse(java.
util.List)

In the next snapshot, there will be a class called Ordering, which adds 
additional features to any Comparator 
that extends it. One such feature is reverse(), so you can do this, for example:
   new TreeSet<String>(Comparators.naturalOrder().reverse())

Original comment by limpbizkit on 25 Nov 2007 at 4:02

GoogleCodeExporter commented 9 years ago
Thanks for the info, looking forward to the next snapshot then! 

When it comes to duplication, one scenario (and this was actually my case) where
reversing collections is not equivalent to reversing comparators is when you 
need to
"reverse" one or more comparators you use to build a compound comparator.

Original comment by stac...@gmail.com on 25 Nov 2007 at 4:21

GoogleCodeExporter commented 9 years ago
I think Jesse gave the wrong reference by mistake; the method he means is
Collections.reverseOrder().

Original comment by kevin...@gmail.com on 25 Nov 2007 at 6:03

GoogleCodeExporter commented 9 years ago
Oh, good point, thanks!

Original comment by stac...@gmail.com on 25 Nov 2007 at 6:06