salvo.jesus.graph
Interface Graph

All Superinterfaces:
java.io.Serializable
All Known Subinterfaces:
CyclePath, DirectedAcyclicGraph, DirectedGraph, DirectedGraphWithDict, Path, SimplePath
All Known Implementing Classes:
CallGraph, CondensedGraph, CyclePathImpl, DirectedAcyclicGraphImpl, DirectedGraphImpl, DirectedGraphWeakImpl, DirectedGraphWithDictImpl, GraphImpl, PathImpl, SimplePathImpl

public interface Graph
extends java.io.Serializable

An interface for Graphs.


Method Summary
 void add(Vertex v)
          Adds a Vertex into the Graph.
 void addEdge(Edge e)
          Adds an Edge into the Graph.
 Edge addEdge(Vertex v1, Vertex v2)
          Adds an Edge into the Graph.
 void addGraphAddEdgeListener(GraphAddEdgeListener listener)
          Adds a GraphAddEdgeListener to the Graph's internal Vector of GraphAddEdgeListeners so that when a new Edge is added, all registered GraphAddEdgeListeners are notified of the event.
 void addGraphAddVertexListener(GraphAddVertexListener listener)
          Adds a GraphAddVertexListener to the Graph's internal Vector of GraphAddVertexListeners so that when a new Vertex is added, all registered GraphAddVertedListeners are notified of the event.
 void addGraphRemoveEdgeListener(GraphRemoveEdgeListener listener)
          Adds a GraphRemoveEdgeListener to the Graph's internal Vector of GraphRemoveEdgeListeners so that when an Edge is removed, all registered GraphRemoveEdgeListeners are notified of the event.
 void addGraphRemoveVertexListener(GraphRemoveVertexListener listener)
          Adds a GraphRemoveVertexListener to the Graph's internal Vector of GraphRemoveVertexListeners so that when a Vertex is removed, all registered GraphRemoveVertexListeners are notified of the event.
 java.util.Collection cloneVertices()
          Returns a clone of the Vector of vertices.
 Edge createEdge(Vertex v1, Vertex v2)
          Method to create the proper type of Edge class.
 java.util.Collection getAdjacentVertices(java.util.Collection vertices)
          Returns the vertices adjacent to all the vertices in the given collection.
 java.util.Collection getAdjacentVertices(Vertex v)
          Returns the vertices adjacent to the specified vertex.
 java.util.Collection getConnectedSet()
          Returns the connected sets in the Graph.
 java.util.Collection getConnectedSet(Vertex v)
          Returns the connected set to which the specified vertex belongs.
 int getDegree()
          Returns the degree of the graph, which is simply the highest degree of all the graph's vertices.
 int getDegree(Vertex v)
          Returns the degree of the vertex, which is simply the number of edges of the vertex.
 java.util.Collection getEdges(Vertex v)
          Returns a Vector of edges of the specified vertex.
 GraphTraversal getTraversal()
          Gets the traversal algorithm used by the Graph.
 java.util.Set getVertices(int degree)
          Returns all vertices with the specified degree.
 int getVerticesCount()
          Returns the number of vertices in the graph
 java.util.Iterator getVerticesIterator()
          Returns an iterator that iterates through the graph's vertices.
 boolean isConnected(Vertex v1, Vertex v2)
          Determines if two vertices are connected
 void mergeconnectedSet(Vertex v1, Vertex v2)
          Merges the connected sets to which Vertex v1 and Vertex v2 belongs, if they are not yet connected.
 void remove(Vertex v)
          Removes the specified Edge from the Graph.
 void removeEdge(Edge e)
          Removes the specified Edge from the Graph.
 void removeEdges(Vertex v)
          Removes incident Edges of a Vertex.
 void removeGraphAddEdgeListener(GraphAddEdgeListener listener)
          Removes a GraphAddEdgeListener from the Graph's internal Vector of GraphAddEdgeListeners.
 void removeGraphAddVertexListener(GraphAddVertexListener listener)
          Removes a GraphAddVertexListener from the Graph's internal Vector of GraphAddVertexListeners.
 void removeGraphRemoveEdgeListener(GraphRemoveEdgeListener listener)
          Removes a GraphRemoveEdgeListener from the Graph's internal Vector of GraphRemoveEdgeListeners.
 void removeGraphRemoveVertexListener(GraphRemoveVertexListener listener)
          Removes a GraphRemoveVertexListener from the Graph's internal Vector of GraphRemoveVertexListeners.
 void setTraversal(GraphTraversal traversal)
          Sets the graph traversal algorithm to be used
 java.util.Vector traverse(Vertex startat)
          Traverses the Graph starting at startat Vertex by performing a depth-first traversal.
 

Method Detail

getVerticesCount

int getVerticesCount()
Returns the number of vertices in the graph

Returns:
The number of vertices in the graph.

add

void add(Vertex v)
         throws java.lang.Exception
