How to sort a list of periods with a datefrom and a dateto

I have a list of periods which have a datefrom and a dateto. I want to sort the list first on datefrom and then on dateto. So that when there are equal datefroms within those the periods are sorted on the dateto. Example: DateFrom --> DateTo 12-05-2012 --> 15-06-2012 12-05-2012 --> 19-06-2012 24-05-2012 --> 26-05-2012 I have created a javaaction and written a small piece of java which does the first sorting. The piece of code uses Collection.sort and the following comparator: class customComparatorValidFrom implements Comparator<Period> { public int compare(Period object1, Period object2) { return object1.getValidFrom().compareTo(object2.getValidFrom()); } } My question is how I can accomplish the second sorting. Anybody has a clue?
1 answers

Wouldn't it be easier to just retrieve the list of Periods in a microflow, using ValidFrom as the primary sort attribute, and ValidTo as the secondary?

Anyway, in Java you'd do something like this:

public int compare(Period period1, Period period2) {
    int validFromCompare = period1.getValidFrom().compareTo(period2.getValidFrom());
    return validFromCompare == 0 ? period1.getValidTo().compareTo(period2.getValidTo()) : validFromCompare;

Note that this requires ValidFrom and ValidTo to be set, i.e. the value empty might cause problems.