ctf: Plug the unsigned utils comparator into Stream comparator.
authorEtienne Bergeron <etienne.bergeron@gmail.com>
Sun, 24 Nov 2013 05:52:17 +0000 (00:52 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 26 Nov 2013 19:43:16 +0000 (14:43 -0500)
This patch-set fixes a pending TODO found randomly.
It modifies the code to use the unsigned comparator and avoid
bugs for large timestamp values.

The comparator no longer accept null values.

Change-Id: Idee0e56edfe85ba01a27fb79d1076736fee24874
Signed-off-by: Etienne Bergeron <etienne.bergeron@gmail.com>
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/18785
Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tested-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
IP-Clean: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputReaderTimestampComparator.java

index a732315be0306c2666d7bc8be0e8957ae259cb1a..c33692c37cf368a4098859c0ee081941639063e4 100644 (file)
@@ -15,8 +15,9 @@ package org.eclipse.linuxtools.internal.ctf.core.trace;
 import java.io.Serializable;
 import java.util.Comparator;
 
+import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
 import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
-
+import org.eclipse.linuxtools.ctf.core.trace.Utils;
 
 /**
  * <b><u>StreamInputReaderTimestampComparator</u></b>
@@ -36,25 +37,19 @@ public class StreamInputReaderTimestampComparator implements
     // Operations
     // ------------------------------------------------------------------------
 
+    /**
+     * @throws NullPointerException
+     *             If any {@link StreamInputReader} parameter is null, of if any
+     *             of them does not contain a current event.
+     */
     @Override
     public int compare(StreamInputReader a, StreamInputReader b) {
-        // TODO: use unsigned comparison to avoid sign errors if needed
-        if (a.getCurrentEvent() == null) {
-            return 0;
-        }
-        if (b.getCurrentEvent() == null) {
-            return 0;
-        }
-        long ta = a.getCurrentEvent().getTimestamp();
-        long tb = b.getCurrentEvent().getTimestamp();
-
-        if (ta < tb) {
-            return -1;
-        } else if (ta > tb) {
-            return 1;
-        } else {
-            return 0;
-        }
+        EventDefinition event_a = a.getCurrentEvent();
+        EventDefinition event_b = b.getCurrentEvent();
+
+        long ta = event_a.getTimestamp();
+        long tb = event_b.getTimestamp();
+        return Utils.unsignedCompare(ta, tb);
     }
 
 }
This page took 0.027093 seconds and 5 git commands to generate.