common
Interface DGraph

All Known Implementing Classes:
AbstractDGraph, DefaultDGraph, ObjGenGraph, ParentUpdateDGraph

public interface DGraph

A directed graph.


Field Summary
static DGraph EMPTY_GRAPH
          An empty directed graph.
 
Method Summary
 void addEdge(java.lang.Object parent, java.lang.Object child)
          Adds to the graph an edge from parent to child.
 boolean addNode(java.lang.Object v)
          Adds the given object as a node in the graph.
 java.util.Set getAncestors(java.lang.Object v)
          Returns the set of ancestors of the given node, including the node itself.
 java.util.Set getChildren(java.lang.Object v)
          Returns an unmodifiable set consisting of the given object's children, or null if the object is not in the graph.
 java.util.Set getDescendants(java.lang.Object v)
          Returns the set of descendants of the given node, including the node itself.
 java.util.Set getParents(java.lang.Object v)
          Returns an unmodifiable set consisting of the given object's parents, or null if the object is not in the graph.
 java.util.Set getRoots()
          Returns the set of nodes in this graph that have no parents.
 java.util.Set nodes()
          Returns an unmodifiable set consisting of the nodes in this graph.
 void print(java.io.PrintStream s)
          Prints a description of this graph to the given stream.
 void removeEdge(java.lang.Object parent, java.lang.Object child)
          Removes the edge from parent to child from the graph.
 boolean removeNode(java.lang.Object v)
          Removes the given node from the graph, along with all the edges incident on it.
 void setParents(java.lang.Object v, java.util.Set parents)
          Changes the graph so that the parent set of the given node is the given set.
 

Field Detail

EMPTY_GRAPH

static final DGraph EMPTY_GRAPH
An empty directed graph.

Method Detail

nodes

java.util.Set nodes()
Returns an unmodifiable set consisting of the nodes in this graph.


addNode

boolean addNode(java.lang.Object v)
Adds the given object as a node in the graph. Has no effect if the node was already in the graph.

Returns:
true if the node was actually added; false if it was already in the graph

removeNode

boolean removeNode(java.lang.Object v)
Removes the given node from the graph, along with all the edges incident on it. Has no effect if the node was not in the graph.

Returns:
true if the node was actually removed; false if it was not in the graph

addEdge

void addEdge(java.lang.Object parent,
             java.lang.Object child)
Adds to the graph an edge from parent to child. Automatically adds these nodes to the graph if they were not already present.


removeEdge

void removeEdge(java.lang.Object parent,
                java.lang.Object child)
Removes the edge from parent to child from the graph. This method has no effect if the edge was not present; it is safe to call even if the given nodes are not in the graph.


getParents

java.util.Set getParents(java.lang.Object v)
Returns an unmodifiable set consisting of the given object's parents, or null if the object is not in the graph.


setParents

void setParents(java.lang.Object v,
                java.util.Set parents)
Changes the graph so that the parent set of the given node is the given set. Automatically adds the child node and any parent nodes if they were not already in the graph.


getChildren

java.util.Set getChildren(java.lang.Object v)
Returns an unmodifiable set consisting of the given object's children, or null if the object is not in the graph.


getRoots

java.util.Set getRoots()
Returns the set of nodes in this graph that have no parents.

Returns:
unmodifiable Set of Object

getAncestors

java.util.Set getAncestors(java.lang.Object v)
Returns the set of ancestors of the given node, including the node itself.

Returns:
unmodifiable Set of Object
Throws:
java.lang.NullPointerException - if the given object is not in the graph

getDescendants

java.util.Set getDescendants(java.lang.Object v)
Returns the set of descendants of the given node, including the node itself.

Returns:
unmodifiable Set of Object
Throws:
java.lang.NullPointerException - if the given object is not in the graph

print

void print(java.io.PrintStream s)
Prints a description of this graph to the given stream.