• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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: 15887
265
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: 70318
283
  • 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.
 
Ranch Hand
Posts: 1666
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think instead of relating this to hadoop, if we understand it simply as core Java coding ,then it is easier to understand. Infact , it has nothing to do with Hadoop and all with code Java.
 
Rancher
Posts: 3628
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is old now, but...

I would also add that the variable name "second" is confusing here.  It's apparently intended as the name of the other object being compared to, the second object.  But since we see the name "second" next to "month" and "day of week", it can easily sound like it refers to seconds as a measure of time.  Bad choice of name - if they'd just called the other object "other", it would have been much clearer.
    Bookmark Topic Watch Topic
  • New Topic