edu.isi.pegasus.planner.partitioner.graph
Class MapGraph

java.lang.Object
  extended by edu.isi.pegasus.planner.partitioner.graph.MapGraph
All Implemented Interfaces:
Graph, GraphNodeContent

public class MapGraph
extends Object
implements Graph

An implementation of the Graph that is backed by a Map.

Version:
$Revision: 2679 $
Author:
Karan Vahi vahi@isi.edu

Nested Class Summary
protected  class MapGraph.MapGraphIterator
          An inner iterator class that traverses through the Graph.
 
Field Summary
private  LogManager mLogger
          The handle to the logging manager.
protected  Map mStore
          The map indexed by the id of the GraphNode, used for storing the nodes of the Graph.
 
Fields inherited from interface edu.isi.pegasus.planner.partitioner.graph.Graph
VERSION
 
Constructor Summary
MapGraph()
          The default constructor.
 
Method Summary
 void addEdge(String parent, String child)
          Adds an edge between two already existing nodes in the graph.
 void addEdges(String child, List 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.
 Object clone()
          Returns a copy of the object.
 Object get(Object key)
          It returns the value associated with the key in the map.
 List getLeaves()
          Returns the leaf nodes of the Graph.
 GraphNode getNode(String identifier)
          Returns the node matching the id passed.
 List getRoots()
          Returns the root nodes of the Graph.
 boolean isEmpty()
          Returns a boolean if there are no nodes in the graph.
 Iterator iterator()
          Returns an iterator that traverses through the graph using a graph traversal algorithm.
 Iterator nodeIterator()
          Returns an iterator for the nodes in the Graph.
 boolean remove(String identifier)
          Removes a node from the Graph.
 int size()
          Returns the number of nodes in the graph.
 Iterator<GraphNode> topologicalSortIterator()
          Returns an iterator for the graph that traverses in topological sort order.
 String toString()
          The textual representation of the graph node.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mStore

protected Map mStore
The map indexed by the id of the GraphNode, used for storing the nodes of the Graph. The value for each key is the corresponding GraphNode of the class.


mLogger

private LogManager mLogger
The handle to the logging manager.

Constructor Detail

MapGraph

public MapGraph()
The default constructor.

Method Detail

addNode

public void addNode(GraphNode node)
Adds a node to the Graph. It overwrites an already existing node with the same ID.

Specified by:
addNode in interface Graph
Parameters:
node - the node to be added to the Graph.

getNode

public GraphNode getNode(String identifier)
Returns the node matching the id passed.

Specified by:
getNode in interface Graph
Parameters:
identifier - the id of the node.
Returns:
the node matching the ID else null.

addRoot

public void addRoot(GraphNode root)
Adds a single root node to the Graph. All the exisitng roots of the Graph become children of the root.

Specified by:
addRoot in interface Graph
Parameters:
root - the GraphNode to be added as a root.
Throws:
RuntimeException - if a node with the same id already exists.

remove

public boolean remove(String identifier)
Removes a node from the Graph.

Specified by:
remove in interface Graph
Parameters:
identifier - the id of the node to be removed.
Returns:
boolean indicating whether the node was removed or not.

getRoots

public List getRoots()
Returns the root nodes of the Graph.

Specified by:
getRoots in interface Graph
Returns:
a list containing GraphNode corressponding to the root nodes.

getLeaves

public List getLeaves()
Returns the leaf nodes of the Graph.

Specified by:
getLeaves in interface Graph
Returns:
a list containing GraphNode corressponding to the leaf nodes.

addEdge

public void addEdge(String parent,
                    String child)
Adds an edge between two already existing nodes in the graph.

Specified by:
addEdge in interface Graph
Parameters:
parent - the parent node ID.
child - the child node ID.

addEdges

public void addEdges(String child,
                     List parents)
A convenience method that allows for bulk addition of edges between already existing nodes in the graph.

Specified by:
addEdges in interface Graph
Parameters:
child - the child node ID
parents - list of parent identifiers as String.

size

public int size()
Returns the number of nodes in the graph.

Specified by:
size in interface Graph
Returns:
the number of nodes

nodeIterator

public Iterator nodeIterator()
Returns an iterator for the nodes in the Graph.

Specified by:
nodeIterator in interface Graph
Returns:
Iterator

iterator

public Iterator iterator()
Returns an iterator that traverses through the graph using a graph traversal algorithm. At any one time, only one iterator can iterate through the graph.

Specified by:
iterator in interface Graph
Returns:
Iterator through the nodes of the graph.

topologicalSortIterator

public Iterator<GraphNode> topologicalSortIterator()
Returns an iterator for the graph that traverses in topological sort order.

Specified by:
topologicalSortIterator in interface Graph
Returns:
Iterator through the nodes of the graph.

toString

public String toString()
The textual representation of the graph node.

Overrides:
toString in class Object
Returns:
textual description.

isEmpty

public boolean isEmpty()
Returns a boolean if there are no nodes in the graph.

Specified by:
isEmpty in interface Graph
Returns:
boolean

clone

public Object clone()
Returns a copy of the object.

Overrides:
clone in class Object
Returns:
clone of the object.

get

public Object get(Object key)
It returns the value associated with the key in the map.

Parameters:
key - the key to the entry in the map.


Copyright © 2011 The University of Southern California. All Rights Reserved.