ss: Bug 475300: Fix inconsistent TreeMapStore due to value comparators
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.segmentstore.core / src / org / eclipse / tracecompass / segmentstore / core / BasicSegment.java
index 8abd688c63cbb9e24bb4bc2b0960396ec8bf4f48..252b76eaef5c6a91e4018dc176c0007b69fe77a4 100644 (file)
@@ -9,6 +9,14 @@
 
 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}.
  *
@@ -18,6 +26,10 @@ public class BasicSegment implements ISegment {
 
     private static final long serialVersionUID = -3257452887960883177L;
 
+    private static final Comparator<ISegment> COMPARATOR = checkNotNull(Ordering
+            .from(SegmentComparators.INTERVAL_START_COMPARATOR)
+            .compound(SegmentComparators.INTERVAL_END_COMPARATOR));
+
     private final long fStart;
     private final long fEnd;
 
@@ -54,9 +66,16 @@ public class BasicSegment implements ISegment {
         return (fEnd - fStart);
     }
 
+    @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$
     }
-
 }
This page took 0.034178 seconds and 5 git commands to generate.