Class DirectedGraphNode<K,V>

All Implemented Interfaces:
Comparable<DirectedGraphNode<K,V>>, GraphNode<K,V>

public class DirectedGraphNode<K,V> extends AbstractGraphNode<K,V> implements Comparable<DirectedGraphNode<K,V>>
A graph node that has the concept of parents and children. Keys can be anything, but probably Strings or Integers.
Author:
Paul Pavlidis
  • Field Details

    • children

      protected Set<K> children
    • parents

      protected Set<K> parents
    • topoSortOrder

      protected int topoSortOrder
  • Constructor Details

    • DirectedGraphNode

      public DirectedGraphNode(K key, V value, DirectedGraph<K,V> graph)
      Parameters:
      key - Object
      value - Object
      graph - Graph
  • Method Details

    • addChild

      public void addChild(K newChildKey)
      Parameters:
      newChildKey - Object
    • addParent

      public void addParent(K newParentKey)
      Parameters:
      newParentKey - Object
    • clone

      public DirectedGraphNode<K,V> clone()
      Makes a copy of this node. It does not make a deep copy of the contents. This should be used when making subgraphs.
      Overrides:
      clone in class Object
      Returns:
      Object
    • compareTo

      public int compareTo(DirectedGraphNode<K,V> o)
      Uses the topological sort order.
      Specified by:
      compareTo in interface Comparable<K>
      Parameters:
      o - Object
      Returns:
      int
    • getAllChildNodes

      public Set<DirectedGraphNode<K,V>> getAllChildNodes()
      Get all the children of this node, recursively.
    • getAllParentNodes

      public Set<DirectedGraphNode<K,V>> getAllParentNodes()
      Get all the parents of this node, recursively.
      Returns:
    • getChildCount

      public int getChildCount()
      Returns:
      int how many children this node has, determined recursively.
    • getChildGraph

      public DirectedGraph<K,V> getChildGraph()
      Get the subgraph starting from this node, including this node.
      Returns:
      Graph
    • getChildKeys

      public Set<K> getChildKeys()
      Returns:
      Object
    • getChildNodes

      public Set<DirectedGraphNode<K,V>> getChildNodes()
      Get the immediate children of this node. References to the DirectedGraphNodes are given, as opposed to key values.
      Returns:
      Set containing the child nodes of this node.
    • getGraph

      public DirectedGraph<K,V> getGraph()
      Specified by:
      getGraph in interface GraphNode<K,V>
      Returns:
      the Graph this belongs to.
    • getParentKeys

      public Set<K> getParentKeys()
      Returns:
      Object
    • getParentNodes

      public Set<DirectedGraphNode<K,V>> getParentNodes()
      Get the immediate parents of this node. References to the DirectedGraphNodes are given, as opposed to key values.
      Returns:
      Set
    • getTopoSortOrder

      public int getTopoSortOrder()
      Returns:
      int
    • hasChild

      public boolean hasChild(Object j)
      Check to see if this node has a particular immediate child.
      Parameters:
      j - Object
      Returns:
      boolean
    • hasParent

      public boolean hasParent(Object j)
      Check to see if this node has a particular immediate parent.
      Parameters:
      j - Object
      Returns:
      boolean
    • inDegree

      public int inDegree()
      Returns:
      int number of immediate parents this node has.
    • isLeaf

      public boolean isLeaf()
      Returns:
    • numParents

      public int numParents()
      Returns:
      int how many parents this node has, determined recursively.
    • outDegree

      public int outDegree()
      Returns:
      int number of immediate children this node has.
    • prune

      public void prune()
      Remove connections that are to nodes not contained in this graph
    • setGraph

      public void setGraph(DirectedGraph<K,V> graph)
    • setTopoSortOrder

      public void setTopoSortOrder(int i)
      Parameters:
      i - int
    • toString

      public String toString()
      Overrides:
      toString in class AbstractGraphNode<K,V>