Henry Wong wrote:
A comparator is supposed to return a negative number, a zero, or a positive number, depending on whether the first argument is less than, equal to, or greater than the second argument. I do not think that is what your comparator is doing.
Henry
Paul Clapham wrote:"Not working"? Would you care to provide some more information about that?
Stephan van Hulst wrote:
Stephan van Hulst wrote:
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Stephan van Hulst wrote:Here's an example:
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Stephan van Hulst wrote:Winston, too bad your Reversed doesn't extend Reversable, in case you want to reverse your reverse ordering
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:Isn't it funny how we end up with different solutions to the same problem? A couple of years back I wrote an Index class which was basically a compound Comparator based on "extractors" - except I called them 'Field's and made them enums (which actually works really nicely).
I also wrote a NaturalOrder class and an Order class that included a "policy" for nulls.
All Kleenex now of course...bloody version 8...
I'm still not quite sure why Comparator doesn't have a reverse() method
Stephan van Hulst wrote:Eh? Comparator has a static method reverseOrder(), and a non-static method reversed(). Do you mean something else?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
salvin francis wrote:
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:...You mean this...
Campbell Ritchie wrote:Shows how much nice the new Java8 code is Please Stephan, show what the requisite import are for those not familiar with those classes.
salvin francis wrote:
Rob Spoor wrote:...You mean this...
Learned something Here's a Cow
No autoboxing involved in your solution. My curiosity took me to Java source for the Integer.compare static method, here is what I found :
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Winston Gutkowski wrote:
Stephan van Hulst wrote:Eh? Comparator has a static method reverseOrder(), and a non-static method reversed(). Do you mean something else?
Yes, I mean a method that returns −compare(o1, o2) (or indeed compare(o2, o1)).
And I realise that reversed().compare() is functionally equivalent, but it's both potentially time and space consuming, and adds complexity. Why not just say that any order is implicitly reversable? Especially in these days of default implementations...
Winston
Java Blogger @ http://www.programtak.com
T Tak wrote:I have written a post to explain how sorting can be done in java. May be you will find it useful.
sort lists in java
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
min = 0x80000000, max = 0x7fffffff, max - min = 0xffffffff, min - max = 0x1
Rob Spoor wrote:
T Tak wrote:I have written a post to explain how sorting can be done in java. May be you will find it useful.
sort lists in java
You're reverseSortList method doesn't sort, it only reverses. It appears to work because you let it reverse the already sorted array.
Java Blogger @ http://www.programtak.com
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
machines help you to do more, but experience less. Experience this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|