Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package kiekerdays.tcptracereduction;
import java.io.Serializable;
import java.util.Comparator;
import kieker.analysis.plugin.filter.flow.TraceEventRecords;
import kieker.common.record.flow.trace.AbstractTraceEvent;
import kieker.common.record.flow.trace.operation.AbstractOperationEvent;
import kieker.common.record.flow.trace.operation.AfterOperationFailedEvent;
/**
* @author Jan Waller, Florian Fittkau, Florian Biss
*/
public final class TraceComperator implements Comparator<TraceEventRecords>, Serializable {
private static final long serialVersionUID = 8920766818232517L;
/**
* Creates a new instance of this class.
*/
public TraceComperator() {
// default empty constructor
}
/**
* {@inheritDoc}
*/
@Override
public int compare(final TraceEventRecords t1, final TraceEventRecords t2) {
final AbstractTraceEvent[] recordsT1 = t1.getTraceEvents();
final AbstractTraceEvent[] recordsT2 = t2.getTraceEvents();
if (recordsT1.length != recordsT2.length) {
return recordsT1.length - recordsT2.length;
}
final int cmpHostnames = t1.getTraceMetadata().getHostname()
.compareTo(t2.getTraceMetadata().getHostname());
if (cmpHostnames != 0) {
return cmpHostnames;
}
for (int i = 0; i < recordsT1.length; i++) {
final AbstractTraceEvent recordT1 = recordsT1[i];
final AbstractTraceEvent recordT2 = recordsT2[i];
final int cmpClass = recordT1.getClass().getName()
.compareTo(recordT2.getClass().getName());
if (cmpClass != 0) {
return cmpClass;
}
if (recordT1 instanceof AbstractOperationEvent) {
final int cmpSignature = ((AbstractOperationEvent) recordT1).getOperationSignature()
.compareTo(((AbstractOperationEvent) recordT2).getOperationSignature());
if (cmpSignature != 0) {
return cmpSignature;
}
}
if (recordT1 instanceof AfterOperationFailedEvent) {
final int cmpError = ((AfterOperationFailedEvent) recordT1).getCause().compareTo(
((AfterOperationFailedEvent) recordT2).getCause());
if (cmpError != 0) {
return cmpClass;
}
}
}
// All records match.
return 0;
}
}