Interface Graph
-
- All Superinterfaces:
GraphNodeContent
- All Known Implementing Classes:
ADag
,AggregatedJob
,MapGraph
public interface Graph extends GraphNodeContent
The interface for the Graph Class. It implements the GraphNodeContent interface. This allows us to associate Graphs with the nodes in a Graph i.e. graph of graphs.- Version:
- $Revision$
- Author:
- Karan Vahi
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
VERSION
The version number associated with this Graph API.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addEdge(GraphNode parent, GraphNode child)
Adds an edge between two already existing nodes in the graph.void
addEdge(java.lang.String parent, java.lang.String child)
Adds an edge between two already existing nodes in the graph.void
addEdges(java.lang.String child, java.util.List<java.lang.String> parents)
A convenience method that allows for bulk addition of edges between already existing nodes in the graph.void
addNode(GraphNode node)
Adds a node to the Graph.void
addRoot(GraphNode root)
Adds a single root node to the Graph.java.util.Iterator<GraphNode>
bottomUpIterator()
Returns an iterator that traverses the graph bottom up from the leaves.java.util.List<GraphNode>
getLeaves()
Returns the leaf nodes of the Graph.GraphNode
getNode(java.lang.String identifier)
Returns the node matching the id passed.java.util.List<GraphNode>
getRoots()
Returns the root nodes of the Graph.boolean
isEmpty()
Returns a boolean if there are no nodes in the graph.java.util.Iterator<GraphNode>
iterator()
Returns an iterator that traverses through the graph using a graph traversal algorithm.java.util.Iterator<GraphNode>
nodeIterator()
Returns an iterator for the nodes in the Graph.boolean
remove(java.lang.String identifier)
Removes a node from the Graph.void
resetEdges()
Resets all the dependencies in the Graph, while preserving the nodes.int
size()
Returns the number of nodes in the graph.java.util.Iterator<GraphNode>
topologicalSortIterator()
Returns an iterator for the graph that traverses in topological sort order.
-
-
-
Field Detail
-
VERSION
static final java.lang.String VERSION
The version number associated with this Graph API.- See Also:
- Constant Field Values
-
-
Method Detail
-
addNode
void addNode(GraphNode node)
Adds a node to the Graph. It overwrites an already existing node with the same ID.- Parameters:
node
- the node to be added to the Graph.
-
addEdge
void addEdge(java.lang.String parent, java.lang.String child)
Adds an edge between two already existing nodes in the graph.- Parameters:
parent
- the parent node ID.child
- the child node ID.
-
addEdge
void addEdge(GraphNode parent, GraphNode child)
Adds an edge between two already existing nodes in the graph.- Parameters:
parent
- the parent node .child
- the child node .
-
addEdges
void addEdges(java.lang.String child, java.util.List<java.lang.String> parents)
A convenience method that allows for bulk addition of edges between already existing nodes in the graph.- Parameters:
child
- the child node IDparents
- list of parent identifiers asString
.
-
resetEdges
void resetEdges()
Resets all the dependencies in the Graph, while preserving the nodes. The resulting Graph is a graph of independent nodes.
-
getNode
GraphNode getNode(java.lang.String identifier)
Returns the node matching the id passed.- Parameters:
identifier
- the id of the node.- Returns:
- the node matching the ID else null.
-
addRoot
void addRoot(GraphNode root)
Adds a single root node to the Graph. All the exisitng roots of the Graph become children of the root.- Parameters:
root
- theGraphNode
to be added as a root.- Throws:
java.lang.RuntimeException
- if a node with the same id already exists.
-
remove
boolean remove(java.lang.String identifier)
Removes a node from the Graph.- Parameters:
identifier
- the id of the node to be removed.- Returns:
- boolean indicating whether the node was removed or not.
-
nodeIterator
java.util.Iterator<GraphNode> nodeIterator()
Returns an iterator for the nodes in the Graph. These iterators are fail safe.- Returns:
- Iterator
-
iterator
java.util.Iterator<GraphNode> iterator()
Returns an iterator that traverses through the graph using a graph traversal algorithm.- Returns:
- Iterator through the nodes of the graph.
-
topologicalSortIterator
java.util.Iterator<GraphNode> topologicalSortIterator()
Returns an iterator for the graph that traverses in topological sort order.- Returns:
- Iterator through the nodes of the graph.
-
bottomUpIterator
java.util.Iterator<GraphNode> bottomUpIterator()
Returns an iterator that traverses the graph bottom up from the leaves. At any one time, only one iterator can iterate through the graph.- Returns:
- Iterator through the nodes of the graph.
-
size
int size()
Returns the number of nodes in the graph.
-
getRoots
java.util.List<GraphNode> getRoots()
Returns the root nodes of the Graph.- Returns:
- a list containing
GraphNode
corressponding to the root nodes.
-
getLeaves
java.util.List<GraphNode> getLeaves()
Returns the leaf nodes of the Graph.- Returns:
- a list containing
GraphNode
corressponding to the leaf nodes.
-
isEmpty
boolean isEmpty()
Returns a boolean if there are no nodes in the graph.- Returns:
- boolean
-
-