|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgoldman.graph.AdjacencyListRepresentation<V,E>
public class AdjacencyListRepresentation<V,E extends Edge<V>>
The AdjacencyListRepresentation class implements the adjacency list representation of a graph.
Constructor Summary | |
---|---|
AdjacencyListRepresentation(boolean isDirected,
boolean storeIncomingEdges)
Observe that no parameter is needed to indicate whether the graph allows multi-edges, since the underlying representation of an adjacency list is not affected by this choice. |
Method Summary | |
---|---|
void |
addEdge(E edge)
Adds the given edge to this graph. |
boolean |
addVertex(V vertex)
It adds the given vertex 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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AdjacencyListRepresentation(boolean isDirected, boolean storeIncomingEdges)
isDirected
- which is true when the graph is a directed graphstoreIncomingEdges
- which is true when the incoming edges should be maintainedMethod Detail |
---|
public boolean isDirected()
GraphRepresentation
isDirected
in interface GraphRepresentation<V,E extends Edge<V>>
public int numVertices()
GraphRepresentation
numVertices
in interface GraphRepresentation<V,E extends Edge<V>>
public boolean containsVertex(V vertex)
GraphRepresentation
containsVertex
in interface GraphRepresentation<V,E extends Edge<V>>
public boolean containsEdge(V source, V dest)
GraphRepresentation
containsEdge
in interface GraphRepresentation<V,E extends Edge<V>>
source
- the source vertexdest
- the destination vertex
public E getEdge(V source, V dest)
GraphRepresentation
source
to dest
,
or null if there is no such edge.
getEdge
in interface GraphRepresentation<V,E extends Edge<V>>
source
- the source vertexdest
- the destination vertex
public NonMutatingIterator<V> iterator()
GraphRepresentation
removeVertex
method.
iterator
in interface GraphRepresentation<V,E extends Edge<V>>
iterator
in interface Iterable<V>
public boolean addVertex(V vertex)
addVertex
in interface GraphRepresentation<V,E extends Edge<V>>
vertex
- the vertex to add to this graph
public void addEdge(E edge)
GraphRepresentation
addEdge
in interface GraphRepresentation<V,E extends Edge<V>>
edge
- the edge to
add to this graphpublic boolean removeVertex(V vertex)
GraphRepresentation
removeVertex
in interface GraphRepresentation<V,E extends Edge<V>>
vertex
- the vertex to remove
public boolean removeEdge(E edge)
GraphRepresentation
removeEdge
in interface GraphRepresentation<V,E extends Edge<V>>
edge
- the edge to be removed from
this graph
public Iterator<E> edgesFrom(V source)
GraphRepresentation
source
. Observe that
for an undirected graph, the iterator is over all edges incident to source
.
edgesFrom
in interface GraphRepresentation<V,E extends Edge<V>>
source
- the source vertex
public Iterator<E> edgesTo(V dest)
GraphRepresentation
dest
.
This method throws an UnsupportedOperationException
when the graph representations
does not support this capability.
edgesTo
in interface GraphRepresentation<V,E extends Edge<V>>
dest
- the destination vertex
UnsupportedOperationException
- the graph is directed and the constructor
parameter specified not to maintain the inedges
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |