01: package org.dbbrowser.drivermanager;
02:
03: import java.util.Comparator;
04: import java.util.Date;
05:
06: /**
07: * Sorts connection info on the basis of last used date
08: * @author amangat
09: */
10: public class ConnectionInfoSorter implements Comparator {
11: /**
12: * Compare 2 ConnectionInfo object by 'last used date'
13: * @param o1
14: * @param o2
15: * @return
16: */
17: public int compare(Object o1, Object o2) {
18: ConnectionInfo ci1 = (ConnectionInfo) o1;
19: ConnectionInfo ci2 = (ConnectionInfo) o2;
20:
21: Date lastUsed1 = ci1.getLastUsed();
22: Date lastUsed2 = ci2.getLastUsed();
23:
24: int returnValue = 0;
25: if (lastUsed1 == null && lastUsed2 == null) {
26: returnValue = 0;
27: } else if (lastUsed1 == null) {
28: returnValue = 1;
29: } else if (lastUsed2 == null) {
30: returnValue = -1;
31: } else {
32: returnValue = lastUsed2.compareTo(lastUsed1);
33: }
34: return returnValue;
35: }
36: }
|