@Test public void testConcatenate() { 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> dag1 = new Dag<>(dagNodeList); DagNode<String> dagNode6 = new DagNode<>("val6"); DagNode<String> dagNode7 = new DagNode<>("val7"); DagNode<String> dagNode8 = new DagNode<>("val8"); dagNode8.addParentNode(dagNode6); dagNode8.addParentNode(dagNode7); Dag<String> dag2 = new Dag<>(Lists.newArrayList(dagNode6, dagNode7, dagNode8)); Dag<String> dagNew = dag1.concatenate(dag2); for (DagNode<String> dagNode : Lists.newArrayList(dagNode6, dagNode7)) { Assert.assertEquals(dagNew.getParents(dagNode).size(), 2); Set<String> set = new HashSet<>(); set.add(dagNew.getParents(dagNode).get(0).getValue()); set.add(dagNew.getParents(dagNode).get(1).getValue()); Assert.assertTrue(set.contains("val4")); Assert.assertTrue(set.contains("val5")); } for (DagNode<String> dagNode : Lists.newArrayList(dagNode4, dagNode5)) { Assert.assertEquals(dagNew.getChildren(dagNode).size(), 2); Set<String> set = new HashSet<>(); set.add(dagNew.getChildren(dagNode).get(0).getValue()); set.add(dagNew.getChildren(dagNode).get(1).getValue()); Assert.assertTrue(set.contains("val6")); Assert.assertTrue(set.contains("val7")); } for (DagNode<String> dagNode : Lists.newArrayList(dagNode6, dagNode7)) { List<DagNode<String>> nextNodes = dagNew.getChildren(dagNode); Assert.assertEquals(nextNodes.size(), 1); Assert.assertEquals(nextNodes.get(0).getValue(), "val8"); } Assert.assertEquals(dagNew.getStartNodes().size(), 1); Assert.assertEquals(dagNew.getStartNodes().get(0).getValue(), "val1"); Assert.assertEquals(dagNew.getEndNodes().size(), 1); Assert.assertEquals(dagNew.getEndNodes().get(0).getValue(), "val8"); }
public Dag<T> concatenate(Dag<T> other) { return concatenate(other, new HashSet<>()); }
Dag { public Dag<T> concatenate(Dag<T> other) { return concatenate(other, new HashSet<>()); } }
Dag { public Dag<T> concatenate(Dag<T> other) { return concatenate(other, new HashSet<>()); } Dag(List<DagNode<T>> dagNodes); }
Dag { public Dag<T> concatenate(Dag<T> other) { return concatenate(other, new HashSet<>()); } 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 Dag<T> concatenate(Dag<T> other) { return concatenate(other, new HashSet<>()); } 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();  }