@Test public void testSubTree() { MutableCTreeNetwork<String, Integer> tree = TreeNetworkBuilder.builder().expectedNodeCount(7).build(); tree.addNode("root"); tree.addEdge("root", "child1", 1); tree.addEdge("root", "child2", 2); tree.addEdge("child1", "grandchild11", 11); tree.addEdge("child1", "grandchild12", 12); tree.addEdge("child2", "grandchild21", 21); tree.addEdge("child2", "grandchild22", 22); MutableCTreeNetwork<String, Integer> subTree = TreeUtils.getSubTree(tree, "root"); assertEquals(tree.asGraph(), subTree.asGraph()); MutableCTreeNetwork<String, Integer> childOneSubTree = TreeUtils.getSubTree(tree, "child1"); MutableCTreeNetwork<String, Integer> expectedSubTree = TreeNetworkBuilder.builder().expectedNodeCount(3).build(); expectedSubTree.addNode("child1"); expectedSubTree.addEdge("child1", "grandchild11", 11); expectedSubTree.addEdge("child1", "grandchild12", 12); assertEquals(childOneSubTree.asGraph(), expectedSubTree.asGraph()); }
public static <N, E> MutableCTreeNetwork<N, E> getSubTree(CTreeNetwork<N, E> tree, N root) { checkNotNull(tree, "tree"); checkNotNull(root, "root"); checkArgument( tree.nodes().contains(root), "Input tree does not contain the input subtree root"); MutableCTreeNetwork<N, E> subtree = TreeNetworkBuilder.from(tree).withRoot(root).build(); growSubTree(tree, subtree, root); return subtree; }
TreeUtils { public static <N, E> MutableCTreeNetwork<N, E> getSubTree(CTreeNetwork<N, E> tree, N root) { checkNotNull(tree, "tree"); checkNotNull(root, "root"); checkArgument( tree.nodes().contains(root), "Input tree does not contain the input subtree root"); MutableCTreeNetwork<N, E> subtree = TreeNetworkBuilder.from(tree).withRoot(root).build(); growSubTree(tree, subtree, root); return subtree; } }
TreeUtils { public static <N, E> MutableCTreeNetwork<N, E> getSubTree(CTreeNetwork<N, E> tree, N root) { checkNotNull(tree, "tree"); checkNotNull(root, "root"); checkArgument( tree.nodes().contains(root), "Input tree does not contain the input subtree root"); MutableCTreeNetwork<N, E> subtree = TreeNetworkBuilder.from(tree).withRoot(root).build(); growSubTree(tree, subtree, root); return subtree; }  }
TreeUtils { public static <N, E> MutableCTreeNetwork<N, E> getSubTree(CTreeNetwork<N, E> tree, N root) { checkNotNull(tree, "tree"); checkNotNull(root, "root"); checkArgument( tree.nodes().contains(root), "Input tree does not contain the input subtree root"); MutableCTreeNetwork<N, E> subtree = TreeNetworkBuilder.from(tree).withRoot(root).build(); growSubTree(tree, subtree, root); return subtree; }  static ImmutableSet<N> roots(Graph<N> graph); static boolean isForestShaped(Graph<N> graph); static boolean isForestShaped(Network<N, ?> graph); static MutableCTreeNetwork<N, E> getSubTree(CTreeNetwork<N, E> tree, N root); static void growSubTree(
      CTreeNetwork<N, E> tree, MutableCTreeNetwork<N, E> subTree, N root); static void addSubTree(
      MutableCTreeNetwork<N, E> tree,
      CTreeNetwork<N, E> subTree,
      N subTreeParent,
      E connectingEdge); }
TreeUtils { public static <N, E> MutableCTreeNetwork<N, E> getSubTree(CTreeNetwork<N, E> tree, N root) { checkNotNull(tree, "tree"); checkNotNull(root, "root"); checkArgument( tree.nodes().contains(root), "Input tree does not contain the input subtree root"); MutableCTreeNetwork<N, E> subtree = TreeNetworkBuilder.from(tree).withRoot(root).build(); growSubTree(tree, subtree, root); return subtree; }  static ImmutableSet<N> roots(Graph<N> graph); static boolean isForestShaped(Graph<N> graph); static boolean isForestShaped(Network<N, ?> graph); static MutableCTreeNetwork<N, E> getSubTree(CTreeNetwork<N, E> tree, N root); static void growSubTree(
      CTreeNetwork<N, E> tree, MutableCTreeNetwork<N, E> subTree, N root); static void addSubTree(
      MutableCTreeNetwork<N, E> tree,
      CTreeNetwork<N, E> subTree,
      N subTreeParent,
      E connectingEdge);  }