tmf.core: Introduce ITmfTimestamp#toNanos
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / timestamp / ITmfTimestamp.java
index cc6e79ac049e5dc50ca951216fe72483e77c1841..b636362ea20b2949346b859a7715c7608d780e21 100644 (file)
@@ -77,6 +77,21 @@ public interface ITmfTimestamp extends Comparable<ITmfTimestamp> {
      */
     int getScale();
 
+    /**
+     * Gets the timestamp converted to nanoseconds, if the timestamp is larger
+     * than {@link Long#MAX_VALUE} or smaller than {@link Long#MIN_VALUE} it
+     * will be clamped to those values.
+     *
+     * @return the timestamp converted to a long value of nanoseconds
+     * @since 2.0
+     */
+    default long toNanos(){
+        if (getScale() == NANOSECOND_SCALE) {
+            return getValue();
+        }
+        return normalize(0L, NANOSECOND_SCALE).getValue();
+    }
+
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
This page took 0.030652 seconds and 5 git commands to generate.