package org.eclipse.tracecompass.internal.ctf.core.trace;
import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import java.util.ListIterator;
public int indexOf(StreamInputPacketIndexEntry element) {
int indexOf = -1;
if (element != null) {
- indexOf = Collections.binarySearch(fEntries, element);
+ indexOf = Collections.binarySearch(fEntries, element, new MonotonicComparator());
}
return (indexOf < 0) ? -1 : indexOf;
}
+ /**
+ * Ordering comparator for entering entries into a data structure sorted by timestamp.
+ */
+ private static class MonotonicComparator implements Comparator<StreamInputPacketIndexEntry> {
+
+ @Override
+ public int compare(StreamInputPacketIndexEntry left, StreamInputPacketIndexEntry right) {
+ if (left.getTimestampBegin() > right.getTimestampBegin()) {
+ return 1;
+ }
+ if (left.getTimestampBegin() < right.getTimestampBegin()) {
+ return -1;
+ }
+ if (left.getTimestampEnd() > right.getTimestampEnd()) {
+ return 1;
+ }
+ if (left.getTimestampEnd() < right.getTimestampEnd()) {
+ return -1;
+ }
+ return 0;
+ }
+ }
+
}
* <p>
* Represents an entry in the index of event packets.
*/
-public class StreamInputPacketIndexEntry implements Comparable<StreamInputPacketIndexEntry> {
+public class StreamInputPacketIndexEntry {
// ------------------------------------------------------------------------
// Attributes
/**
* Which target is being traced
*/
- private String fTarget ;
+ private String fTarget;
private long fTargetID;
/**
*/
private final Map<String, Object> fAttributes = new HashMap<>();
-
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
}
/**
- * @param lostEvents the lostEvents to set
+ * @param lostEvents
+ * the lostEvents to set
*/
public void setLostEvents(long lostEvents) {
fLostEvents = lostEvents;
* The name of the attribute
* @return The value that was stored, or null if it wasn't found
*/
- public Object lookupAttribute(String field){
+ public Object lookupAttribute(String field) {
return fAttributes.get(field);
}
/**
* @return The ID of the target
*/
- public long getTargetId(){
+ public long getTargetId() {
return fTargetID;
}
-
- @Override
- public int compareTo(StreamInputPacketIndexEntry o) {
- if (fTimestampBegin > o.fTimestampBegin) {
- return 1;
- }
- if (fTimestampBegin < o.fTimestampBegin) {
- return -1;
- }
- if (fTimestampEnd > o.fTimestampEnd) {
- return 1;
- }
- if (fTimestampEnd < o.fTimestampEnd) {
- return -1;
- }
- return 0;
- }
}