Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / event / TmfTimestamp.java
index b786e3dd309d0e0de640a17e7a05c17864a54c6c..0708e277212645882d9b8251570ec05993e6b06b 100644 (file)
@@ -41,7 +41,7 @@ package org.eclipse.linuxtools.tmf.event;
  * Notice that the adjusted timestamp value could be negative e.g. for events
  * that occurred before t0 wrt the reference clock.
  */
-public class TmfTimestamp implements Cloneable {
+public class TmfTimestamp implements Cloneable, Comparable<TmfTimestamp> {
 
        // ------------------------------------------------------------------------
     // Attributes
@@ -256,6 +256,23 @@ public class TmfTimestamp implements Cloneable {
         return ts2.fValue - ts1.fValue;
     }
 
+    /**
+     * Compute the delta between two timestamps (adjusted to scale of current timestamp).
+     * 
+     * @param reference the reference timestamp to synchronize with
+     * @return the delta timestamp 
+     * @throws ArithmeticException
+     */
+    public TmfTimestamp getDelta(TmfTimestamp other) throws ArithmeticException {
+        TmfTimestamp newSecond = other;
+        if ((fScale != other.fScale) || (fPrecision != other.fPrecision)) {
+            newSecond = other.synchronize(0, fScale);
+        }
+        return new TmfTimestamp(fValue - newSecond.fValue,
+                                fScale, 
+                                newSecond.fPrecision > fPrecision ? newSecond.fPrecision : fPrecision);
+    }
+
     /**
      * Compare with another timestamp
      * 
@@ -372,4 +389,9 @@ public class TmfTimestamp implements Cloneable {
                return clone;
     }
 
+       @Override
+       public int compareTo(TmfTimestamp o) {
+               return compareTo(o, false);
+       }
+
 }
This page took 0.023992 seconds and 5 git commands to generate.