org._3pq.jgrapht.graph

Class AbstractGraph

Implemented Interfaces:
Graph
Known Direct Subclasses:
AbstractBaseGraph, GraphDelegator, Subgraph

public abstract class AbstractGraph
extends java.lang.Object
implements Graph

A skeletal implementation of the Graph interface, to minimize the effort required to implement graph interfaces. This implementation is applicable to both: directed graphs and undirected graphs.
Author:
Barak Naveh
See Also:
Graph, DirectedGraph, UndirectedGraph

Constructor Summary

AbstractGraph()
Construct a new empty graph object.

Method Summary

boolean
addAllEdges(Collection edges)
boolean
addAllVertices(Collection vertices)
protected boolean
assertVertexExist(Object v)
Ensures that the specified vertex exists in this graph, or else throws exception.
boolean
containsEdge(Object sourceVertex, Object targetVertex)
boolean
removeAllEdges(Collection edges)
List
removeAllEdges(Object sourceVertex, Object targetVertex)
protected boolean
removeAllEdges(Edge[] edges)
Removes all the edges in this graph that are also contained in the specified edge array.
boolean
removeAllVertices(Collection vertices)
String
toString()
Returns a string of the parenthesized pair (V, E) representing this G=(V,E) graph.
protected String
toStringFromSets(Collection vertexSet, Collection edgeSet)
Helper for subclass implementations of toString( ).

Constructor Details

AbstractGraph

public AbstractGraph()
Construct a new empty graph object.

Method Details

addAllEdges

public boolean addAllEdges(Collection edges)
Specified by:
addAllEdges in interface Graph

addAllVertices

public boolean addAllVertices(Collection vertices)
Specified by:
addAllVertices in interface Graph

assertVertexExist

protected boolean assertVertexExist(Object v)
Ensures that the specified vertex exists in this graph, or else throws exception.
Parameters:
v - vertex
Returns:
true if this assertion holds.

containsEdge

public boolean containsEdge(Object sourceVertex,
                            Object targetVertex)
Specified by:
containsEdge in interface Graph

removeAllEdges

public boolean removeAllEdges(Collection edges)
Specified by:
removeAllEdges in interface Graph

removeAllEdges

public List removeAllEdges(Object sourceVertex,
                           Object targetVertex)
Specified by:
removeAllEdges in interface Graph

removeAllEdges

protected boolean removeAllEdges(Edge[] edges)
Removes all the edges in this graph that are also contained in the specified edge array. After this call returns, this graph will contain no edges in common with the specified edges. This method will invoke the Graph.removeEdge(Edge) method.
Parameters:
edges - edges to be removed from this graph.
Returns:
true if this graph changed as a result of the call.

removeAllVertices

public boolean removeAllVertices(Collection vertices)
Specified by:
removeAllVertices in interface Graph

toString

public String toString()
Returns a string of the parenthesized pair (V, E) representing this G=(V,E) graph. 'V' is the string representation of the vertex set, and 'E' is the string representation of the edge set.
Returns:
a string representation of this graph.

toStringFromSets

protected String toStringFromSets(Collection vertexSet,
                                  Collection edgeSet)
Helper for subclass implementations of toString( ).
Parameters:
vertexSet - the vertex set V to be printed
edgeSet - the edge set E to be printed
Returns:
a string representation of (V,E)