001package org.andromda.utils.beans.comparators; 002 003import java.io.Serializable; 004import java.util.Comparator; 005import java.util.Date; 006 007/** 008 * Used to sort by Date values 009 * 010 * @author Chad Brandon 011 */ 012class DateComparator 013 implements Comparator, 014 Serializable 015{ 016 private static final long serialVersionUID = 34L; 017 018 /** 019 * Used to sort Date values, both objects are assumed to be assignable 020 * to java.util.Date 021 * @param objectA 022 * @param objectB 023 * @return compare result 024 */ 025 public int compare( 026 final Object objectA, 027 final Object objectB) 028 { 029 final Date aAsDate = (Date)objectA; 030 final Date bAsDate = (Date)objectB; 031 int result = 0; 032 033 if (bAsDate.after(aAsDate)) 034 { 035 // set result to a negative integer if the first argument of this 036 // method is less than the second 037 result = -1; 038 } 039 else if (aAsDate.after(bAsDate)) 040 { 041 // set result to a positive integer if the first argument of this 042 // method is greater than the second 043 result = 1; 044 } 045 return result; 046 } 047}