001package org.andromda.utils.beans.comparators; 002 003import java.io.Serializable; 004import java.util.Calendar; 005import java.util.Comparator; 006 007/** 008 * Used to sort by Calendar values 009 * 010 * @author Chad Brandon 011 */ 012class CalendarComparator 013 implements Comparator, 014 Serializable 015{ 016 private static final long serialVersionUID = 34L; 017 018 /** 019 * Used to sort Calendar values, both objects are assumed to be assignable 020 * to java.util.Calendar 021 * @param objectA 022 * @param objectB 023 * @return compareresult 024 */ 025 public int compare( 026 Object objectA, 027 Object objectB) 028 { 029 Calendar aAsCalendar = (Calendar)objectA; 030 Calendar bAsCalendar = (Calendar)objectB; 031 int result = 0; 032 033 if (bAsCalendar.after(aAsCalendar)) 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 (aAsCalendar.after(bAsCalendar)) 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}