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>
public class DirectedGraph<K,V> extends AbstractGraph<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
Fields Modifier and Type Field Description protected DefaultTreeModel
dtm
protected Map<K,DirectedGraphNode<K,V>>
items
-
Constructor Summary
Constructors Constructor Description DirectedGraph()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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
addNode(K key, V item)
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()
DirectedGraphNode<K,V>
getRoot()
DefaultTreeModel
getTreeModel()
Collection<V>
getValues()
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.String
toString()
Shows the tree as a tabbed list.JTree
treeView()
Generate a JTree corresponding to this graph.JTree
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 Detail
-
dtm
protected DefaultTreeModel dtm
-
items
protected Map<K,DirectedGraphNode<K,V>> items
-
-
Method Detail
-
addChildTo
public void addChildTo(K key, K newChildKey) throws IllegalStateException
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
public void addChildTo(K key, K newChildKey, V newChild)
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
public void addNode(DirectedGraphNode<K,V> node)
- Specified by:
addNode
in classAbstractGraph<DirectedGraphNode<K,V>,K,V>
- Parameters:
node
- GraphNode
-
addNode
public void addNode(K key, V item)
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
public void addParentTo(K key, K newParentKey) throws IllegalStateException
- Parameters:
key
- ObjectnewParentKey
- Object- Throws:
IllegalArgumentException
- if the new parent isn't already in the graph.IllegalStateException
-
addParentTo
public void addParentTo(K key, K newParentKey, V newParent)
- Parameters:
key
- ObjectnewParentKey
- ObjectnewParent
- Object
-
containsKey
public boolean containsKey(K key)
- 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
public void deleteLeaf(K leaf)
- Parameters:
leaf
- the key for the node. If it is not leaf, nothing will happen.
-
getItems
public Map<K,DirectedGraphNode<K,V>> getItems()
- Specified by:
getItems
in classAbstractGraph<DirectedGraphNode<K,V>,K,V>
- Returns:
- Map
-
getRoot
public DirectedGraphNode<K,V> getRoot()
- Returns:
- root of the tree.
-
getTreeModel
public DefaultTreeModel getTreeModel()
-
getValues
public Collection<V> 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
public String toString()
Shows the tree as a tabbed list. Items that have no parents are shown at the 'highest' level.
-
treeView
public JTree treeView()
Generate a JTree corresponding to this graph.- Returns:
- javax.swing.JTree
-
treeView
public JTree treeView(Class<? extends DefaultMutableTreeNode> nodeClass)
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
-
-