01: package org.andromda.utils.beans.comparators;
02:
03: import java.io.Serializable;
04:
05: import java.util.Comparator;
06: import java.util.Date;
07:
08: /**
09: * Used to sort by Date values
10: *
11: * @author Chad Brandon
12: */
13: class DateComparator implements Comparator, Serializable {
14: /**
15: * Used to sort Date values, both objects are assumed to be assignable
16: * to java.util.Date
17: */
18: public int compare(final Object objectA, final Object objectB) {
19: final Date aAsDate = (Date) objectA;
20: final Date bAsDate = (Date) objectB;
21: int result = 0;
22:
23: if (bAsDate.after(aAsDate)) {
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 (aAsDate.after(bAsDate)) {
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: }
|