Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date Ascending order Comparator

 
Adrian Enns
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a comparator that sorts a collection of objects by date in descending order, but I'm having problem creating a comparator that sorts by date in ascending order. Can you help?

The code for the desceding comparator is:

private class DateComparatorDescending implements Comparator
{
public int compare(Object one, Object two)
{
CmnProbEduTraining objOne = (CmnProbEduTraining)one;
CmnProbEduTraining objTwo = (CmnProbEduTraining)two;

if (objOne.getInsertedDt().after(objTwo.getInsertedDt()))
{
return -1;
}
else if (objOne.getInsertedDt().before(objTwo.getInsertedDt()))
{
return +1;
}
else
{
return 0;
}
}
}
 
Henry Wong
author
Marshal
Pie
Posts: 21506
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what happens when you substitute negative one for one, and visa versa?

Henry
 
Adrian Enns
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that worked. I had tried that, but my changed code wasn't getting deployed to my server for some reason. Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic