package org.eclipse.tracecompass.analysis.os.linux.core.latency;
-import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
-
import java.io.Serializable;
-import java.util.Comparator;
import java.util.Map;
-import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.common.core.NonNullUtils;
import org.eclipse.tracecompass.segmentstore.core.ISegment;
-import org.eclipse.tracecompass.segmentstore.core.SegmentComparators;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Ordering;
/**
* A linux kernel system call, represented as an {@link ISegment}.
private static final long serialVersionUID = 1554494342105208730L;
- private static final Comparator<ISegment> COMPARATOR = checkNotNull(Ordering
- .from(SegmentComparators.INTERVAL_START_COMPARATOR)
- .compound(SegmentComparators.INTERVAL_END_COMPARATOR)
- /* Kind of lazy, but should work! */
- .compound(Ordering.usingToString()));
-
/**
* The subset of information that is available from the syscall entry event.
*/
}
@Override
- public int compareTo(@Nullable ISegment o) {
- if (o == null) {
- throw new IllegalArgumentException();
+ public int compareTo(@NonNull ISegment o) {
+ int ret = ISegment.super.compareTo(o);
+ if (ret != 0) {
+ return ret;
}
- return COMPARATOR.compare(this, o);
+ return toString().compareTo(o.toString());
}
@Override
package org.eclipse.tracecompass.segmentstore.core;
-import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
-
-import java.util.Comparator;
-
-import org.eclipse.jdt.annotation.Nullable;
-
-import com.google.common.collect.Ordering;
-
/**
* Basic implementation of {@link ISegment}.
*
private static final long serialVersionUID = -3257452887960883177L;
- private static final Comparator<ISegment> COMPARATOR;
- static {
- /* checkNotNull() has to be called separately, or else it breaks the
- * type inference. */
- Comparator<ISegment> comp = Ordering
- .from(SegmentComparators.INTERVAL_START_COMPARATOR)
- .compound(SegmentComparators.INTERVAL_END_COMPARATOR);
- COMPARATOR = checkNotNull(comp);
- }
-
private final long fStart;
private final long fEnd;
return fEnd;
}
- @Override
- public int compareTo(@Nullable ISegment o) {
- if (o == null) {
- throw new IllegalArgumentException();
- }
- return COMPARATOR.compare(this, o);
- }
-
@Override
public String toString() {
return new String('[' + String.valueOf(fStart) + ", " + String.valueOf(fEnd) + ']'); //$NON-NLS-1$
import java.io.Serializable;
+import org.eclipse.jdt.annotation.NonNull;
+
/**
* Generic interface for any segment (like a time range) that can be used in the
* segment store.
*
* @author Alexandre Montplaisir
*/
-public interface ISegment extends Serializable, Comparable<ISegment> {
+public interface ISegment extends Serializable, Comparable<@NonNull ISegment> {
/**
* The start position/time of the segment.
*/
long getEnd();
+ @Override
+ default int compareTo(@NonNull ISegment arg0) {
+ return SegmentComparators.INTERVAL_START_COMPARATOR
+ .thenComparing(SegmentComparators.INTERVAL_END_COMPARATOR)
+ .compare(this, arg0);
+ }
+
/**
* The length/duration of the segment.
*
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.segmentstore.core.ISegment;
-import org.eclipse.tracecompass.segmentstore.core.SegmentComparators;
import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
-import com.google.common.collect.Ordering;
-
/**
* This class implements an XML Pattern Segment. This type of segment has
* content and a default timestamp, which is the start time of the segment.
private static final byte TYPE_STRING = 1;
private static final byte TYPE_LONG = 2;
- private static final @NonNull Comparator<ISegment> COMPARATOR = Ordering
- .from(SegmentComparators.INTERVAL_START_COMPARATOR)
- .compound(SegmentComparators.INTERVAL_END_COMPARATOR)
- /* Kind of lazy, but should work! */
- .compound(Ordering.usingToString());
-
private final int fScale;
private final long fStart;
private final long fEnd;
}
@Override
- public int compareTo(@Nullable ISegment o) {
- if (o == null) {
- throw new IllegalArgumentException("Cannot compare to null"); //$NON-NLS-1$
+ public int compareTo(@NonNull ISegment o) {
+ int ret = ISegment.super.compareTo(o);
+ if (ret != 0) {
+ return ret;
}
- return COMPARATOR.compare(this, o);
+ return toString().compareTo(o.toString());
}
@Override