Adds a Vertex into the Graph. This will also create a new entry in the edges Vector and add the newly added Vertex to its own connected set, thereby adding a new Vector in the connectedSet Vector. Finally, all GraphAddVertexListeners are informed of the event that a Vertex has been added to the Graph.

Parameters:
v - Vertex to be added to the Graph
Throws:
java.lang.Exception

remove

void remove(Vertex v)
            throws java.lang.Exception
Removes the specified Edge from the Graph.

Parameters:
edge - The Edge object to be removed.
Throws:
java.lang.Exception

getVerticesIterator

java.util.Iterator getVerticesIterator()
Returns an iterator that iterates through the graph's vertices.

Returns:
An iterator of Vector vertices.

cloneVertices

java.util.Collection cloneVertices()
Returns a clone of the Vector of vertices.

Returns:
A clone of the Vector of vertices.

createEdge

Edge createEdge(Vertex v1,
                Vertex v2)
Method to create the proper type of Edge class.

Parameters:
v1 - One endpoint of the edge
v2 - Other endpoint of the edge

addEdge

Edge addEdge(Vertex v1,
             Vertex v2)
             throws java.lang.Exception
Adds an Edge into the Graph. The vertices of the Edge must already be existing in the Graph for this method to work properly. The vertices in both ends of the Edge are merged into one connected set, thereby possibly decreasing the number of Vectors in the coonectedSet Vector. Finally, all GraphAddEdgeListeners are informed of the event that a Edge has been added to the Graph.

Parameters:
v1 - One endpoint of the edge
v2 - Other endpoint of the edge
Returns:
The Edge object created and added to the Graph.
Throws:
java.lang.Exception

addEdge

void addEdge(Edge e)
             throws java.lang.Exception
Adds an Edge into the Graph. The vertices of the Edge need not be existing in the Graph for this method to work properly. The vertices in both ends of the Edge are merged into one connected set, thereby possibly decreasing the number of Vectors in the coonectedSet Vector. Finally, all GraphAddEdgeListeners are informed of the event that a Edge has been added to the Graph.

In the event that any one of the vertices are not existing in the Graph, they are added to the Graph.

Note: It is the caller's responsibility to make sure that the type of Edge being added to the Graph matches the Graph. For example, only a DirectedEdge must be added to a DirectedGraph.

Parameters:
e - The edge to be added to the Graph.
Throws:
java.lang.Exception

removeEdge

void removeEdge(Edge e)
                throws java.lang.Exception
Removes the specified Edge from the Graph.

Parameters:
e - The Edge object to be removed.
Throws:
java.lang.Exception

removeEdges

void removeEdges(Vertex v)
                 throws java.lang.Exception
Removes incident Edges of a Vertex. The Edges removed are those whose either endpoints has the specified vertex. This method is usually called just prior to removing a Vertex from a Graph.

Parameters:
v - Vertex whose Edges are to be removed
Throws:
java.lang.Exception

getDegree

int getDegree()
Returns the degree of the graph, which is simply the highest degree of all the graph's vertices.

Returns:
An int indicating the degree of the graph.

getDegree

int getDegree(Vertex v)
Returns the degree of the vertex, which is simply the number of edges of the vertex.

Returns:
The degree of the vertex.

getVertices

java.util.Set getVertices(int degree)
Returns all vertices with the specified degree.

Parameters:
degree - The degree of the vertex to be returned.
Returns:
A collection of vertices with the above specified degree.

getEdges

java.util.Collection getEdges(Vertex v)
Returns a Vector of edges of the specified vertex.

Parameters:
v - The vertex whose edges we want returned
Returns:
A Vector of Edges that are incident edges of the specified vertex.

getAdjacentVertices

java.util.Collection getAdjacentVertices(Vertex v)
Returns the vertices adjacent to the specified vertex.

Parameters:
v - The Vertex you want to determine its adjacent vertices.
Returns:
Vector of vertices adjacent to the specified vertex v.

getAdjacentVertices

java.util.Collection getAdjacentVertices(java.util.Collection vertices)
Returns the vertices adjacent to all the vertices in the given collection.

Parameters:
vertices - Vector of Vertex where each vertex in the returned Set must be adjacent to.
Returns:
Set of vertices adjacent to all the vertices in the supplied Vector.

getConnectedSet

java.util.Collection getConnectedSet()
Returns the connected sets in the Graph. Each Vector in the return Vector is a Vector of vertices that are connected to each other, regardless of the direction of the Edge conneting them together.

Returns:
Vector of Vector of connected vertices.

getConnectedSet

java.util.Collection getConnectedSet(Vertex v)
Returns the connected set to which the specified vertex belongs.

Parameters:
v - Vertex to which you want the connected set returned.
Returns:
Vector of connected vertices where the specified vertex belongs.

mergeconnectedSet

void mergeconnectedSet(Vertex v1,
                       Vertex v2)
Merges the connected sets to which Vertex v1 and Vertex v2 belongs, if they are not yet connected. This ma result in decreasing the number of Vectors in the connectedSet Vector.

Parameters:
v1 - Vertex whose connected set you want merged with the connected set of Vertex v2.
v2 - Vertex whose connected set you want merged with the connected set of Vertex v1.

traverse

java.util.Vector traverse(Vertex startat)
Traverses the Graph starting at startat Vertex by performing a depth-first traversal. The vertices traversed from startat are stored in Visited. Only the connected components to which startat belongs to will be traversed.

Parameters:
startat - The Vertex to which you want to start the traversal.

getTraversal

GraphTraversal getTraversal()
Gets the traversal algorithm used by the Graph.

Returns:
GraphTraversal object performing traversal for the Graph.

setTraversal

void setTraversal(GraphTraversal traversal)
Sets the graph traversal algorithm to be used

Parameters:
traversal - A concrete implementation of the GraphTraversal object.

isConnected

boolean isConnected(Vertex v1,
                    Vertex v2)
Determines if two vertices are connected

Parameters:
v1 - starting Vertex for the path
v2 - ending Vertex for the path
Returns:
true if v1 and v2 are connected.

addGraphAddVertexListener

void addGraphAddVertexListener(GraphAddVertexListener listener)
Adds a GraphAddVertexListener to the Graph's internal Vector of GraphAddVertexListeners so that when a new Vertex is added, all registered GraphAddVertedListeners are notified of the event.

Parameters:
listener - GraphAddVertexListener you want registered or be notified when a new Vertex is added
See Also:
GraphAddVertexListener, removeGraphAddVertexListener( GraphAddVertexListener )

addGraphAddEdgeListener

void addGraphAddEdgeListener(GraphAddEdgeListener listener)
Adds a GraphAddEdgeListener to the Graph's internal Vector of GraphAddEdgeListeners so that when a new Edge is added, all registered GraphAddEdgeListeners are notified of the event.

Parameters:
listener - GraphAddEdgeListener you want registered or be notified when a new Edge is added
See Also:
GraphAddEdgeListener, removeGraphAddEdgeListener( GraphAddEdgeListener )

addGraphRemoveEdgeListener

void addGraphRemoveEdgeListener(GraphRemoveEdgeListener listener)
Adds a GraphRemoveEdgeListener to the Graph's internal Vector of GraphRemoveEdgeListeners so that when an Edge is removed, all registered GraphRemoveEdgeListeners are notified of the event.

Parameters:
listener - GraphRemoveEdgeListener you want registered or be notified when an Edge is removed
See Also:
GraphRemoveEdgeListener, removeGraphRemoveEdgeListener( GraphRemoveEdgeListener )

addGraphRemoveVertexListener

void addGraphRemoveVertexListener(GraphRemoveVertexListener listener)
Adds a GraphRemoveVertexListener to the Graph's internal Vector of GraphRemoveVertexListeners so that when a Vertex is removed, all registered GraphRemoveVertexListeners are notified of the event.

Parameters:
listener - GraphRemoveVertexListener you want registered or be notified when a Vertex is removed
See Also:
GraphRemoveVertexListener, removeGraphRemoveVertexListener( GraphRemoveVertexListener )

removeGraphAddVertexListener

void removeGraphAddVertexListener(GraphAddVertexListener listener)
Removes a GraphAddVertexListener from the Graph's internal Vector of GraphAddVertexListeners.

Parameters:
listener - GraphAddVertexListener you no longer want registered or be notified when a Vertex is added
See Also:
GraphAddVertexListener, addGraphAddVertexListener( GraphAddVertexListener )

removeGraphAddEdgeListener

void removeGraphAddEdgeListener(GraphAddEdgeListener listener)
Removes a GraphAddEdgeListener from the Graph's internal Vector of GraphAddEdgeListeners.

Parameters:
listener - GraphAddEdgeListener you no longer want registered or be notified when an Edge is added
See Also:
GraphAddEdgeListener, addGraphAddEdgeListener( GraphAddEdgeListener )

removeGraphRemoveEdgeListener

void removeGraphRemoveEdgeListener(GraphRemoveEdgeListener listener)
Removes a GraphRemoveEdgeListener from the Graph's internal Vector of GraphRemoveEdgeListeners.

Parameters:
listener - GraphRemoveEdgeListener you no longer want registered or be notified when an Edge is removed
See Also:
GraphRemoveEdgeListener, addGraphRemoveEdgeListener( GraphRemoveEdgeListener )

removeGraphRemoveVertexListener

void removeGraphRemoveVertexListener(GraphRemoveVertexListener listener)
Removes a GraphRemoveVertexListener from the Graph's internal Vector of GraphRemoveVertexListeners.

Parameters:
listener - GraphRemoveVertexListener you no longer want registered or be notified when a Vertex is removed
See Also:
GraphRemoveVertexListener, addGraphRemoveVertexListener( GraphRemoveVertexListener )