public abstract class AbstractGraph<T extends Vertex>
extends java.lang.Object
Constructor and Description |
---|
AbstractGraph()
Initialize graph to a default initial capacity of 16 vertices
|
AbstractGraph(java.util.Collection<T> vertices)
Use the vertices in a collection as the initial vertices in the graph
|
AbstractGraph(int initialCapacity)
Initialize graph to have capacity for the given number of vertices
|
Modifier and Type | Method and Description |
---|---|
boolean |
addVertex(T vertex)
Inserts vertex if it is not already present.
|
boolean |
containsEdge(T from,
T to)
Shows whether or not the graph contains the specified edge
|
boolean |
containsVertex(Vertex vertex)
Shows whether or not the graph contains the given vertex
|
abstract int |
edgeCount()
Returns the number of edges in the graph.
|
java.util.Set<T> |
getVertices()
Returns a set containing the vertices in the graph.
|
boolean |
removeVertex(Vertex vertex)
Remove a vertex from the graph.
|
int |
vertexCount()
Number of vertices in the graph
|
java.util.Iterator<T> |
vertexIterator()
Returns an iterator over the vertices in the graph
|
public AbstractGraph()
public AbstractGraph(int initialCapacity)
initialCapacity
- expected number of verticespublic AbstractGraph(java.util.Collection<T> vertices)
vertices
- collection of vertices that will make up the initial vertices
of the graphpublic final boolean addVertex(T vertex)
vertex
- vertex to be insertedpublic final boolean containsVertex(Vertex vertex)
vertex
- the vertex whose presence in the graph is to be testedpublic final boolean removeVertex(Vertex vertex)
vertex
- vertex to be removed from the graphpublic final int vertexCount()
public final java.util.Set<T> getVertices()
public final java.util.Iterator<T> vertexIterator()
public final boolean containsEdge(T from, T to)
from
- the tail or source vertex of the edge for which we are testingto
- the head or target vertex of the edge for which we are testingjava.lang.IllegalArgumentException
- if either vertex is not present in the graphpublic abstract int edgeCount()