@Test public void testInitialize() { DagNode<String> dagNode1 = new DagNode<>("val1"); DagNode<String> dagNode2 = new DagNode<>("val2"); DagNode<String> dagNode3 = new DagNode<>("val3"); DagNode<String> dagNode4 = new DagNode<>("val4"); DagNode<String> dagNode5 = new DagNode<>("val5"); dagNode2.addParentNode(dagNode1); dagNode3.addParentNode(dagNode1); dagNode4.addParentNode(dagNode2); dagNode4.addParentNode(dagNode3); dagNode5.addParentNode(dagNode3); List<DagNode<String>> dagNodeList = Lists.newArrayList(dagNode1, dagNode2, dagNode3, dagNode4, dagNode5); Dag<String> dag = new Dag<>(dagNodeList); Assert.assertEquals(dag.getStartNodes().size(), 1); Assert.assertEquals(dag.getStartNodes().get(0).getValue(), "val1"); Assert.assertEquals(dag.getEndNodes().size(), 2); Assert.assertEquals(dag.getEndNodes().get(0).getValue(), "val4"); Assert.assertEquals(dag.getEndNodes().get(1).getValue(), "val5"); DagNode startNode = dag.getStartNodes().get(0); Assert.assertEquals(dag.getChildren(startNode).size(), 2); Set<String> childSet = new HashSet<>(); for (DagNode<String> node: dag.getChildren(startNode)) { childSet.add(node.getValue()); } Assert.assertTrue(childSet.contains("val2")); Assert.assertTrue(childSet.contains("val3")); dagNode2 = dag.getChildren(startNode).get(0); dagNode3 = dag.getChildren(startNode).get(1); Assert.assertEquals(dag.getChildren(dagNode2).size(), 1); Assert.assertEquals(dag.getChildren(dagNode2).get(0).getValue(), "val4"); for (DagNode<String> node: dag.getChildren(dagNode3)) { childSet.add(node.getValue()); } Assert.assertTrue(childSet.contains("val4")); Assert.assertTrue(childSet.contains("val5")); Assert.assertEquals(dag.getChildren(dagNode4).size(), 0); Assert.assertEquals(dag.getChildren(dagNode5).size(), 0); }
public List<DagNode<T>> getChildren(DagNode node) { return parentChildMap.getOrDefault(node, Collections.EMPTY_LIST); }
Dag { public List<DagNode<T>> getChildren(DagNode node) { return parentChildMap.getOrDefault(node, Collections.EMPTY_LIST); } }
Dag { public List<DagNode<T>> getChildren(DagNode node) { return parentChildMap.getOrDefault(node, Collections.EMPTY_LIST); } Dag(List<DagNode<T>> dagNodes); }
Dag { public List<DagNode<T>> getChildren(DagNode node) { return parentChildMap.getOrDefault(node, Collections.EMPTY_LIST); } Dag(List<DagNode<T>> dagNodes); List<DagNode<T>> getChildren(DagNode node); List<DagNode<T>> getParents(DagNode node); Set<DagNode<T>> getDependencyNodes(Set<DagNode<T>> forkNodes); boolean isEmpty(); Dag<T> concatenate(Dag<T> other); Dag<T> concatenate(Dag<T> other, Set<DagNode<T>> forkNodes); Dag<T> merge(Dag<T> other); @Override String toString(); }
Dag { public List<DagNode<T>> getChildren(DagNode node) { return parentChildMap.getOrDefault(node, Collections.EMPTY_LIST); } Dag(List<DagNode<T>> dagNodes); List<DagNode<T>> getChildren(DagNode node); List<DagNode<T>> getParents(DagNode node); Set<DagNode<T>> getDependencyNodes(Set<DagNode<T>> forkNodes); boolean isEmpty(); Dag<T> concatenate(Dag<T> other); Dag<T> concatenate(Dag<T> other, Set<DagNode<T>> forkNodes); Dag<T> merge(Dag<T> other); @Override String toString();  }