• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Coding Question in Hadoop

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 17696
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79964
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2949
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Master Rancher
Posts: 5060
81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Quick! Before anybody notices! Cover it up with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic