1 package org.andromda.utils.beans.comparators;
2
3 import java.io.Serializable;
4 import java.util.Comparator;
5 import java.util.Date;
6
7 /**
8 * Used to sort by Date values
9 *
10 * @author Chad Brandon
11 */
12 class DateComparator
13 implements Comparator,
14 Serializable
15 {
16 private static final long serialVersionUID = 34L;
17
18 /**
19 * Used to sort Date values, both objects are assumed to be assignable
20 * to java.util.Date
21 * @param objectA
22 * @param objectB
23 * @return compare result
24 */
25 public int compare(
26 final Object objectA,
27 final Object objectB)
28 {
29 final Date aAsDate = (Date)objectA;
30 final Date bAsDate = (Date)objectB;
31 int result = 0;
32
33 if (bAsDate.after(aAsDate))
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 (aAsDate.after(bAsDate))
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 }