package org.eclipse.linuxtools.tmf.event;
-
/**
* <b><u>TmfTimestamp</u></b>
* <p>
* 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
int scaleDiff = Math.abs(fScale - newScale);
// Let's try to be realistic...
if (scaleDiff >= scalingFactors.length) {
- throw new ArithmeticException("Scaling exception");
+ throw new ArithmeticException("Scaling exception"); //$NON-NLS-1$
}
// Adjust the timestamp
long scalingFactor = scalingFactors[scaleDiff];
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
*
}
@Override
+ @SuppressWarnings("nls")
public String toString() {
return "[TmfTimestamp(" + fValue + "," + fScale + "," + fPrecision + ")]";
}
return clone;
}
+ @Override
+ public int compareTo(TmfTimestamp o) {
+ return compareTo(o, false);
+ }
+
}