Class 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
    • Constructor Detail

      • DirectedGraph

        public DirectedGraph()
    • 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 - 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
      • addParentTo

        public void addParentTo​(K key,
                                K newParentKey,
                                V newParent)
        Parameters:
        key - Object
        newParentKey - Object
        newParent - Object
      • deleteLeaf

        public void deleteLeaf​(K leaf)
        Parameters:
        leaf - the key for the node. If it is not leaf, nothing will happen.
      • 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