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 Details

  • Constructor Details

    • DirectedGraph

      public DirectedGraph()
  • Method Details

    • 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 - Object
      newChildKey - 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 - Object
      newChildKey - Object
      newChild - Object
    • addNode

      public void addNode(DirectedGraphNode<K,V> node)
      Specified by:
      addNode in class AbstractGraph<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 interface Graph<DirectedGraphNode<K,V>,K,V>
      Specified by:
      addNode in class AbstractGraph<DirectedGraphNode<K,V>,K,V>
      Parameters:
      key - Object
      item - Object
    • addParentTo

      public void addParentTo(K key, K newParentKey) throws IllegalStateException
      Parameters:
      key - Object
      newParentKey - 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 - Object
      newParentKey - Object
      newParent - Object
    • containsKey

      public boolean containsKey(K key)
      Specified by:
      containsKey in interface Graph<DirectedGraphNode<K,V>,K,V>
      Specified by:
      containsKey in class AbstractGraph<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 class AbstractGraph<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.
      Overrides:
      toString in class Object
      Returns:
      String
    • 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