posted 19 years ago
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;
}
}
}