Class DirectedGraphNode<K,V>
- java.lang.Object
-
- ubic.basecode.dataStructure.Visitable
-
- ubic.basecode.dataStructure.graph.AbstractGraphNode<K,V>
-
- ubic.basecode.dataStructure.graph.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
-
-
Constructor Summary
Constructors Constructor Description DirectedGraphNode(K key, V value, DirectedGraph<K,V> graph)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(K newChildKey)voidaddParent(K newParentKey)DirectedGraphNode<K,V>clone()Makes a copy of this node.intcompareTo(DirectedGraphNode<K,V> o)Uses the topological sort order.Set<DirectedGraphNode<K,V>>getAllChildNodes()Get all the children of this node, recursively.Set<DirectedGraphNode<K,V>>getAllParentNodes()Get all the parents of this node, recursively.intgetChildCount()DirectedGraph<K,V>getChildGraph()Get the subgraph starting from this node, including this node.Set<K>getChildKeys()Set<DirectedGraphNode<K,V>>getChildNodes()Get the immediate children of this node.DirectedGraph<K,V>getGraph()Set<K>getParentKeys()Set<DirectedGraphNode<K,V>>getParentNodes()Get the immediate parents of this node.intgetTopoSortOrder()booleanhasChild(Object j)Check to see if this node has a particular immediate child.booleanhasParent(Object j)Check to see if this node has a particular immediate parent.intinDegree()booleanisLeaf()intnumParents()intoutDegree()voidprune()Remove connections that are to nodes not contained in this graphvoidsetGraph(DirectedGraph<K,V> graph)voidsetTopoSortOrder(int i)StringtoString()
-
-
-
Constructor Detail
-
DirectedGraphNode
public DirectedGraphNode(K key, V value, DirectedGraph<K,V> graph)
- Parameters:
key- Objectvalue- Objectgraph- Graph
-
-
Method Detail
-
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.
-
compareTo
public int compareTo(DirectedGraphNode<K,V> o)
Uses the topological sort order.- Specified by:
compareToin interfaceComparable<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
-
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()
-
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:
toStringin classAbstractGraphNode<K,V>
-
-