aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernd Hufmann2012-11-30 10:51:11 (EST)
committerBernd Hufmann2012-11-30 13:55:28 (EST)
commit15d0249714b54fed528bbb6f539e5b234c523824 (patch)
treec2e21bb2171b66663b849abc2a0e4d2ea08436ab
parent75128abc752815183062693e4d595fc480c64e0c (diff)
downloadorg.eclipse.linuxtools-15d0249714b54fed528bbb6f539e5b234c523824.zip
org.eclipse.linuxtools-15d0249714b54fed528bbb6f539e5b234c523824.tar.gz
org.eclipse.linuxtools-15d0249714b54fed528bbb6f539e5b234c523824.tar.bz2
Implement TmfTimestampDelta for deltas of timestampsrefs/changes/44/8944/4
The toString() method of this class returns the timestamp string formatted with TmfTimestampFormat.DefaultIntervalFormat() and also considers negative values correctly. The getDelta() method of TmfTimestamp and TmfSimpleTimestamp returns now an instance of TmfTimestampDelta. This also fixes the incorrect display of timestamps deltas in the Sequence Diagram view. Change-Id: I249ab9ac7a5f4170f86f038bc89d419dcce9514a Reviewed-on: https://git.eclipse.org/r/8944 Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com> IP-Clean: Patrick Tasse <patrick.tasse@gmail.com> Tested-by: Hudson CI
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/AllTests.java1
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampDeltaTest.java160
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfSimpleTimestamp.java2
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestamp.java2
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestampDelta.java115
-rwxr-xr-xlttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/uml2sd/SDWidget.java12
6 files changed, 279 insertions, 13 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/AllTests.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/AllTests.java
index 6e10a92..575cf68 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/AllTests.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/AllTests.java
@@ -32,6 +32,7 @@ public class AllTests {
//$JUnit-BEGIN$
suite.addTestSuite(TmfTimestampTest.class);
suite.addTestSuite(TmfSimpleTimestampTest.class);
+ suite.addTestSuite(TmfTimestampDeltaTest.class);
suite.addTestSuite(TmfTimeRangeTest.class);
suite.addTestSuite(TmfEventFieldTest.class);
suite.addTestSuite(TmfEventTypeTest.class);
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampDeltaTest.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampDeltaTest.java
new file mode 100644
index 0000000..4b74bb3
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampDeltaTest.java
@@ -0,0 +1,160 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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
+ *
+ * Contributors:
+ * Bernd Hufmann - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.event;
+
+import junit.framework.TestCase;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestampDelta;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimestampFormat;
+
+/**
+ * Test suite for the TmfTimestampDelta class.
+ */
+@SuppressWarnings("nls")
+public class TmfTimestampDeltaTest extends TestCase {
+
+ // ------------------------------------------------------------------------
+ // Variables
+ // ------------------------------------------------------------------------
+
+ private final ITmfTimestamp ts0 = new TmfTimestampDelta();
+ private final ITmfTimestamp ts1 = new TmfTimestampDelta(12345, 0);
+ private final ITmfTimestamp ts2 = new TmfTimestampDelta(12345, -1);
+ private final ITmfTimestamp ts3 = new TmfTimestampDelta(12345, 2, 5);
+ private final ITmfTimestamp ts4 = new TmfTimestampDelta(-12345, -5);
+
+ // ------------------------------------------------------------------------
+ // Housekeping
+ // ------------------------------------------------------------------------
+
+ /**
+ * @param name the test name
+ */
+ public TmfTimestampDeltaTest(final String name) {
+ super(name);
+ }
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ *
+ */
+ public void testDefaultConstructor() {
+ assertEquals("getValue", 0, ts0.getValue());
+ assertEquals("getscale", 0, ts0.getScale());
+ assertEquals("getPrecision", 0, ts0.getPrecision());
+ }
+
+ /**
+ *
+ */
+ public void testValueConstructor() {
+ assertEquals("getValue", 12345, ts1.getValue());
+ assertEquals("getscale", 0, ts1.getScale());
+ assertEquals("getPrecision", 0, ts1.getPrecision());
+ }
+
+ /**
+ *
+ */
+ public void testValueScaleConstructor() {
+ assertEquals("getValue", 12345, ts2.getValue());
+ assertEquals("getscale", -1, ts2.getScale());
+ assertEquals("getPrecision", 0, ts2.getPrecision());
+ }
+
+ /**
+ *
+ */
+ public void testFullConstructor() {
+ assertEquals("getValue", 12345, ts3.getValue());
+ assertEquals("getscale", 2, ts3.getScale());
+ assertEquals("getPrecision", 5, ts3.getPrecision());
+
+ assertEquals("getValue", -12345, ts4.getValue());
+ assertEquals("getscale", -5, ts4.getScale());
+ assertEquals("getPrecision", 0, ts4.getPrecision());
+ }
+
+ /**
+ *
+ */
+ public void testCopyConstructor() {
+ final ITmfTimestamp ts = new TmfTimestamp(12345, 2, 5);
+ final ITmfTimestamp copy = new TmfTimestamp(ts);
+
+ assertEquals("getValue", ts.getValue(), copy.getValue());
+ assertEquals("getscale", ts.getScale(), copy.getScale());
+ assertEquals("getPrecision", ts.getPrecision(), copy.getPrecision());
+
+ assertEquals("getValue", 12345, copy.getValue());
+ assertEquals("getscale", 2, copy.getScale());
+ assertEquals("getPrecision", 5, copy.getPrecision());
+ }
+
+ /**
+ *
+ */
+ public void testCopyNullConstructor() {
+ try {
+ new TmfTimestamp(null);
+ fail("TmfIntervalTimestamp: null argument");
+ } catch (final IllegalArgumentException e) {
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // normalize
+ // ------------------------------------------------------------------------
+ /**
+ *
+ */
+ public void testNormalizeOffset() {
+ ITmfTimestamp ts = ts0.normalize(12345, 0);
+ assertTrue("instance", ts instanceof TmfTimestampDelta);
+ assertEquals("getValue", 12345, ts.getValue());
+ assertEquals("getscale", 0, ts.getScale());
+ assertEquals("getPrecision", 0, ts.getPrecision());
+ }
+
+ // ------------------------------------------------------------------------
+ // toString
+ // ------------------------------------------------------------------------
+
+ /**
+ *
+ */
+ public void testToStringDefault() {
+ assertEquals("toString", "000.000 000 000", ts0.toString());
+ assertEquals("toString", "12345.000 000 000", ts1.toString());
+ assertEquals("toString", "1234.500 000 000", ts2.toString());
+ assertEquals("toString", "1234500.000 000 000", ts3.toString());
+ assertEquals("toString", "-000.123 450 000", ts4.toString());
+ }
+
+ /**
+ *
+ */
+ public void testToStringFormat() {
+ TmfTimestampFormat format = new TmfTimestampFormat("HH:mm:ss.SSS CCC NNN");
+ assertEquals("toString", "00:00:00.000 000 000", ts0.toString(format));
+ assertEquals("toString", "03:25:45.000 000 000", ts1.toString(format));
+ assertEquals("toString", "00:20:34.500 000 000", ts2.toString(format));
+ assertEquals("toString", "06:55:00.000 000 000", ts3.toString(format));
+ assertEquals("toString", "-00:00:00.123 450 000", ts4.toString(format));
+ }
+}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfSimpleTimestamp.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfSimpleTimestamp.java
index dc23ce6..1f25f66 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfSimpleTimestamp.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfSimpleTimestamp.java
@@ -87,7 +87,7 @@ public class TmfSimpleTimestamp extends TmfTimestamp {
@Override
public ITmfTimestamp getDelta(final ITmfTimestamp ts) {
if (ts instanceof TmfSimpleTimestamp) {
- return new TmfSimpleTimestamp(getValue() - ts.getValue());
+ return new TmfTimestampDelta(getValue() - ts.getValue());
}
return super.getDelta(ts);
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestamp.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestamp.java
index ca05759..299caa5 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestamp.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestamp.java
@@ -287,7 +287,7 @@ public class TmfTimestamp implements ITmfTimestamp {
public ITmfTimestamp getDelta(final ITmfTimestamp ts) {
final ITmfTimestamp nts = ts.normalize(0, fScale);
final long value = fValue - nts.getValue();
- return new TmfTimestamp(value, fScale, fPrecision + nts.getPrecision());
+ return new TmfTimestampDelta(value, fScale, fPrecision + nts.getPrecision());
}
// ------------------------------------------------------------------------
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestampDelta.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestampDelta.java
new file mode 100644
index 0000000..03e31fe
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestampDelta.java
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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
+ *
+ * Contributors:
+ * Bernd Hufmann - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.tmf.core.event;
+
+import java.util.TimeZone;
+
+/**
+ * A generic timestamp implementation for delta between timestamps.
+ * The toString() method takes negative values into consideration.
+ *
+ * @author Bernd Hufmann
+ * @since 2.0
+ */
+public class TmfTimestampDelta extends TmfTimestamp {
+
+ // ------------------------------------------------------------------------
+ // Members
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+ /**
+ * Default constructor
+ */
+ public TmfTimestampDelta() {
+ super();
+ }
+
+ /**
+ * Simple constructor (scale = precision = 0)
+ *
+ * @param value the timestamp value
+ */
+
+ public TmfTimestampDelta(long value) {
+ super(value);
+ }
+
+ /**
+ * Simple constructor (precision = 0)
+ *
+ * @param value the timestamp value
+ * @param scale the timestamp scale
+ */
+ public TmfTimestampDelta(long value, int scale) {
+ super(value, scale);
+ }
+
+
+ /**
+ * Copy constructor
+ *
+ * @param timestamp the timestamp to copy
+ */
+ public TmfTimestampDelta(ITmfTimestamp timestamp) {
+ super(timestamp);
+ }
+
+ /**
+ * Full constructor
+ *
+ * @param value the timestamp value
+ * @param scale the timestamp scale
+ * @param precision the timestamp precision
+ */
+ public TmfTimestampDelta(long value, int scale, int precision) {
+ super(value, scale, precision);
+ }
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp#normalize(long, int)
+ */
+ @Override
+ public ITmfTimestamp normalize(final long offset, final int scale) {
+ ITmfTimestamp nts = super.normalize(offset, scale);
+ return new TmfTimestampDelta(nts.getValue(), nts.getScale(), nts.getPrecision());
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return toString(TmfTimestampFormat.getDefaulIntervalFormat());
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#toString(org.eclipse.linuxtools.tmf.core.event.TmfTimestampFormat)
+ */
+ @Override
+ public String toString(TmfTimestampFormat format) {
+ if (getValue() < 0) {
+ TmfTimestampDelta tmpTs = new TmfTimestampDelta(-getValue(), getScale(), getPrecision());
+ return "-" + tmpTs.toString(format); //$NON-NLS-1$
+ }
+ TmfTimestampFormat deltaFormat = new TmfTimestampFormat(format.toPattern());
+ deltaFormat.setTimeZone(TimeZone.getTimeZone("UTC")); //$NON-NLS-1$
+ return super.toString(deltaFormat);
+ }
+}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/uml2sd/SDWidget.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/uml2sd/SDWidget.java
index 19d1a0c..0f42b86 100755
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/uml2sd/SDWidget.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/uml2sd/SDWidget.java
@@ -27,7 +27,6 @@ import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;
import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicExecutionOccurrence;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Frame;
@@ -1193,7 +1192,6 @@ public class SDWidget extends ScrollView implements SelectionListener,
*/
protected String getPostfixForTooltip(boolean accessible) {
StringBuffer postfix = new StringBuffer();
-// String postfix = "";//$NON-NLS-1$
// Determine if the tooltip must show the time difference between the current mouse position and
// the last selected graphNode
if ((fCurrentGraphNode != null) &&
@@ -1208,19 +1206,15 @@ public class SDWidget extends ScrollView implements SelectionListener,
postfix.append(SDMessages._138);
postfix.append(" "); //$NON-NLS-1$
-// postfix = " -> " + fCurrentGraphNode.getName() + "\n" + SDMessages._138 + " "; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
//double delta = ((ITimeRange)toolTipNode).getLastTime()-((ITimeRange)currentGraphNode).getLastTime();
ITmfTimestamp firstTime = ((ITimeRange) fCurrentGraphNode).getEndTime();
ITmfTimestamp lastTime = ((ITimeRange) fToolTipNode).getEndTime();
- TmfTimestamp delta = (TmfTimestamp) lastTime.getDelta(firstTime);
+ ITmfTimestamp delta = lastTime.getDelta(firstTime);
postfix.append(delta.toString());
-// postfix += delta.toString();
} else {
if ((fToolTipNode instanceof ITimeRange) && ((ITimeRange) fToolTipNode).hasTimeInfo()) {
postfix.append("\n"); //$NON-NLS-1$
-// postfix = "\n";//$NON-NLS-1$
ITmfTimestamp firstTime = ((ITimeRange) fToolTipNode).getStartTime();
ITmfTimestamp lastTime = ((ITimeRange) fToolTipNode).getEndTime();
@@ -1232,16 +1226,12 @@ public class SDWidget extends ScrollView implements SelectionListener,
postfix.append("end: "); //$NON-NLS-1$
postfix.append(lastTime.toString());
postfix.append("\n"); //$NON-NLS-1$
-// postfix += "start: " + firstTime + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
-// postfix += "end: " + lastTime + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
} else {
postfix.append(firstTime.toString());
-// postfix += firstTime.toString();
}
}
else if (lastTime != null) {
postfix.append(lastTime.toString());
-// postfix += lastTime.toString();
}
}
}