statesystem : Add a default compareTo() for segments
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.segmentstore.core / src / org / eclipse / tracecompass / segmentstore / core / ISegment.java
index e82cf387d8322b42e11f469a546f82695f536627..eff096573ab314292ec92bfd0ffd3e5259d6285c 100644 (file)
@@ -14,13 +14,15 @@ package org.eclipse.tracecompass.segmentstore.core;
 
 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.
@@ -36,6 +38,13 @@ public interface ISegment extends Serializable, Comparable<ISegment> {
      */
     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.
      *
This page took 0.025635 seconds and 5 git commands to generate.