TaskTree { public long getRootTaskId() { for (TaskRelation rel : map.values()) { if (!rel.getParentId().isPresent()) { return rel.getId(); } } throw new IllegalStateException("Root task doesn't exist in an attempt: "+map.values()); } TaskTree(List<TaskRelation> rels); long getRootTaskId(); List<Long> getRecursiveParentIdListFromRoot(long id); List<Long> getRecursiveParentsUpstreamChildrenIdListFromFar(long id); T walkChildrenRecursively(long id, T value, Walker<T> walker); List<Long> getRecursiveChildrenIdList(long id);  }
@Test public void testRootId() throws Exception { assertThat( tree.getRootTaskId(), is(1L)); }