Class DelegateTree<V,E>
java.lang.Object
edu.uci.ics.jung.graph.GraphDecorator<V,E>
edu.uci.ics.jung.graph.DelegateTree<V,E>
- Type Parameters:
V- the vertex typeE- the edge type
- All Implemented Interfaces:
DirectedGraph<V,E>, Forest<V, E>, Graph<V, E>, Hypergraph<V, E>, Tree<V, E>, Serializable
An implementation of
Tree that delegates to
a specified instance of DirectedGraph.- See Also:
-
Field Summary
FieldsFields inherited from class GraphDecorator
delegate -
Constructor Summary
ConstructorsConstructorDescriptionCreates an instance.DelegateTree(com.google.common.base.Supplier<DirectedGraph<V, E>> graphFactory) create an instance with passed values.DelegateTree(DirectedGraph<V, E> graph) Creates a newDelegateTreewhich delegates tograph. -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd the passed child node as a child of parent.booleanadd the passed child node as a child of parent.booleanaddEdge(E edge, Collection<? extends V> vertices) Addsedgeto this graph.booleanAdd an edge to the tree, connecting v1, the parent and v2, the child.booleanAdd an edge to the tree, connecting v1, the parent and v2, the child.booleanWill set the root of the Tree, only if the Tree is empty and the root is currently unset.intgetChildCount(V parent) get the number of children of the passed parent nodegetChildEdges(V vertex) Returns the edges connectingvertexto its children in this tree.getChildren(V parent) get the immediate children nodes of the passed parentintcomputes and returns the depth of the tree from the root to the passed vertexstatic final <V,E> com.google.common.base.Supplier <Tree<V, E>> intComputes and returns the height of the tree.intgetIncidentCount(E edge) Returns the number of vertices that are incident toedge.get the single parent node of the passed childgetParentEdge(V vertex) Returns the edge connectingvertexto its parent in this tree.Returns an ordered list of the nodes beginning at the root and ending atvertex, including all intermediate nodes.getRoot()getter for the root of the treeCollection<Tree<V, E>> getTrees()Returns a view of this graph as a collection ofTreeinstances.booleanisInternal(V v) booleanbooleanbooleanremoveChild(V orphan) removes a node from the tree, causing all descendants of the removed node also to be removedbooleanremoveVertex(V vertex) remove the passed node, and all nodes that are descendants of the passed node.voidsets the root to the passed value, only if the root is previously unsettoString()Methods inherited from class GraphDecorator
addEdge, containsEdge, containsVertex, degree, findEdge, findEdgeSet, getDefaultEdgeType, getDest, getEdgeCount, getEdgeCount, getEdges, getEdges, getEdgeType, getEndpoints, getIncidentEdges, getIncidentVertices, getInEdges, getNeighborCount, getNeighbors, getOpposite, getOutEdges, getPredecessorCount, getPredecessors, getSource, getSuccessorCount, getSuccessors, getVertexCount, getVertices, inDegree, isDest, isIncident, isNeighbor, isPredecessor, isSource, isSuccessor, outDegree, removeEdgeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Graph
getDest, getEndpoints, getInEdges, getOpposite, getOutEdges, getPredecessorCount, getPredecessors, getSource, getSuccessorCount, getSuccessors, inDegree, isDest, isPredecessor, isSource, isSuccessor, outDegreeMethods inherited from interface Hypergraph
addEdge, containsEdge, containsVertex, degree, findEdge, findEdgeSet, getDefaultEdgeType, getEdgeCount, getEdgeCount, getEdges, getEdges, getEdgeType, getIncidentEdges, getIncidentVertices, getNeighborCount, getNeighbors, getVertexCount, getVertices, isIncident, isNeighbor, removeEdge
-
Field Details
-
root
-
vertex_depths
-
-
Constructor Details
-
DelegateTree
public DelegateTree()Creates an instance. -
DelegateTree
create an instance with passed values.- Parameters:
graphFactory- must create a DirectedGraph to use as a delegate
-
DelegateTree
Creates a newDelegateTreewhich delegates tograph. Assumes thatgraphis already a tree; if it's not, future behavior of this instance is undefined.- Parameters:
graph- the graph to which this instance will delegate operations.
-
-
Method Details
-
getFactory
- Type Parameters:
V- the vertex type for the graph SupplierE- the edge type for the graph Supplier- Returns:
- a
Supplierthat creates an instance of this graph type.
-
addEdge
Add an edge to the tree, connecting v1, the parent and v2, the child. v1 must already exist in the tree, and v2 must not already exist the passed edge must be unique in the tree. Passing an edgeType other than EdgeType.DIRECTED may cause an illegal argument exception in the delegate graph. -
addEdge
Add an edge to the tree, connecting v1, the parent and v2, the child. v1 must already exist in the tree, and v2 must not already exist the passed edge must be unique in the tree. -
addVertex
Will set the root of the Tree, only if the Tree is empty and the root is currently unset.- Specified by:
addVertexin interfaceHypergraph<V,E> - Overrides:
addVertexin classGraphDecorator<V,E> - Parameters:
vertex- the tree root to set- Returns:
- true if this call mutates the underlying graph
- Throws:
UnsupportedOperationException- if the root was previously set- See Also:
-
removeVertex
remove the passed node, and all nodes that are descendants of the passed node.- Specified by:
removeVertexin interfaceHypergraph<V,E> - Overrides:
removeVertexin classGraphDecorator<V,E> - Parameters:
vertex- the vertex to remove- Returns:
trueiff the tree was modified- See Also:
-
addChild
add the passed child node as a child of parent. parent must exist in the tree, and child must not already exist.- Parameters:
edge- the unique edge to connect the parent and child nodesparent- the existing parent to attach the child tochild- the new child to add to the tree as a child of parentedgeType- must be EdgeType.DIRECTED or the underlying graph may throw an exception- Returns:
- whether this call mutates the underlying graph
-
addChild
add the passed child node as a child of parent. parent must exist in the tree, and child must not already exist- Parameters:
edge- the unique edge to connect the parent and child nodesparent- the existing parent to attach the child tochild- the new child to add to the tree as a child of parent- Returns:
- whether this call mutates the underlying graph
-
getChildCount
get the number of children of the passed parent node- Specified by:
getChildCountin interfaceForest<V,E> - Parameters:
parent- the vertex whose child edges are to be returned- Returns:
- the
Collectionof edges connectingvertexto its children in this tree - See Also:
-
getChildren
get the immediate children nodes of the passed parent- Specified by:
getChildrenin interfaceForest<V,E> - Parameters:
parent- the vertex whose children are to be returned- Returns:
- the
Collectionof children ofvertexin this tree - See Also:
-
getParent
-
getPath
-
getRoot
-
setRoot
sets the root to the passed value, only if the root is previously unset- Parameters:
root- the initial tree root
-
removeChild
removes a node from the tree, causing all descendants of the removed node also to be removed- Parameters:
orphan- the node to remove- Returns:
- whether this call mutates the underlying graph
-
getDepth
-
getHeight
-
isInternal
- Parameters:
v- the vertex to test- Returns:
trueifvis neither a leaf nor the root of this tree
-
isLeaf
- Parameters:
v- the vertex to test- Returns:
trueifvhas no children
-
isRoot
- Parameters:
v- the vertex to test- Returns:
trueifvhas no parent
-
getIncidentCount
Description copied from interface:HypergraphReturns the number of vertices that are incident toedge. For hyperedges, this can be any nonnegative integer; for edges this must be 2 (or 1 if self-loops are permitted).Equivalent to
getIncidentVertices(edge).size().- Specified by:
getIncidentCountin interfaceHypergraph<V,E> - Overrides:
getIncidentCountin classGraphDecorator<V,E> - Parameters:
edge- the edge whose incident vertex count is to be returned- Returns:
- the number of vertices that are incident to
edge. - See Also:
-
addEdge
Description copied from interface:HypergraphAddsedgeto this graph. Fails under the following circumstances:edgeis already an element of the graph- either
edgeorverticesisnull verticeshas the wrong number of vertices for the graph typeverticesare already connected by another edge in this graph, and this graph does not accept parallel edges
- Specified by:
addEdgein interfaceHypergraph<V,E> - Overrides:
addEdgein classGraphDecorator<V,E> - Parameters:
edge- the edge to addvertices- the vertices to which the edge will be connected- Returns:
trueif the add is successful, andfalseotherwise- See Also:
-
toString
-
getTrees
-
getChildEdges
Description copied from interface:ForestReturns the edges connectingvertexto its children in this tree. The children of a vertex are defined as being the successors of that vertex on the respective (unique) shortest paths from the root to those vertices. This is syntactic (maple) sugar forgetOutEdges(vertex).- Specified by:
getChildEdgesin interfaceForest<V,E> - Parameters:
vertex- the vertex whose child edges are to be returned- Returns:
- the
Collectionof edges connectingvertexto its children in this tree - See Also:
-
getParentEdge
Description copied from interface:ForestReturns the edge connectingvertexto its parent in this tree. (Ifvertexis the root, returnsnull.) The parent of a vertex is defined as being its predecessor in the (unique) shortest path from the root to this vertex. This is a convenience method which is equivalent toGraph.getInEdges(vertex).iterator().next(), and also toGraph.findEdge(vertex, getParent(vertex)).- Specified by:
getParentEdgein interfaceForest<V,E> - Parameters:
vertex- the vertex whose incoming edge is to be returned- Returns:
- the edge connecting
vertexto its parent, ornullifvertexis the root - See Also:
-