1 package org.andromda.utils.beans.comparators;
2
3 import java.io.Serializable;
4 import java.util.Calendar;
5 import java.util.Comparator;
6
7 /**
8 * Used to sort by Calendar values
9 *
10 * @author Chad Brandon
11 */
12 class CalendarComparator
13 implements Comparator,
14 Serializable
15 {
16 private static final long serialVersionUID = 34L;
17
18 /**
19 * Used to sort Calendar values, both objects are assumed to be assignable
20 * to java.util.Calendar
21 * @param objectA
22 * @param objectB
23 * @return compareresult
24 */
25 public int compare(
26 Object objectA,
27 Object objectB)
28 {
29 Calendar aAsCalendar = (Calendar)objectA;
30 Calendar bAsCalendar = (Calendar)objectB;
31 int result = 0;
32
33 if (bAsCalendar.after(aAsCalendar))
34 {
35 // set result to a negative integer if the first argument of this
36 // method is less than the second
37 result = -1;
38 }
39 else if (aAsCalendar.after(bAsCalendar))
40 {
41 // set result to a positive integer if the first argument of this
42 // method is greater than the second
43 result = 1;
44 }
45 return result;
46 }
47 }