Wednesday, August 02, 2006

Date Comparator

// Create Date Comparator for ChangeLogEntry's
Comparator comparator = new Comparator() {
public int compare(Object object1, Object object2) {
ChangeLogEntry entry1 = (ChangeLogEntry)object1;
ChangeLogEntry entry2 = (ChangeLogEntry)object2;

// Compare Dates
int compare = entry1.getDate().compareTo(entry2.getDate());

// Invert so that sort is descending
return (compare * -1);
}
};

// Sort the entries
Collections.sort(filteredEntries, comparator);

No comments: