01: package org.andromda.utils.beans.comparators;
02:
03: import java.io.Serializable;
04:
05: import java.util.Calendar;
06: import java.util.Comparator;
07:
08: /**
09: * Used to sort by Calendar values
10: *
11: * @author Chad Brandon
12: */
13: class CalendarComparator implements Comparator, Serializable {
14: /**
15: * Used to sort Calendar values, both objects are assumed to be assignable
16: * to java.util.Calendar
17: */
18: public int compare(Object objectA, Object objectB) {
19: Calendar aAsCalendar = (Calendar) objectA;
20: Calendar bAsCalendar = (Calendar) objectB;
21: int result = 0;
22:
23: if (bAsCalendar.after(aAsCalendar)) {
24: // set result to a negative integer if the first argument of this
25: // method is less than the second
26: result = -1;
27: } else if (aAsCalendar.after(bAsCalendar)) {
28: // set result to a positive integer if the first argument of this
29: // method is greater than the second
30: result = 1;
31: }
32: return result;
33: }
34: }
|