analysis.graph: Fix getHead() to return the earliest vertex
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Thu, 11 Feb 2016 17:39:24 +0000 (12:39 -0500)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Fri, 12 Feb 2016 22:24:30 +0000 (17:24 -0500)
Instead of returning the first vertex of the first element, make sure it
returns the earliest vertex.

Change-Id: I4c29fa02f97128ca80e8510560c8ae5512f3d72c
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/66418
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
analysis/org.eclipse.tracecompass.analysis.graph.core.tests/src/org/eclipse/tracecompass/analysis/graph/core/tests/graph/TmfGraphTest.java
analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/base/TmfGraph.java

index 9480d7c2c7e03f15a442e139d306eb86b09929f4..8d7c0e62f5062a714a3a5b103c0cb6341fdb1024 100644 (file)
@@ -238,6 +238,7 @@ public class TmfGraphTest {
      */
     @Test
     public void testHead() {
+        assertNull(fGraph.getHead());
         fGraph.append(WORKER1, fV0);
         fGraph.append(WORKER1, fV1);
         assertEquals(fV0, fGraph.getHead());
@@ -246,6 +247,20 @@ public class TmfGraphTest {
         assertEquals(fV0, fGraph.getHead(fV0));
     }
 
+    /**
+     * Test the {@link TmfGraph#getHead()} methods with 2 workers
+     */
+    @Test
+    public void testHead2() {
+        fGraph.append(WORKER1, fV1);
+        fGraph.append(WORKER2, fV0);
+        assertEquals(fV0, fGraph.getHead());
+        assertEquals(fV1, fGraph.getHead(WORKER1));
+        assertEquals(fV0, fGraph.getHead(WORKER2));
+        assertEquals(fV1, fGraph.getHead(fV1));
+        assertEquals(fV0, fGraph.getHead(fV0));
+    }
+
     /**
      * The test {@link TmfGraph#getParentOf(TmfVertex)} method
      */
index 561e0c5fd80f76aab183446112ffe7d699737154..1e0ec7cd88ccf416f9585922026d59df2a5ea4a8 100644 (file)
@@ -218,7 +218,8 @@ public class TmfGraph {
     }
 
     /**
-     * Returns the head node of the first object of the nodeMap
+     * Returns the head node of the object of the nodeMap that has the earliest
+     * head vertex time
      *
      * @return The head vertex
      */
@@ -226,7 +227,12 @@ public class TmfGraph {
         if (fNodeMap.isEmpty()) {
             return null;
         }
-        return getHead(NonNullUtils.checkNotNull(fNodeMap.keySet().iterator().next()));
+        IGraphWorker headWorker = fNodeMap.keySet().stream()
+                .filter(k -> !fNodeMap.get(k).isEmpty())
+                .sorted((k1, k2) -> fNodeMap.get(k1).get(0).compareTo(fNodeMap.get(k2).get(0)))
+                .findFirst()
+                .get();
+        return getHead(headWorker);
     }
 
     /**
This page took 0.027751 seconds and 5 git commands to generate.