• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Coding Question in Hadoop

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have been reading a book called pro hadoop. There is a line of code I don't understand. Can someone please help me to understand the below method what it actually means.


//Sort ascending my month and descending my day of the week





The above code is in github and Im sharing that here : https://github.com/augusto/hadoop-sandbox/blob/master/src/main/java/org/apress/prohadoop/c6/MonthDoWWritable.java

Thank you!
 
Marshal
Posts: 15638
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The comment pretty much summarizes the intent. The -1* inverts the logic of the compareTo() method and essentially causes a descending sort order. The 1* part is redundant but I suspect it was just added to emphasize the ascending sort order.
 
Marshal
Posts: 69494
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:. . . . The -1* inverts the logic of the compareTo() method . . .

I don't know whether it is any different from Java®, but in Java® a simple negation of the result of a comparison method is error‑prone. You will find an explanation in this Java™ Tutorials page.
 
Sush Bathin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, if I understand correctly. The month is 1 and week is 4
.. if this.month =1 and passed month is 2 as 1==2(which is not equal) it goes to else part which is


so 1* (1=this.month).compareTo(?) where does second.month goes?
-----------------------------------------
case 2:
lets say the passed value is equal (1==1)

return -1*4.compareTo(?) I dont get that part.
 
Ever since I found this suit I've felt strange new needs. And a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic