public class TreeImpl extends GraphImpl implements Tree
Directions of Edges in tree are generally ignored. Directionality is basically implied when specifying the root of a Tree, where such operation requires it.
A Tree does not allow cycle paths. So any attempts to create a cycle will thrown a CycleException.
| Constructor and Description |
|---|
TreeImpl()
Creates an instance of a TreeImpl
|
| Modifier and Type | Method and Description |
|---|---|
Edge |
addNode(Vertex parent,
Vertex childNode)
Convenience method to adding nodes in a Tree.
|
Tree |
createTree()
Factory method that returns a new instance of TreeImpl.
|
List |
getChildren(Vertex vertex)
Returns the child nodes of the node specified by the argument.
|
int |
getDepth(Vertex node)
Returns the depth of the node in the Tree.
|
int |
getHeight()
Returns the height of the Tree.
|
List |
getLeaves()
Returns a List of the leaves of ths Tree.
|
Vertex |
getParent(Vertex vertex)
Returns the parent node of the node specified by the argument.
|
Vertex |
getRoot()
Returns the current root of the Tree.
|
Tree |
getSubTree(Vertex subTreeRootVertex)
Returns a new instance of a Tree that is rooted
from the specified node.
|
boolean |
isLeaf(Vertex vertex)
Returns true if the specified node is a leaf.
|
void |
setRoot(Vertex rootVertex)
Sets the root of the Tree.
|
add, addEdge, addEdge, addGraphAddEdgeListener, addGraphAddVertexListener, addGraphRemoveEdgeListener, addGraphRemoveVertexListener, addListener, cloneVertices, containsEdge, containsVertex, forgetConnectedSets, getAdjacentVertices, getAdjacentVertices, getConnectedSet, getConnectedSet, getDegree, getDegree, getEdges, getEdgesCount, getEdgeSet, getGraphFactory, getTraversal, getVertexSet, getVertices, getVerticesCount, getVerticesIterator, isConnected, remove, removeEdge, removeEdges, removeGraphAddEdgeListener, removeGraphAddVertexListener, removeGraphRemoveEdgeListener, removeGraphRemoveVertexListener, removeListener, setGraphFactory, setTraversal, toString, traverseclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitadd, addEdge, addEdge, addGraphAddEdgeListener, addGraphAddVertexListener, addGraphRemoveEdgeListener, addGraphRemoveVertexListener, addListener, cloneVertices, getAdjacentVertices, getAdjacentVertices, getConnectedSet, getConnectedSet, getDegree, getDegree, getEdges, getEdgesCount, getEdgeSet, getGraphFactory, getTraversal, getVertexSet, getVertices, getVerticesCount, getVerticesIterator, isConnected, remove, removeEdge, removeEdges, removeGraphAddEdgeListener, removeGraphAddVertexListener, removeGraphRemoveEdgeListener, removeGraphRemoveVertexListener, removeListener, setGraphFactory, setTraversal, traversepublic void setRoot(Vertex rootVertex) throws GraphException
TreesetRoot in interface TreeGraphExceptionTree.setRoot(salvo.jesus.graph.Vertex)public Vertex getRoot()
TreegetRoot in interface TreeTree.getRoot()public boolean isLeaf(Vertex vertex) throws GraphException
TreeisLeaf in interface TreeEmptyTreeException - is the Tree is empty.GraphExceptionTree.isLeaf(salvo.jesus.graph.Vertex)public Vertex getParent(Vertex vertex) throws GraphException
TreegetParent in interface TreeEmptyTreeException - is the Tree is empty.GraphExceptionTree.getParent(salvo.jesus.graph.Vertex)public List getChildren(Vertex vertex) throws GraphException
TreegetChildren in interface TreeEmptyTreeException - is the Tree is empty.GraphExceptionTree.getChildren(salvo.jesus.graph.Vertex)public Tree getSubTree(Vertex subTreeRootVertex) throws Exception
TreeAlthough a new Tree is returned, the nodes and edges within the new Tree are the same instances as those of the Tree from where it was taken from.
getSubTree in interface TreesubTreeRootVertex - The root of the subtree that we want to returnEmptyTreeException - is the Tree is empty.ExceptionTree.getSubTree(salvo.jesus.graph.Vertex)public int getDepth(Vertex node) throws GraphException
TreegetDepth in interface TreeGraphExceptionTree.getDepth(salvo.jesus.graph.Vertex)public List getLeaves()
TreegetLeaves in interface TreeTree.getLeaves()public int getHeight()
TreegetHeight in interface TreeTree.getHeight()public Tree createTree()
createTree in interface Treepublic Edge addNode(Vertex parent, Vertex childNode) throws Exception
TreeAdds a node to the Tree. The parent node must already be existing in the Tree before the child node can be added. To add the root node, specify null as the parent.
Note that the parent and child relativity is dependent for whatever is the current root node of the Tree. Hence, if childNode later on becomes root via setRoot(), then the parent actually becomes the child of childNode.
addNode in interface TreeGraphException - if there is already a root or the child node
is already existing.NoSuchVertexException - if the parent is not null and is not existingExceptionTree.addNode(salvo.jesus.graph.Vertex, salvo.jesus.graph.Vertex)Copyright © 2019 JULIE Lab, Germany. All rights reserved.