import MailMessage; import Comparator; public class DateComparator implements Comparator { public boolean lessThan(Object first, Object second) { String date1 = ((MailMessage)first).getField("date"); String date2 = ((MailMessage)second).getField("date"); Integer year1 = Integer.valueOf(date1.substring(12,16)); // System.out.println(year1); Integer year2 = Integer.valueOf(date2.substring(12,16)); if (year1.intValue() < year2.intValue()) return true; if (year2.intValue() < year1.intValue()) return false; String strMonth1 = date1.substring(8,11); String strMonth2 = date2.substring(8,11); int month1 = 0; int month2 = 0; if (strMonth1.equals("Jan")) month1 = 1; if (strMonth1.equals("Feb")) month1 = 2; if (strMonth1.equals("Mar")) month1 = 3; if (strMonth1.equals("Apr")) month1 = 4; if (strMonth1.equals("May")) month1 = 5; if (strMonth1.equals("Jun")) month1 = 6; if (strMonth1.equals("Jul")) month1 = 7; if (strMonth1.equals("Aug")) month1 = 8; if (strMonth1.equals("Sep")) month1 = 9; if (strMonth1.equals("Oct")) month1 = 10; if (strMonth1.equals("Nov")) month1 = 11; if (strMonth1.equals("Dec")) month1 = 12; if (strMonth2.equals("Jan")) month2 = 1; if (strMonth2.equals("Feb")) month2 = 2; if (strMonth2.equals("Mar")) month2 = 3; if (strMonth2.equals("Apr")) month2 = 4; if (strMonth2.equals("May")) month2 = 5; if (strMonth2.equals("Jun")) month2 = 6; if (strMonth2.equals("Jul")) month2 = 7; if (strMonth2.equals("Aug")) month2 = 8; if (strMonth2.equals("Sep")) month2 = 9; if (strMonth2.equals("Oct")) month2 = 10; if (strMonth2.equals("Nov")) month2 = 11; if (strMonth2.equals("Dec")) month2 = 12; if (month1 < month2) { System.out.println("Month1: " + month1 + " < " + "Month2: " + month2 + " " + "returning true"); return true; }//if if (month1 > month2) { System.out.println("Month1: " + month2 + " > " + "Month2:" + month1 + " " + "returning false"); return false; }//if Integer day1 = Integer.valueOf(date1.substring(5,7)); Integer day2 = Integer.valueOf(date2.substring(5,7)); if (day1.intValue() < day2.intValue()) return true; if (day2.intValue() < day1.intValue()) return false; Integer time1 = Integer.valueOf(date1.substring(17,19) + date1.substring(20,22) + date1.substring(23,25)); Integer time2 = Integer.valueOf(date2.substring(17,19) + date2.substring(20,22) + date2.substring(23,25)); if (time1.intValue() < time2.intValue()) return true; if (time2.intValue() < time1.intValue()) return false; return true; } public boolean equals(Object first, Object second) { return true; } } // public class // 0000000001111111111222222222234 // 1234567890123456789012345678901 //Sat, 20 Nov 1999 16:15:53 -0600