public class DirectedGraph<K,V> extends AbstractGraph<DirectedGraphNode<K,V>,K,V>
Modifier and Type | Field and Description |
---|---|
protected DefaultTreeModel |
dtm |
protected Map<K,DirectedGraphNode<K,V>> |
items |
Constructor and Description |
---|
DirectedGraph() |
Modifier and Type | Method and 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(DirectedGraphNode<K,V> node) |
void |
addNode(K key,
V item)
Will not be attached to any other 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.
|
get, getNodeContents, unmarkAll
protected DefaultTreeModel dtm
protected Map<K,DirectedGraphNode<K,V>> items
public void addChildTo(K key, K newChildKey) throws IllegalStateException
key
- ObjectnewChildKey
- ObjectIllegalStateException
- if the graph doesn't contain the child node.public void addChildTo(K key, K newChildKey, V newChild)
key
- ObjectnewChildKey
- ObjectnewChild
- Objectpublic void addNode(DirectedGraphNode<K,V> node)
addNode
in class AbstractGraph<DirectedGraphNode<K,V>,K,V>
node
- GraphNodepublic void addNode(K key, V item)
addNode
in interface Graph<DirectedGraphNode<K,V>,K,V>
addNode
in class AbstractGraph<DirectedGraphNode<K,V>,K,V>
key
- Objectitem
- Objectpublic void addParentTo(K key, K newParentKey) throws IllegalStateException
key
- ObjectnewParentKey
- ObjectIllegalArgumentException
- if the new parent isn't already in the graph.IllegalStateException
public void addParentTo(K key, K newParentKey, V newParent)
key
- ObjectnewParentKey
- ObjectnewParent
- Objectpublic boolean containsKey(K key)
containsKey
in interface Graph<DirectedGraphNode<K,V>,K,V>
containsKey
in class AbstractGraph<DirectedGraphNode<K,V>,K,V>
key
- Objectpublic void deleteLeaf(K leaf)
leaf
- the key for the node. If it is not leaf, nothing will happen.public Map<K,DirectedGraphNode<K,V>> getItems()
getItems
in class AbstractGraph<DirectedGraphNode<K,V>,K,V>
public DirectedGraphNode<K,V> getRoot()
public DefaultTreeModel getTreeModel()
public Collection<V> getValues()
public void prune()
public void topoSort()
public String toString()
public JTree treeView()
public JTree treeView(Class<? extends DefaultMutableTreeNode> nodeClass)
nodeClass
- The class to be used for TreeNodes. Must provide a constructor that takes a DirectedGraphNode
(the root)Copyright © 2003–2023 UBC Michael Smith Laboratories. All rights reserved.