01: /*******************************************************************************
02: * Product of NIST/ITL Advanced Networking Technologies Division (ANTD). *
03: *******************************************************************************/package tools.tracesviewer;
04:
05: import java.util.Comparator;
06:
07: /** A class that is used for comparing log records.
08: *
09: *@version 1.2
10: *
11: *@author M. Ranganathan <br/>
12: *
13: *
14: *
15: */
16:
17: class LogComparator implements Comparator {
18: public int compare(Object obj1, Object obj2) {
19: try {
20: TracesMessage m1 = (TracesMessage) obj1;
21: TracesMessage m2 = (TracesMessage) obj2;
22: long ts1 = Long.parseLong(m1.getTime());
23: long ts2 = Long.parseLong(m2.getTime());
24: if (m1.hashCode() == m2.hashCode()) {
25: return 0;
26: } else if (ts1 < ts2)
27: return -1;
28: else if (ts1 > ts2)
29: return 1;
30: else {
31: // Bug fix contributed by Pierre Sandström
32: return m1 != m2 ? 1 : 0;
33: }
34: } catch (NumberFormatException ex) {
35: ex.printStackTrace();
36: System.exit(0);
37: return 0;
38: }
39: }
40:
41: public boolean equals(Object obj2) {
42: return super.equals(obj2);
43:
44: }
45:
46: }
|