Class DirectedGraph<K,V>
java.lang.Object
ubic.basecode.dataStructure.graph.AbstractGraph<DirectedGraphNode<K,V>,K,V>
ubic.basecode.dataStructure.graph.DirectedGraph<K,V>
- All Implemented Interfaces:
Graph<DirectedGraphNode<K,
V>, K, V>
A graph that contains DirectedGraphNodes. It can be cyclic. Small unconnected parts of the graph will be ignored for
many operation. Tree traversals start from the root node. There can be only one root.
- Author:
- Paul Pavlidis
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DefaultTreeModel
protected Map
<K, DirectedGraphNode<K, V>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChildTo
(K key, K newChildKey) Add a child to a particular node identified by key; if the node is not in the graph, an exception is thrown.void
addChildTo
(K key, K newChildKey, V newChild) Add a child to a particualar node identified by key.void
Will not be attached to any other node.void
addNode
(DirectedGraphNode<K, V> node) void
addParentTo
(K key, K newParentKey) void
addParentTo
(K key, K newParentKey, V newParent) boolean
containsKey
(K key) void
deleteLeaf
(K leaf) Map
<K, DirectedGraphNode<K, V>> getItems()
getRoot()
Get all the values in thee graph.void
prune()
Remove edges to nodes that aren't in the graph.void
topoSort()
Fills in the topoSortOrder for each node.toString()
Shows the tree as a tabbed list.treeView()
Generate a JTree corresponding to this graph.treeView
(Class<? extends DefaultMutableTreeNode> nodeClass) Generate a JTree corresponding to this graph.Methods inherited from class ubic.basecode.dataStructure.graph.AbstractGraph
get, getNodeContents, unmarkAll
-
Field Details
-
dtm
-
items
-
-
Constructor Details
-
DirectedGraph
public DirectedGraph()
-
-
Method Details
-
addChildTo
Add a child to a particular node identified by key; if the node is not in the graph, an exception is thrown.- Parameters:
key
- ObjectnewChildKey
- Object- Throws:
IllegalStateException
- if the graph doesn't contain the child node.
-
addChildTo
Add a child to a particualar node identified by key. If it is a new node, it will be added to the graph first.- Parameters:
key
- ObjectnewChildKey
- ObjectnewChild
- Object
-
addNode
- Specified by:
addNode
in classAbstractGraph<DirectedGraphNode<K,
V>, K, V> - Parameters:
node
- GraphNode
-
addNode
Will not be attached to any other node.- Specified by:
addNode
in interfaceGraph<DirectedGraphNode<K,
V>, K, V> - Specified by:
addNode
in classAbstractGraph<DirectedGraphNode<K,
V>, K, V> - Parameters:
key
- Objectitem
- Object
-
addParentTo
- Parameters:
key
- ObjectnewParentKey
- Object- Throws:
IllegalArgumentException
- if the new parent isn't already in the graph.IllegalStateException
-
addParentTo
- Parameters:
key
- ObjectnewParentKey
- ObjectnewParent
- Object
-
containsKey
- Specified by:
containsKey
in interfaceGraph<DirectedGraphNode<K,
V>, K, V> - Specified by:
containsKey
in classAbstractGraph<DirectedGraphNode<K,
V>, K, V> - Parameters:
key
- Object- Returns:
- true if the graph contains an item referenced by key, false otherwise.
-
deleteLeaf
- Parameters:
leaf
- the key for the node. If it is not leaf, nothing will happen.
-
getItems
- Specified by:
getItems
in classAbstractGraph<DirectedGraphNode<K,
V>, K, V> - Returns:
- Map
-
getRoot
- Returns:
- root of the tree.
-
getTreeModel
-
getValues
Get all the values in thee graph.- Returns:
-
prune
public void prune()Remove edges to nodes that aren't in the graph. -
topoSort
public void topoSort()Fills in the topoSortOrder for each node. -
toString
Shows the tree as a tabbed list. Items that have no parents are shown at the 'highest' level. -
treeView
Generate a JTree corresponding to this graph.- Returns:
- javax.swing.JTree
-
treeView
Generate a JTree corresponding to this graph.- Parameters:
nodeClass
- The class to be used for TreeNodes. Must provide a constructor that takes a DirectedGraphNode (the root)- Returns:
- javax.swing.JTree
-