@Override public Collection<Tree<V, E>> getTrees() { return ((Forest<V, E>) delegate).getTrees(); }
@Override public synchronized Collection<Tree<V, E>> getTrees() { return ((Forest<V, E>) delegate).getTrees(); }
public Collection<Tree<V, E>> getTrees() { return ((Forest<V,E>)delegate).getTrees(); }
public synchronized Collection<Tree<V, E>> getTrees() { return ((Forest<V,E>)delegate).getTrees(); }
/** * Returns the roots of this forest. * * @param <V> * the vertex type * @param <E> * the edge type */ public static <V, E> List<V> getRoots(Forest<V, E> forest) { List<V> roots = new ArrayList<V>(); for (Tree<V, E> tree : forest.getTrees()) { roots.add(tree.getRoot()); } return roots; }
/** * @param <V> the vertex type * @param <E> the edge type * @param forest the forest whose roots are to be returned * @return the roots of this forest. */ public static <V,E> List<V> getRoots(Forest<V,E> forest) { List<V> roots = new ArrayList<V>(); for(Tree<V,E> tree : forest.getTrees()) { roots.add(tree.getRoot()); } return roots; }
/** * Returns a list of all the roots - the entry which is at the start of each chain or branch. For the tree to be a * tree, there should only be one of these * * @return */ public List<V> getRoots() { Collection<Tree<V, Integer>> t = graph.getTrees(); List<V> branchRoots = new ArrayList<V>(); for (Tree<V, Integer> branch : t) { branchRoots.add(branch.getRoot()); } return branchRoots; }
/** * Returns a list of all the roots - the entry which is at the start of each chain or branch. For the tree to be a * tree, there should only be one of these * * @return */ public List<V> getRoots() { Collection<Tree<V, Integer>> t = graph.getTrees(); List<V> branchRoots = new ArrayList<V>(); for (Tree<V, Integer> branch : t) { branchRoots.add(branch.getRoot()); } return branchRoots; }
/** * Returns the subtree of <code>tree</code> which is rooted at <code>root</code> as a <code>Forest</code>. * The tree returned is an independent entity, although it uses the same vertex and edge objects. * @param <V> the vertex type * @param <E> the edge type * @param forest the tree whose subtree is to be extracted * @param root the root of the subtree to be extracted * @return the subtree of <code>tree</code> which is rooted at <code>root</code> * @throws InstantiationException if a new tree of the same type cannot be created * @throws IllegalAccessException if a new tree of the same type cannot be created */ @SuppressWarnings("unchecked") public static <V,E> Tree<V,E> getSubTree(Forest<V,E> forest, V root) throws InstantiationException, IllegalAccessException { if (!forest.containsVertex(root)) throw new IllegalArgumentException("Specified tree does not contain the specified root as a vertex"); Forest<V,E> subforest = forest.getClass().newInstance(); subforest.addVertex(root); growSubTree(forest, subforest, root); return subforest.getTrees().iterator().next(); }
/** * Connects <code>subTree</code> to <code>tree</code> by attaching it as a child * of <code>node</code> with edge <code>connectingEdge</code>. * @param <V> the vertex type * @param <E> the edge type * @param tree the tree to which <code>subTree</code> is to be added * @param subTree the tree which is to be grafted on to <code>tree</code> * @param node the parent of <code>subTree</code> in its new position in <code>tree</code> * @param connectingEdge the edge used to connect <code>subtree</code>'s root as a child of <code>node</code> */ public static <V,E> void addSubTree(Forest<V,E> tree, Forest<V,E> subTree, V node, E connectingEdge) { if (node != null && !tree.containsVertex(node)) throw new IllegalArgumentException("Specified tree does not contain the specified node as a vertex"); V root = subTree.getTrees().iterator().next().getRoot(); addFromSubTree(tree, subTree, connectingEdge, node, root); }
/** * Connects <code>subTree</code> to <code>tree</code> by attaching it as a * child of <code>node</code> with edge <code>connectingEdge</code>. * * @param <V> * the vertex type * @param <E> * the edge type * @param tree * the tree to which <code>subTree</code> is to be added * @param subTree * the tree which is to be grafted on to <code>tree</code> * @param node * the parent of <code>subTree</code> in its new position in * <code>tree</code> * @param connectingEdge * the edge used to connect <code>subtree</code>'s root as a * child of <code>node</code> */ public static <V, E> void addSubTree(Forest<V, E> tree, Forest<V, E> subTree, V node, E connectingEdge) { if (node != null && !tree.containsVertex(node)) { throw new IllegalArgumentException( "Specified tree does not contain the specified node as a vertex"); } V root = subTree.getTrees().iterator().next().getRoot(); addFromSubTree(tree, subTree, connectingEdge, node, root); }
/** * Returns the subtree of <code>tree</code> which is rooted at * <code>root</code> as a <code>Forest<V,E></code>. The tree returned is an * independent entity, although it uses the same vertex and edge objects. * * @param <V> * the vertex type * @param <E> * the edge type * @param forest * the tree whose subtree is to be extracted * @param root * the root of the subtree to be extracted * @return the subtree of <code>tree</code> which is rooted at * <code>root</code> * @throws InstantiationException * if a new tree of the same type cannot be created * @throws IllegalAccessException */ public static <V, E> Tree<V, E> getSubTree(Forest<V, E> forest, V root) { if (!forest.containsVertex(root)) { throw new IllegalArgumentException( "Specified tree does not contain the specified root as a vertex"); } Forest<V, E> subforest = (Forest<V, E>) forest.newInstance(); subforest.addVertex(root); growSubTree(forest, subforest, root); return subforest.getTrees().iterator().next(); }