*/
@Test
public void testHead() {
+ assertNull(fGraph.getHead());
fGraph.append(WORKER1, fV0);
fGraph.append(WORKER1, fV1);
assertEquals(fV0, fGraph.getHead());
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
*/
}
/**
- * 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
*/
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);
}
/**