|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgoldman.graph.AdjacencyMatrixRepresentation<V,E>
public class AdjacencyMatrixRepresentation<V,E extends Edge<V>>
The AdjacencyMatrixRepresentation class implements the adjacency matrix representation of a graph.
Field Summary | |
---|---|
static int |
DEFAULT_INITIAL_CAPACITY
|
Constructor Summary | |
---|---|
AdjacencyMatrixRepresentation(boolean isDirected)
|
Method Summary | |
---|---|
void |
addEdge(E edge)
Adds the given edge to this graph. |
protected void |
addEdge(int sourceID,
int destID,
E edge)
|
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)
Removing a vertex implicitly removes all of its incident edges. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_INITIAL_CAPACITY
Constructor Detail |
---|
public AdjacencyMatrixRepresentation(boolean isDirected)
Method 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
e.source
= dest
and e.dest
= source
.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
protected void addEdge(int sourceID, int destID, E edge)
sourceID
- the id associated
with the source vertexdestID
- the id associated with the
destination vertexedge
- the edge to add
public void addEdge(E edge)
GraphRepresentation
addEdge
in interface GraphRepresentation<V,E extends Edge<V>>
edge
- the edge to add to
this graph
public boolean removeVertex(V vertex)
removeVertex
in interface GraphRepresentation<V,E extends Edge<V>>
vertex
- the
vertex to be removed
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
source
IllegalArgumentException
- source
is not in the graphpublic 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
dest
IllegalArgumentException
- dest
is not in the graph
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |