goldman.graph
Interface GraphRepresentation<V,E extends Edge<V>>

All Superinterfaces:
Iterable<V>
All Known Implementing Classes:
AdjacencyListRepresentation, AdjacencyMatrixRepresentation

public interface GraphRepresentation<V,E extends Edge<V>>
extends Iterable<V>

The GraphRepresentation interface defines the methods that must be supported by any graph representation, such as the adjacency list and adjacency matrix representations. This design allows different types of graphs (e.g., weighted and unweighted) to independently choose their internal representation from among the classes that implement GraphRepresentation.


Method Summary
 void addEdge(E edge)
          Adds the given edge to this graph.
 boolean addVertex(V vertex)
          Adds the given vertex to this graph unless it is already in the graph.
 boolean containsEdge(V source, V dest)
          Returns true if and only if there is an edge in the graph from the source vertex to the destination vertex.
 boolean containsVertex(V vertex)
          Returns true if and only if the give vertex is in the graph.
 Iterator<E> edgesFrom(V source)
          Returns an iterator over the outgoing edges from source.
 Iterator<E> edgesTo(V dest)
          Returns an iterator over the incoming edges from dest.
 E getEdge(V source, V dest)
          Returns an edge in the graph from source to dest, or null if there is no such edge.
 boolean isDirected()
          Returns true if and only if this graph representation is being used to support a directed graph.
 NonMutatingIterator<V> iterator()
          Returns a non-mutating iterator over the vertices of the graph.
 int numVertices()
          Returns the number of vertices in this graph.
 boolean removeEdge(E edge)
          Returns true when the given edge is successfully removed, and false, if the edge did not exist.
 boolean removeVertex(V vertex)
          Returns true if and only if the given vertex existed and was removed.
 

Method Detail

addEdge

void addEdge(E edge)
Adds the given edge to this graph.


addVertex

boolean addVertex(V vertex)
Adds the given vertex to this graph unless it is already in the graph. It returns true if and only if the vertex is added.


containsEdge

boolean containsEdge(V source,
                     V dest)
Returns true if and only if there is an edge in the graph from the source vertex to the destination vertex.


containsVertex

boolean containsVertex(V vertex)
Returns true if and only if the give vertex is in the graph.


edgesFrom

Iterator<E> edgesFrom(V source)
Returns an iterator over the outgoing edges from source. Observe that for an undirected graph, the iterator is over all edges incident to source.


edgesTo

Iterator<E> edgesTo(V dest)
Returns an iterator over the incoming edges from dest. This method throws an UnsupportedOperationException when the graph representations does not support this capability.


getEdge

E getEdge(V source,
          V dest)
Returns an edge in the graph from source to dest, or null if there is no such edge.


isDirected

boolean isDirected()
Returns true if and only if this graph representation is being used to support a directed graph.


iterator

NonMutatingIterator<V> iterator()
Returns a non-mutating iterator over the vertices of the graph. A non-mutating iterator is returned to ensure that the application program can only remove a vertex from a graph using the removeVertex method.

Specified by:
iterator in interface Iterable<V>

numVertices

int numVertices()
Returns the number of vertices in this graph.


removeEdge

boolean removeEdge(E edge)
Returns true when the given edge is successfully removed, and false, if the edge did not exist.


removeVertex

boolean removeVertex(V vertex)
Returns true if and only if the given vertex existed and was removed.