Package edu.uci.ics.jung.graph.util
Class TreeUtils
- java.lang.Object
-
- edu.uci.ics.jung.graph.util.TreeUtils
-
public class TreeUtils extends java.lang.Object
Contains static methods for operating on instances ofTree
.
-
-
Constructor Summary
Constructors Constructor Description TreeUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <V,E>
voidaddFromSubTree(Forest<V,E> tree, Forest<V,E> subTree, E edge, V parent, V root)
Adds the trees insource
todestination
.static <V,E>
voidaddSubTree(Forest<V,E> tree, Forest<V,E> subTree, V node, E connectingEdge)
ConnectssubTree
totree
by attaching it as a child ofnode
with edgeconnectingEdge
.static <V,E>
java.util.List<V>getRoots(Forest<V,E> forest)
Returns the roots of this forest.static <V,E>
Tree<V,E>getSubTree(Forest<V,E> forest, V root)
Returns the subtree oftree
which is rooted atroot
as aForest
.static <V,E>
voidgrowSubTree(Forest<V,E> tree, Forest<V,E> subTree, V root)
Populatessubtree
with the subtree oftree
which is rooted atroot
.
-
-
-
Method Detail
-
getRoots
public static <V,E> java.util.List<V> getRoots(Forest<V,E> forest)
Returns the roots of this forest.- Type Parameters:
V
- the vertex typeE
- the edge type
-
getSubTree
public static <V,E> Tree<V,E> getSubTree(Forest<V,E> forest, V root) throws java.lang.InstantiationException, java.lang.IllegalAccessException
Returns the subtree oftree
which is rooted atroot
as aForest
. The tree returned is an independent entity, although it uses the same vertex and edge objects.- Type Parameters:
V
- the vertex typeE
- the edge type- Parameters:
forest
- the tree whose subtree is to be extractedroot
- the root of the subtree to be extracted- Returns:
- the subtree of
tree
which is rooted atroot
- Throws:
java.lang.InstantiationException
- if a new tree of the same type cannot be createdjava.lang.IllegalAccessException
-
growSubTree
public static <V,E> void growSubTree(Forest<V,E> tree, Forest<V,E> subTree, V root)
Populatessubtree
with the subtree oftree
which is rooted atroot
.- Type Parameters:
V
- the vertex typeE
- the edge type- Parameters:
tree
- the tree whose subtree is to be extractedsubTree
- the tree instance which is to be populated with the subtree oftree
root
- the root of the subtree to be extracted
-
addSubTree
public static <V,E> void addSubTree(Forest<V,E> tree, Forest<V,E> subTree, V node, E connectingEdge)
ConnectssubTree
totree
by attaching it as a child ofnode
with edgeconnectingEdge
.- Type Parameters:
V
- the vertex typeE
- the edge type- Parameters:
tree
- the tree to whichsubTree
is to be addedsubTree
- the tree which is to be grafted on totree
node
- the parent ofsubTree
in its new position intree
connectingEdge
- the edge used to connectsubtree
's root as a child ofnode
-
addFromSubTree
public static <V,E> void addFromSubTree(Forest<V,E> tree, Forest<V,E> subTree, E edge, V parent, V root)
Adds the trees insource
todestination
.source
is left unchanged. The vertex and edge objects insource
will also be used indestination
, in the same (structural) roles.- Type Parameters:
V
- the vertex typeE
- the edge type- Parameters:
destination
- the forest to which the trees insource
will be addedsource
- the forest whose trees will be added todestination
FIXME also note that this is redundant with DelegateForest.addTree()
-
-