org.globus.cog.util.graph
Class Graph

java.lang.Object
  extended by org.globus.cog.util.graph.Graph
All Implemented Interfaces:
Cloneable, GraphInterface

public class Graph
extends Object
implements GraphInterface

Implements the graph interface

See Also:
org.globus.ogce.util.Graph, org.globus.ogce.util.GraphEdge, org.globus.ogce.util.GraphNode

Constructor Summary
Graph()
          Constructs a new Graph object without any nodes or edges
 
Method Summary
 Edge addEdge(Node FromNode, Node ToNode, Object contents)
          Adds an edge from FromNode to ToNode
 void addGraphListener(GraphListener l)
          Adds a listener to listen for structural changes in the graph
 Node addNode()
          Creates a new node in the graph
 Node addNode(Object Contents)
          Creates a new node storing Contents in it
 void clear()
          Removes all nodes and edges from this graph
 Object clone()
          Returns a shallow copy of the graph.
 int edgeCount()
          Returns No of edges in the graph
 boolean equals(Object o)
          Determines if the specified graph is structurally equivalen to the specified graph.
 Edge findEdge(Object contents)
           
 Node findNode(Object contents)
          Finds the node that has the specified contents
 EdgeIterator getEdgesIterator()
          Returns an iterator with the edges in the graph
 Set getEdgesSet()
          Returns a list with the edges in the graph.
 NodeIterator getNodesIterator()
          Returns an iterator with all the nodes in the graph
 Set getNodesSet()
          Returns a list with the nodes in the graph.
 int hashCode()
           
 int nodeCount()
          Returns No of nodes in the graph
 void removeEdge(Edge edge)
          Removes an edge from the graph
 void removeEdge(Node fromNode, Node toNode)
          Removes an edge going from FromNode to ToNode
 void removeGraphListener(GraphListener l)
          Removes a listener
 void removeNode(Node node)
          Removes the specified node from the graph It will also remove all the edges connected to the node
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Graph

public Graph()
Constructs a new Graph object without any nodes or edges

Method Detail

addGraphListener

public void addGraphListener(GraphListener l)
Description copied from interface: GraphInterface
Adds a listener to listen for structural changes in the graph

Specified by:
addGraphListener in interface GraphInterface
Parameters:
l - the listener to be added

removeGraphListener

public void removeGraphListener(GraphListener l)
Description copied from interface: GraphInterface
Removes a listener

Specified by:
removeGraphListener in interface GraphInterface

clear

public void clear()
Description copied from interface: GraphInterface
Removes all nodes and edges from this graph

Specified by:
clear in interface GraphInterface

addNode

public Node addNode()
Creates a new node in the graph

Specified by:
addNode in interface GraphInterface
Returns:
a reference to the newly created node

addNode

public Node addNode(Object Contents)
Creates a new node storing Contents in it

Specified by:
addNode in interface GraphInterface
Parameters:
Contents - The feature to be added to the Node attribute
Returns:
a reference to the newly created node

addEdge

public Edge addEdge(Node FromNode,
                    Node ToNode,
                    Object contents)
             throws NodeNotFoundException
Adds an edge from FromNode to ToNode

Specified by:
addEdge in interface GraphInterface
Parameters:
FromNode - the node the edge starts from
ToNode - the node the edge goes to
contents - The object to be stored in the edge
Returns:
The newly created edge
Throws:
NodeNotFoundException - If one of the specified nodes is not found

edgeCount

public int edgeCount()
Returns No of edges in the graph

Specified by:
edgeCount in interface GraphInterface
Returns:
Description of the Return Value

nodeCount

public int nodeCount()
Returns No of nodes in the graph

Specified by:
nodeCount in interface GraphInterface
Returns:
Description of the Return Value

getNodesIterator

public NodeIterator getNodesIterator()
Returns an iterator with all the nodes in the graph

Specified by:
getNodesIterator in interface GraphInterface
Returns:
The nodesIterator value

getNodesSet

public Set getNodesSet()
Description copied from interface: GraphInterface
Returns a list with the nodes in the graph. The order of nodes is a given. New nodes are added at the end of the list. This method allows manipulation of the graph based on the indexes of nodes.

Specified by:
getNodesSet in interface GraphInterface
Returns:
the list of nodes in this graph

getEdgesIterator

public EdgeIterator getEdgesIterator()
Returns an iterator with the edges in the graph

Specified by:
getEdgesIterator in interface GraphInterface
Returns:
The edgesIterator value

getEdgesSet

public Set getEdgesSet()
Description copied from interface: GraphInterface
Returns a list with the edges in the graph. The order of edges should not change between calls to this method, unless changes are made to the graph. New edges are added at the end of the list. This method allows manipulation of the graph based on the indexes of edges.

Specified by:
getEdgesSet in interface GraphInterface
Returns:
the list of edges in this graph

removeNode

public void removeNode(Node node)
                throws NodeNotFoundException
Removes the specified node from the graph It will also remove all the edges connected to the node

Specified by:
removeNode in interface GraphInterface
Parameters:
node - Description of the Parameter
Throws:
NodeNotFoundException - thrown if the node was not found in this graph

removeEdge

public void removeEdge(Node fromNode,
                       Node toNode)
                throws NodeNotFoundException,
                       EdgeNotFoundException
Removes an edge going from FromNode to ToNode

Specified by:
removeEdge in interface GraphInterface
Parameters:
fromNode - Description of the Parameter
toNode - Description of the Parameter
Throws:
NodeNotFoundException - Description of the Exception
EdgeNotFoundException - Description of the Exception

removeEdge

public void removeEdge(Edge edge)
                throws EdgeNotFoundException
Removes an edge from the graph

Specified by:
removeEdge in interface GraphInterface
Parameters:
edge - Description of the Parameter
Throws:
EdgeNotFoundException - Description of the Exception

findEdge

public Edge findEdge(Object contents)
Specified by:
findEdge in interface GraphInterface

findNode

public Node findNode(Object contents)
Description copied from interface: GraphInterface
Finds the node that has the specified contents

Specified by:
findNode in interface GraphInterface

clone

public Object clone()
Returns a shallow copy of the graph. The Node and Edge objects will be different, but their contained objects will remain the same

Specified by:
clone in interface GraphInterface
Overrides:
clone in class Object
Returns:
the cloned graph

equals

public boolean equals(Object o)
Determines if the specified graph is structurally equivalen to the specified graph. Structural equivalence, in this case, means: Given graph A and B:

hashCode

public int hashCode()
Overrides:
hashCode in class Object