public abstract class AbstractGraph extends java.lang.Object implements Graph
Graph
,
DirectedGraph
,
UndirectedGraph
Constructor and Description |
---|
AbstractGraph()
Construct a new empty graph object.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addAllEdges(java.util.Collection edges)
Adds all of the specified edges to this graph.
|
boolean |
addAllVertices(java.util.Collection vertices)
Adds all of the specified vertices to this graph.
|
protected boolean |
assertVertexExist(java.lang.Object v)
Ensures that the specified vertex exists in this graph, or else throws
exception.
|
boolean |
containsEdge(java.lang.Object sourceVertex,
java.lang.Object targetVertex)
Returns true if and only if this graph contains an edge going
from the source vertex to the target vertex.
|
boolean |
removeAllEdges(java.util.Collection edges)
Removes all the edges in this graph that are also contained in the
specified edge collection.
|
protected boolean |
removeAllEdges(Edge[] edges)
Removes all the edges in this graph that are also contained in the
specified edge array.
|
java.util.List |
removeAllEdges(java.lang.Object sourceVertex,
java.lang.Object targetVertex)
Removes all the edges going from the specified source vertex to the
specified target vertex, and returns a list of all removed edges.
|
boolean |
removeAllVertices(java.util.Collection vertices)
Removes all the vertices in this graph that are also contained in the
specified vertex collection.
|
java.lang.String |
toString()
Returns a string of the parenthesized pair (V, E) representing this
G=(V,E) graph.
|
protected java.lang.String |
toStringFromSets(java.util.Collection vertexSet,
java.util.Collection edgeSet)
Helper for subclass implementations of toString( ).
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addEdge, addEdge, addVertex, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, removeEdge, removeEdge, removeVertex, vertexSet
public boolean addAllEdges(java.util.Collection edges)
Graph
Graph.addEdge(Edge)
method.addAllEdges
in interface Graph
edges
- the edges to be added to this graph.Graph.addAllEdges(Collection)
public boolean addAllVertices(java.util.Collection vertices)
Graph
Graph.addVertex(Object)
method.addAllVertices
in interface Graph
vertices
- the vertices to be added to this graph.Graph.addAllVertices(Collection)
public boolean containsEdge(java.lang.Object sourceVertex, java.lang.Object targetVertex)
Graph
null
, returns false
.containsEdge
in interface Graph
sourceVertex
- source vertex of the edge.targetVertex
- target vertex of the edge.Graph.containsEdge(Object, Object)
public boolean removeAllEdges(java.util.Collection edges)
Graph
Graph.removeEdge(Edge)
method.removeAllEdges
in interface Graph
edges
- edges to be removed from this graph.Graph.removeAllEdges(Collection)
public java.util.List removeAllEdges(java.lang.Object sourceVertex, java.lang.Object targetVertex)
Graph
null
if any of the specified vertices does exist
in the graph. If both vertices exist but no edge found, returns an
empty list. This method will either invoke the Graph.removeEdge(Edge)
method, or the Graph.removeEdge(Object, Object)
method.removeAllEdges
in interface Graph
sourceVertex
- source vertex of the edge.targetVertex
- target vertex of the edge.null
if no edge removed.Graph.removeAllEdges(Object, Object)
public boolean removeAllVertices(java.util.Collection vertices)
Graph
Graph.removeVertex(Object)
method.removeAllVertices
in interface Graph
vertices
- vertices to be removed from this graph.Graph.removeAllVertices(Collection)
public java.lang.String toString()
toString
in class java.lang.Object
protected boolean assertVertexExist(java.lang.Object v)
v
- vertextrue
if this assertion holds.java.lang.NullPointerException
- if specified vertex is null
.java.lang.IllegalArgumentException
- if specified vertex does not exist in
this graph.protected boolean removeAllEdges(Edge[] edges)
Graph.removeEdge(Edge)
method.edges
- edges to be removed from this graph.Graph.removeEdge(Edge)
,
Graph.containsEdge(Edge)
protected java.lang.String toStringFromSets(java.util.Collection vertexSet, java.util.Collection edgeSet)
vertexSet
- the vertex set V to be printededgeSet
- the edge set E to be printed