@Test
public void testNormalizeScaleNot0() {
ITmfTimestamp ts = ts0.normalize(0, 1);
- assertEquals("getValue", 0, ts.getValue());
- assertEquals("getscale", 1, ts.getScale());
+ assertEquals("Zero", TmfTimestamp.ZERO, ts);
ts = ts0.normalize(12345, 1);
assertEquals("getValue", 12345, ts.getValue());
@Test
public void testNormalizeScaleNot0() {
ITmfTimestamp ts = ts0.normalize(0, 1);
- assertEquals("getValue", 0, ts.getValue());
- assertEquals("getscale", 1, ts.getScale());
+ assertEquals("Zero test", TmfTimestamp.ZERO, ts);
ts = ts0.normalize(12345, 1);
assertEquals("getValue", 12345, ts.getValue());
@Test
public void testNormalizeScale() {
+ ITmfTimestamp ts = ts1.normalize(0, 3);
+ assertEquals("getValue", 12, ts.getValue());
+ assertEquals("getscale", 3, ts.getScale());
+
+ ts = ts1.normalize(0, -3);
+ assertEquals("getValue", 12345000L, ts.getValue());
+ assertEquals("getscale", -3, ts.getScale());
+ }
+
+ @Test
+ public void testNormalizeLargeScale() {
+ ITmfTimestamp ts = ts1.normalize(0, 10);
+ assertEquals("getValue", 0, ts.getValue());
+ assertEquals("getscale", 0, ts.getScale());
+
+ ts = ts1.normalize(0, -10);
+ assertEquals("getValue", 123450000000000L, ts.getValue());
+ assertEquals("getscale", -10, ts.getScale());
+ }
+
+ @Test
+ public void testNormalizeZeroScale() {
ITmfTimestamp ts = ts0.normalize(0, 10);
assertEquals("getValue", 0, ts.getValue());
- assertEquals("getscale", 10, ts.getScale());
+ assertEquals("getscale", 0, ts.getScale());
ts = ts0.normalize(0, -10);
assertEquals("getValue", 0, ts.getValue());
- assertEquals("getscale", -10, ts.getScale());
+ assertEquals("getscale", 0, ts.getScale());
}
@Test
public void testNormalizeOffsetAndScale() {
final int SCALE = 12;
- ITmfTimestamp ts = ts0.normalize(0, SCALE);
+ ITmfTimestamp ts = ts1.normalize(0, SCALE);
assertEquals("getValue", 0, ts.getValue());
- assertEquals("getscale", SCALE, ts.getScale());
+ assertEquals("getscale", 0, ts.getScale()); // zeroed
- ts = ts0.normalize(12345, SCALE);
+ ts = ts1.normalize(12345, SCALE);
assertEquals("getValue", 12345, ts.getValue());
assertEquals("getscale", SCALE, ts.getScale());
- ts = ts0.normalize(10, SCALE);
+ ts = ts1.normalize(10, SCALE);
assertEquals("getValue", 10, ts.getValue());
assertEquals("getscale", SCALE, ts.getScale());
- ts = ts0.normalize(-10, SCALE);
+ ts = ts1.normalize(-10, SCALE);
assertEquals("getValue", -10, ts.getValue());
assertEquals("getscale", SCALE, ts.getScale());
}
final ITmfTimestamp ts0b = TmfTimestamp.create(0, Integer.MAX_VALUE);
final ITmfTimestamp ts0c = TmfTimestamp.create(Long.MAX_VALUE, Integer.MAX_VALUE);
- assertEquals("compareTo", 1, ts0a.compareTo(ts0b));
- assertEquals("compareTo", -1, ts0a.compareTo(ts0c));
+ assertTrue("compareTo", ts0a.compareTo(ts0b) > 0);
+ assertTrue("compareTo", ts0a.compareTo(ts0c) < 0);
- assertEquals("compareTo", -1, ts0b.compareTo(ts0a));
- assertEquals("compareTo", -1, ts0b.compareTo(ts0c));
+ assertTrue("compareTo", ts0b.compareTo(ts0a) < 0);
+ assertTrue("compareTo", ts0b.compareTo(ts0c) < 0);
- assertEquals("compareTo", 1, ts0c.compareTo(ts0a));
- assertEquals("compareTo", 1, ts0c.compareTo(ts0b));
+ assertTrue("compareTo", ts0c.compareTo(ts0a) > 0);
+ assertTrue("compareTo", ts0c.compareTo(ts0b) > 0);
}
@Test
final ITmfTimestamp ts0b = TmfTimestamp.create(0, Integer.MAX_VALUE);
final ITmfTimestamp ts0c = TmfTimestamp.create(Long.MIN_VALUE, Integer.MAX_VALUE);
- assertEquals("compareTo", -1, ts0a.compareTo(ts0b));
- assertEquals("compareTo", 1, ts0a.compareTo(ts0c));
+ assertTrue("compareTo", ts0a.compareTo(ts0b) < 0);
+ assertTrue("compareTo", ts0a.compareTo(ts0c) > 0);
- assertEquals("compareTo", 1, ts0b.compareTo(ts0a));
- assertEquals("compareTo", 1, ts0b.compareTo(ts0c));
+ assertTrue("compareTo", ts0b.compareTo(ts0a) > 0);
+ assertTrue("compareTo", ts0b.compareTo(ts0c) > 0);
- assertEquals("compareTo", -1, ts0c.compareTo(ts0a));
- assertEquals("compareTo", -1, ts0c.compareTo(ts0b));
+ assertTrue("compareTo", ts0c.compareTo(ts0a) < 0);
+ assertTrue("compareTo", ts0c.compareTo(ts0b) < 0);
}
- @Test
+ @Test(expected = NullPointerException.class)
public void testCompareToCornerCases4() {
- assertEquals("compareTo", 1, ts0.compareTo(null));
+ assertTrue("compareTo", ts0.compareTo(null) > 0);
}
@Test
assertTrue("CompareTo", t3.compareTo(t4) > 0);
}
+ @Test
+ public void testCompareToDifferentScale2() {
+ final ITmfTimestamp t5 = TmfTimestamp.fromSeconds(1);
+ final ITmfTimestamp t6 = TmfTimestamp.fromMillis(1234);
+
+ assertTrue("CompareTo", t5.compareTo(t6) < 0);
+ assertTrue("CompareTo", t6.compareTo(t5) > 0);
+ }
+
+ @Test
+ public void testCompareToSpecials() {
+ ITmfTimestamp ersatzBigBang = TmfTimestamp.create(Long.MIN_VALUE, Integer.MAX_VALUE);
+ ITmfTimestamp ersatzBigCrunch = TmfTimestamp.create(Long.MAX_VALUE, Integer.MAX_VALUE);
+
+ ITmfTimestamp lolo = TmfTimestamp.fromMicros(Long.MIN_VALUE);
+ ITmfTimestamp lo = TmfTimestamp.fromMillis(-100);
+ ITmfTimestamp lohi = TmfTimestamp.fromMicros(100);
+ ITmfTimestamp hilo = TmfTimestamp.fromMillis(Long.MIN_VALUE);
+ ITmfTimestamp hi = TmfTimestamp.fromMillis(100);
+
+ assertTrue("CompareTo", TmfTimestamp.BIG_BANG.compareTo(ts0) < 0);
+ assertTrue("CompareTo", TmfTimestamp.BIG_BANG.compareTo(ts1) < 0);
+ assertTrue("CompareTo", TmfTimestamp.BIG_BANG.compareTo(ts2) < 0);
+ assertTrue("CompareTo", TmfTimestamp.BIG_BANG.compareTo(ts3) < 0);
+ assertTrue("CompareTo", TmfTimestamp.BIG_BANG.compareTo(ts4) < 0);
+ assertTrue("CompareTo", TmfTimestamp.BIG_BANG.compareTo(TmfTimestamp.fromSeconds(Long.MIN_VALUE)) < 0);
+ assertTrue("CompareTo", TmfTimestamp.BIG_BANG.compareTo(ersatzBigBang) < 0);
+ assertTrue("CompareTo", TmfTimestamp.BIG_BANG.compareTo(TmfTimestamp.BIG_CRUNCH) < 0);
+ assertTrue("CompareTo", TmfTimestamp.BIG_BANG.compareTo(TmfTimestamp.BIG_BANG) == 0);
+ assertTrue("CompareTo", ts0.compareTo(TmfTimestamp.BIG_BANG) > 0);
+ assertTrue("CompareTo", ts1.compareTo(TmfTimestamp.BIG_BANG) > 0);
+ assertTrue("CompareTo", ts2.compareTo(TmfTimestamp.BIG_BANG) > 0);
+ assertTrue("CompareTo", ts3.compareTo(TmfTimestamp.BIG_BANG) > 0);
+ assertTrue("CompareTo", ts4.compareTo(TmfTimestamp.BIG_BANG) > 0);
+ assertTrue("CompareTo", ersatzBigBang.compareTo(TmfTimestamp.BIG_BANG) > 0);
+
+ assertTrue("CompareTo", TmfTimestamp.BIG_CRUNCH.compareTo(ts0) > 0);
+ assertTrue("CompareTo", TmfTimestamp.BIG_CRUNCH.compareTo(ts1) > 0);
+ assertTrue("CompareTo", TmfTimestamp.BIG_CRUNCH.compareTo(ts2) > 0);
+ assertTrue("CompareTo", TmfTimestamp.BIG_CRUNCH.compareTo(ts3) > 0);
+ assertTrue("CompareTo", TmfTimestamp.BIG_CRUNCH.compareTo(ts4) > 0);
+ assertTrue("CompareTo", TmfTimestamp.BIG_CRUNCH.compareTo(TmfTimestamp.fromSeconds(Long.MIN_VALUE)) > 0);
+ assertTrue("CompareTo", TmfTimestamp.BIG_CRUNCH.compareTo(ersatzBigCrunch) > 0);
+ assertTrue("CompareTo", TmfTimestamp.BIG_CRUNCH.compareTo(TmfTimestamp.BIG_BANG) > 0);
+ assertTrue("CompareTo", TmfTimestamp.BIG_CRUNCH.compareTo(TmfTimestamp.BIG_CRUNCH) == 0);
+ assertTrue("CompareTo", ts0.compareTo(TmfTimestamp.BIG_CRUNCH) < 0);
+ assertTrue("CompareTo", ts1.compareTo(TmfTimestamp.BIG_CRUNCH) < 0);
+ assertTrue("CompareTo", ts2.compareTo(TmfTimestamp.BIG_CRUNCH) < 0);
+ assertTrue("CompareTo", ts3.compareTo(TmfTimestamp.BIG_CRUNCH) < 0);
+ assertTrue("CompareTo", ts4.compareTo(TmfTimestamp.BIG_CRUNCH) < 0);
+ assertTrue("CompareTo", ersatzBigCrunch.compareTo(TmfTimestamp.BIG_CRUNCH) < 0);
+
+ assertTrue("CompareTo", ersatzBigBang.compareTo(ersatzBigCrunch) < 0);
+ assertTrue("CompareTo", ersatzBigCrunch.compareTo(ersatzBigBang) > 0);
+ assertTrue("CompareTo", ersatzBigBang.compareTo(ersatzBigBang) == 0);
+
+ assertTrue("CompareTo", lolo.compareTo(hi) < 0);
+ assertTrue("CompareTo", hi.compareTo(lolo) > 0);
+ assertTrue("CompareTo", lolo.compareTo(lolo) == 0);
+
+ assertTrue("CompareTo", lo.compareTo(hi) < 0);
+ assertTrue("CompareTo", hi.compareTo(lo) > 0);
+ assertTrue("CompareTo", lo.compareTo(lo) == 0);
+
+ assertTrue("CompareTo", hilo.compareTo(lohi) < 0);
+ assertTrue("CompareTo", lohi.compareTo(hilo) > 0);
+ assertTrue("CompareTo", hilo.compareTo(hilo) == 0);
+
+ }
+
@Test
public void testCompareToLargeScale1() {
final ITmfTimestamp t1 = TmfTimestamp.create(-1, 100);
final ITmfTimestamp t3 = TmfTimestamp.create(1, 100);
final ITmfTimestamp t4 = TmfTimestamp.create(1000, -100);
- assertEquals("CompareTo", -1, t1.compareTo(t2));
+ assertTrue("CompareTo", t1.compareTo(t2) < 0);
assertTrue("CompareTo", t1.compareTo(t3) < 0);
assertTrue("CompareTo", t1.compareTo(t4) < 0);
assertEquals("CompareTo", -1, ts0.compareTo(ts0b));
}
+ @Test
+ public void testCompareToLargeScale3() {
+ final ITmfTimestamp ts0a = TmfTimestamp.create(1, Integer.MAX_VALUE);
+ final ITmfTimestamp ts0b = TmfTimestamp.create(2, Integer.MAX_VALUE);
+
+ assertTrue("CompareTo", ts0b.compareTo(ts0a) > 0);
+ assertTrue("CompareTo", ts0a.compareTo(ts0b) < 0);
+ }
+
// ------------------------------------------------------------------------
// getDelta
// ------------------------------------------------------------------------
return ITmfTimestamp.NANOSECOND_SCALE;
}
- // ------------------------------------------------------------------------
- // ITmfTimestamp
- // ------------------------------------------------------------------------
-
- @Override
- public ITmfTimestamp normalize(final long offset, final int scale) {
- if (scale == ITmfTimestamp.NANOSECOND_SCALE) {
- return new TmfNanoTimestamp(saturatedAdd(getValue(), offset));
- }
- return super.normalize(offset, scale);
- }
-
- @Override
- public int compareTo(final ITmfTimestamp ts) {
- if (ts instanceof TmfNanoTimestamp) {
- final long delta = getValue() - ts.getValue();
- return (delta == 0) ? 0 : (delta > 0) ? 1 : -1;
- }
- return super.compareTo(ts);
- }
-
- @Override
- public ITmfTimestamp getDelta(final ITmfTimestamp ts) {
- if (ts instanceof TmfNanoTimestamp) {
- return new TmfTimestampDelta(getValue() - ts.getValue(), ITmfTimestamp.NANOSECOND_SCALE);
- }
- return super.getDelta(ts);
- }
-
/**
* @since 2.0
*/
public long toNanos() {
return getValue();
}
-
- // ------------------------------------------------------------------------
- // Object
- // ------------------------------------------------------------------------
-
- @Override
- public int hashCode() {
- return super.hashCode();
- }
-
- @Override
- public boolean equals(final Object other) {
- if (this == other) {
- return true;
- }
- if (other == null) {
- return false;
- }
- if (!(other instanceof TmfNanoTimestamp)) {
- return super.equals(other);
- }
- final TmfNanoTimestamp ts = (TmfNanoTimestamp) other;
-
- return compareTo(ts) == 0;
- }
-
}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2016 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.core.timestamp;
-
-/**
- * A timestamp with a user provided scale and value
- *
- * @author Matthew Khouzam
- * @since 2.0
- */
-public class TmfRealTimestamp extends TmfTimestamp {
-
- // ------------------------------------------------------------------------
- // Attributes
- // ------------------------------------------------------------------------
-
- /**
- * The timestamp raw value (mantissa)
- */
- private final long fValue;
-
- /**
- * The timestamp scale (magnitude)
- */
- private final int fScale;
-
- // ------------------------------------------------------------------------
- // Constructors
- // ------------------------------------------------------------------------
-
- /**
- * Full constructor
- *
- * @param value
- * the timestamp value
- * @param scale
- * the timestamp scale
- */
- public TmfRealTimestamp(final long value, final int scale) {
- fValue = value;
- fScale = scale;
- }
-
- @Override
- public long getValue() {
- return fValue;
- }
-
- @Override
- public int getScale() {
- return fScale;
- }
-}
public long getValue() {
return fValue;
}
-
- // ------------------------------------------------------------------------
- // ITmfTimestamp
- // ------------------------------------------------------------------------
-
- @Override
- public ITmfTimestamp normalize(final long offset, final int scale) {
- if (scale == ITmfTimestamp.SECOND_SCALE) {
- return TmfTimestamp.fromSeconds(saturatedAdd(getValue(), offset));
- }
- return super.normalize(offset, scale);
- }
-
- @Override
- public int compareTo(final ITmfTimestamp ts) {
- if (ts instanceof TmfSecondTimestamp) {
- final long delta = getValue() - ts.getValue();
- return (delta == 0) ? 0 : (delta > 0) ? 1 : -1;
- }
- return super.compareTo(ts);
- }
-
- @Override
- public ITmfTimestamp getDelta(final ITmfTimestamp ts) {
- if (ts instanceof TmfSecondTimestamp) {
- return new TmfTimestampDelta(getValue() - ts.getValue());
- }
- return super.getDelta(ts);
- }
-
- // ------------------------------------------------------------------------
- // Object
- // ------------------------------------------------------------------------
-
- @Override
- public int hashCode() {
- return super.hashCode();
- }
-
- @Override
- public boolean equals(final Object other) {
- if (this == other) {
- return true;
- }
- if (other == null) {
- return false;
- }
- if (!(other instanceof TmfSecondTimestamp)) {
- return super.equals(other);
- }
- final TmfSecondTimestamp ts = (TmfSecondTimestamp) other;
-
- return compareTo(ts) == 0;
- }
-
}
* @author Francois Chouinard
*/
public abstract class TmfTimestamp implements ITmfTimestamp {
+
+ /**
+ * Default implementation of the tmf timestamp. We want this to be hidden.
+ *
+ * @author Matthew Khouzam
+ *
+ */
+ private static final class Impl extends TmfTimestamp {
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ /**
+ * The timestamp raw value (mantissa)
+ */
+ private final long fValue;
+
+ /**
+ * The timestamp scale (magnitude)
+ */
+ private final int fScale;
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Full constructor
+ *
+ * @param value
+ * the timestamp value
+ * @param scale
+ * the timestamp scale
+ */
+ public Impl(final long value, final int scale) {
+ fValue = value;
+ fScale = scale;
+ }
+
+ @Override
+ public long getValue() {
+ return fValue;
+ }
+
+ @Override
+ public int getScale() {
+ return fScale;
+ }
+ }
+
/**
* Create a timestamp.
*
if (scale == ITmfTimestamp.SECOND_SCALE) {
return fromSeconds(value);
}
+ if (value == 0) {
+ return ZERO;
+ }
return createOther(value, scale);
}
}
private static @NonNull ITmfTimestamp createOther(long value, int scale) {
- return new TmfRealTimestamp(value, scale);
+ return new Impl(value, scale);
}
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
/**
- * The beginning of time
+ * Zero - a zero time constant. The value is zero, so this allows some
+ * interesting simplifications.
*/
- public static final @NonNull ITmfTimestamp BIG_BANG = new TmfRealTimestamp(Long.MIN_VALUE, Integer.MAX_VALUE);
+ public static final @NonNull ITmfTimestamp ZERO = new TmfTimestamp() {
+ @Override
+ public long getValue() {
+ return 0;
+ }
+
+ @Override
+ public int getScale() {
+ return 0;
+ }
+
+ @Override
+ public @NonNull ITmfTimestamp normalize(long offset, int scale) {
+ if (offset == 0) {
+ return this;
+ }
+ return create(offset, scale);
+ }
+
+ @Override
+ public int compareTo(ITmfTimestamp ts) {
+ return Long.compare(0, ts.getValue());
+ }
+ };
/**
- * The end of time
+ * The beginning of time will be lesser than any other timestamp
*/
- public static final @NonNull ITmfTimestamp BIG_CRUNCH = new TmfRealTimestamp(Long.MAX_VALUE, Integer.MAX_VALUE);
+ public static final @NonNull ITmfTimestamp BIG_BANG = new TmfTimestamp() {
+ @Override
+ public long getValue() {
+ return Long.MIN_VALUE;
+ }
+
+ @Override
+ public int getScale() {
+ return Integer.MAX_VALUE;
+ }
+
+ @Override
+ public int compareTo(ITmfTimestamp other) {
+ if (equals(other) == true) {
+ return 0;
+ }
+ return -1;
+ }
+
+ @Override
+ public ITmfTimestamp normalize(long offset, int scale) {
+ return this;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ return this == other;
+ }
+ };
/**
- * Zero
+ * The end of time will be greater than any other timestamp
*/
- public static final @NonNull ITmfTimestamp ZERO = new TmfRealTimestamp(0, 0);
+ public static final @NonNull ITmfTimestamp BIG_CRUNCH = new TmfTimestamp() {
+ @Override
+ public long getValue() {
+ return Long.MAX_VALUE;
+ }
+
+ @Override
+ public int getScale() {
+ return Integer.MAX_VALUE;
+ }
+
+ @Override
+ public int compareTo(ITmfTimestamp other) {
+ if (equals(other) == true) {
+ return 0;
+ }
+ return 1;
+ }
+
+ @Override
+ public ITmfTimestamp normalize(long offset, int scale) {
+ return this;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ return this == other;
+ }
+ };
// ------------------------------------------------------------------------
// ITmfTimestamp
return this;
}
- // In case of big bang and big crunch just return this (no need to
- // normalize)
- if (this.equals(BIG_BANG) || this.equals(BIG_CRUNCH)) {
- return this;
- }
-
if (value == 0) {
return create(offset, scale);
}
int scale = getScale();
// Check the corner cases (we can't use equals() because it uses
// compareTo()...)
- if (ts == null) {
+ if (BIG_BANG.equals(ts)) {
return 1;
}
- if (this == ts || (value == ts.getValue() && scale == ts.getScale())) {
- return 0;
- }
- if ((value == BIG_BANG.getValue() && scale == BIG_BANG.getScale()) || (ts.getValue() == BIG_CRUNCH.getValue() && ts.getScale() == BIG_CRUNCH.getScale())) {
+
+ if (BIG_CRUNCH.equals(ts)) {
return -1;
}
- if ((value == BIG_CRUNCH.getValue() && scale == BIG_CRUNCH.getScale()) || (ts.getValue() == BIG_BANG.getValue() && ts.getScale() == BIG_BANG.getScale())) {
- return 1;
+
+ if (this == ts || isIdentical(this, ts)) {
+ return 0;
}
- final ITmfTimestamp nts = ts.normalize(0, scale);
- if ((nts.getValue() == 0 && ts.getValue() != 0) || (ts.getValue() != Long.MAX_VALUE && nts.getValue() == Long.MAX_VALUE) || (ts.getValue() != Long.MIN_VALUE && nts.getValue() == Long.MIN_VALUE)) {
- // Scaling error. We can figure it out nonetheless.
- // First, look at the sign of the mantissa
- final long otherValue = ts.getValue();
- if (value == 0 && otherValue == 0) {
- return 0;
- }
- if (value < 0 && otherValue >= 0) {
- return -1;
- }
- if (value >= 0 && otherValue < 0) {
+ if (scale == ts.getScale()) {
+ if (ts.getValue() == Long.MIN_VALUE) {
return 1;
}
-
- // Otherwise, just compare the scales
- final int otherScale = ts.getScale();
- return (scale > otherScale) ? (otherValue >= 0) ? 1 : -1 : (otherValue >= 0) ? -1 : 1;
+ final long delta = saturatedAdd(getValue(), -ts.getValue());
+ return Long.compare(delta, 0);
+ }
+ final ITmfTimestamp largerScale = (scale > ts.getScale()) ? this : ts;
+ final ITmfTimestamp smallerScale = (scale < ts.getScale()) ? this : ts;
+
+ final ITmfTimestamp nts = largerScale.normalize(0, smallerScale.getScale());
+ if (hasSaturated(largerScale, nts)) {
+ // We've saturated largerScale.
+ if (smallerScale.getScale() == scale) {
+ return Long.compare(0, nts.getValue());
+ }
+ return Long.compare(nts.getValue(), 0);
}
- final long delta = value - nts.getValue();
- return Long.compare(delta, 0);
+ if (smallerScale.getScale() == scale) {
+ return Long.compare(value, nts.getValue());
+ }
+ return Long.compare(nts.getValue(), smallerScale.getValue());
+ }
+
+ private static boolean hasSaturated(final ITmfTimestamp ts, final ITmfTimestamp nts) {
+ return (nts.getValue() == 0 && ts.getValue() != 0) || !isIdentical(ts, nts) && ((nts.getValue() == Long.MAX_VALUE) || (nts.getValue() == Long.MIN_VALUE));
+ }
+
+ private static boolean isIdentical(final ITmfTimestamp ts, final ITmfTimestamp nts) {
+ return ts.getValue() == nts.getValue() && ts.getScale() == nts.getScale();
}
/**
}
/* We allow comparing with other types of *I*TmfTimestamp though */
final ITmfTimestamp ts = (ITmfTimestamp) other;
+ if (getScale() == ts.getScale()) {
+ return getValue() == ts.getValue();
+ }
return (compareTo(ts) == 0);
}
*
* @author Bernd Hufmann
*/
-public class TmfTimestampDelta extends TmfRealTimestamp {
+public class TmfTimestampDelta extends TmfTimestamp {
// ------------------------------------------------------------------------
// Members
// ------------------------------------------------------------------------
+ private final long fValue;
+ private final int fScale;
+
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
* Default constructor
*/
public TmfTimestampDelta() {
- super(0, ITmfTimestamp.SECOND_SCALE);
+ this(0, ITmfTimestamp.SECOND_SCALE);
}
/**
*/
public TmfTimestampDelta(long value) {
- super(value, ITmfTimestamp.SECOND_SCALE);
+ this(value, ITmfTimestamp.SECOND_SCALE);
}
/**
* the timestamp scale
*/
public TmfTimestampDelta(long value, int scale) {
- super(value, scale);
+ fValue = value;
+ fScale = scale;
}
/**
* the timestamp to copy
*/
public TmfTimestampDelta(ITmfTimestamp timestamp) {
- super(timestamp.getValue(), timestamp.getScale());
+ this(timestamp.getValue(), timestamp.getScale());
}
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
+ @Override
+ public long getValue() {
+ return fValue;
+ }
+
+ @Override
+ public int getScale() {
+ return fScale;
+ }
+
@Override
public ITmfTimestamp normalize(final long offset, final int scale) {
ITmfTimestamp nts = super.normalize(offset, scale);