tmf: Add an 'intersects' method to ITmfTimestamp
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Fri, 12 Apr 2013 23:05:18 +0000 (19:05 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 16 Apr 2013 19:08:26 +0000 (15:08 -0400)
Trivial implementation, but makes it more simple to check if
a timestamp is part of a given range.

Change-Id: I6ec1cc929f77cd5df5bc95b6b238c235f8b11f55
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/11914
Tested-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
IP-Clean: Patrick Tasse <patrick.tasse@gmail.com>

org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/ITmfTimestamp.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimestamp.java

index 3baf2ffd098784084e1f6827c2142e951e1528be..39dbb387deb4c3eea045449be05307168c977e1f 100644 (file)
@@ -45,25 +45,21 @@ public interface ITmfTimestamp extends Comparable<ITmfTimestamp> {
 
     /**
      * The millisecond scale factor (10e0)
-     * @since 2.0
      */
     public static final int SECOND_SCALE = 0;
 
     /**
      * The millisecond scale factor (10e-3)
-     * @since 2.0
      */
     public static final int MILLISECOND_SCALE = -3;
 
     /**
      * The microsecond scale factor (10e-6)
-     * @since 2.0
      */
     public static final int MICROSECOND_SCALE = -6;
 
     /**
      * The nanosecond scale factor (10e-9)
-     * @since 2.0
      */
     public static final int NANOSECOND_SCALE = -9;
 
@@ -116,13 +112,21 @@ public interface ITmfTimestamp extends Comparable<ITmfTimestamp> {
      */
     public ITmfTimestamp getDelta(ITmfTimestamp ts);
 
+    /**
+     * Returns if this timestamp intersects the given time range. Borders are
+     * inclusive (for more fine-grained behavior, you can use
+     * {@link #compareTo(ITmfTimestamp)}.
+     *
+     * @param range
+     *            The time range to compare to
+     * @return True if this timestamp is part of the time range, false if not
+     */
+    public boolean intersects(TmfTimeRange range);
+
     // ------------------------------------------------------------------------
     // Comparable
     // ------------------------------------------------------------------------
 
-    /* (non-Javadoc)
-     * @see java.lang.Comparable#compareTo(java.lang.Object)
-     */
     @Override
     int compareTo(ITmfTimestamp ts);
 
index 19665b36323cb14d0fead14c68baf0abe0534f28..c31ef9082e5bdca68b70b507c54c457ecb936ec6 100644 (file)
@@ -44,13 +44,11 @@ public class TmfTimestamp implements ITmfTimestamp {
 
     /**
      * A more practical definition of "beginning of time"
-     * @since 2.0
      */
     public static final ITmfTimestamp PROJECT_IS_FUNDED = BIG_BANG;
 
     /**
      * A more practical definition of "end of time"
-     * @since 2.0
      */
     public static final ITmfTimestamp PROJECT_IS_CANNED = BIG_CRUNCH;
 
@@ -291,6 +289,15 @@ public class TmfTimestamp implements ITmfTimestamp {
         return new TmfTimestampDelta(value, fScale, fPrecision + nts.getPrecision());
     }
 
+    @Override
+    public boolean intersects(TmfTimeRange range) {
+        if (this.compareTo(range.getStartTime()) >= 0 &&
+                this.compareTo(range.getEndTime()) <= 0) {
+            return true;
+        }
+        return false;
+    }
+
     // ------------------------------------------------------------------------
     // Comparable
     // ------------------------------------------------------------------------
This page took 0.02911 seconds and 5 git commands to generate.