org._3pq.jgrapht.graph

Class AbstractBaseGraph

Implemented Interfaces:
Cloneable, Graph, Serializable
Known Direct Subclasses:
DefaultDirectedGraph, DirectedMultigraph, Multigraph, Pseudograph, SimpleDirectedGraph, SimpleGraph

public abstract class AbstractBaseGraph
extends AbstractGraph
implements Graph, Cloneable, Serializable

The most general implementation of the Graph interface. Its subclasses add various restrictions to get more specific graphs. The decision whether it is directed or undirected is decided at construction time and cannot be later modified (see constructor for details).

This graph implementation guarantees deterministic vertex and edge set ordering (via LinkedHashMap and LinkedHashSet).

Author:
Barak Naveh
Since:
Jul 24, 2003

Constructor Summary

AbstractBaseGraph(EdgeFactory ef, boolean allowMultipleEdges, boolean allowLoops)
Construct a new pseudograph.

Method Summary

Edge
addEdge(Object sourceVertex, Object targetVertex)
boolean
addEdge(Edge e)
boolean
addVertex(Object v)
Object
clone()
Returns a shallow copy of this graph instance.
boolean
containsEdge(Edge e)
boolean
containsVertex(Object v)
int
degreeOf(Object vertex)
Set
edgeSet()
List
edgesOf(Object vertex)
List
getAllEdges(Object sourceVertex, Object targetVertex)
Edge
getEdge(Object sourceVertex, Object targetVertex)
EdgeFactory
getEdgeFactory()
int
inDegreeOf(Object vertex)
List
incomingEdgesOf(Object vertex)
boolean
isAllowingLoops()
Returns true if and only if self-loops are allowed in this graph.
boolean
isAllowingMultipleEdges()
Returns true if and only if multiple edges are allowed in this graph.
int
outDegreeOf(Object vertex)
List
outgoingEdgesOf(Object vertex)
Edge
removeEdge(Object sourceVertex, Object targetVertex)
boolean
removeEdge(Edge e)
boolean
removeVertex(Object v)
void
setEdgeListFactory(EdgeListFactory edgeListFactory)
Set the EdgeListFactory to use for this graph.
Set
vertexSet()

Methods inherited from class org._3pq.jgrapht.graph.AbstractGraph

addAllEdges, addAllVertices, assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets

Constructor Details

AbstractBaseGraph

public AbstractBaseGraph(EdgeFactory ef,
                         boolean allowMultipleEdges,
                         boolean allowLoops)
Construct a new pseudograph. The pseudograph can either be directed or undirected, depending on the specified edge factory. A sample edge is created using the edge factory to see if the factory is compatible with this class of graph. For example, if this graph is a DirectedGraph the edge factory must produce DirectedEdges. If this is not the case, an IllegalArgumentException is thrown.
Parameters:
ef - the edge factory of the new graph.
allowMultipleEdges - whether to allow multiple edges or not.
allowLoops - whether to allow edges that are self-loops or not.

Method Details

addEdge

public Edge addEdge(Object sourceVertex,
                    Object targetVertex)
Specified by:
addEdge in interface Graph

addEdge

public boolean addEdge(Edge e)
Specified by:
addEdge in interface Graph

addVertex

public boolean addVertex(Object v)
Specified by:
addVertex in interface Graph

clone

public Object clone()
Returns a shallow copy of this graph instance. Neither edges nor vertices are cloned.
Returns:
a shallow copy of this set.
See Also:
java.lang.Object.clone()

containsEdge

public boolean containsEdge(Edge e)
Specified by:
containsEdge in interface Graph

containsVertex

public boolean containsVertex(Object v)
Specified by:
containsVertex in interface Graph

degreeOf

public int degreeOf(Object vertex)
See Also:
org._3pq.jgrapht.UndirectedGraph.degreeOf(java.lang.Object)

edgeSet

public Set edgeSet()
Specified by:
edgeSet in interface Graph

edgesOf

public List edgesOf(Object vertex)
Specified by:
edgesOf in interface Graph

getAllEdges

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

getEdge

public Edge getEdge(Object sourceVertex,
                    Object targetVertex)
Specified by:
getEdge in interface Graph

getEdgeFactory

public EdgeFactory getEdgeFactory()
Specified by:
getEdgeFactory in interface Graph

inDegreeOf

public int inDegreeOf(Object vertex)
See Also:
org._3pq.jgrapht.DirectedGraph.inDegreeOf(java.lang.Object)

incomingEdgesOf

public List incomingEdgesOf(Object vertex)
See Also:
org._3pq.jgrapht.DirectedGraph.incomingEdgesOf(java.lang.Object)

isAllowingLoops

public boolean isAllowingLoops()
Returns true if and only if self-loops are allowed in this graph. A self loop is an edge that its source and target vertices are the same.
Returns:
true if and only if graph loops are allowed.

isAllowingMultipleEdges

public boolean isAllowingMultipleEdges()
Returns true if and only if multiple edges are allowed in this graph. The meaning of multiple edges is that there can be many edges going from vertex v1 to vertex v2.
Returns:
true if and only if multiple edges are allowed.

outDegreeOf

public int outDegreeOf(Object vertex)
See Also:
org._3pq.jgrapht.DirectedGraph.outDegreeOf(java.lang.Object)

outgoingEdgesOf

public List outgoingEdgesOf(Object vertex)
See Also:
org._3pq.jgrapht.DirectedGraph.outgoingEdgesOf(java.lang.Object)

removeEdge

public Edge removeEdge(Object sourceVertex,
                       Object targetVertex)
Specified by:
removeEdge in interface Graph

removeEdge

public boolean removeEdge(Edge e)
Specified by:
removeEdge in interface Graph

removeVertex

public boolean removeVertex(Object v)
Specified by:
removeVertex in interface Graph

setEdgeListFactory

public void setEdgeListFactory(EdgeListFactory edgeListFactory)
Set the EdgeListFactory to use for this graph. Initially, a graph is created with a default implementation which always supplies an java.util.ArrayList with capacity 1.
Parameters:
edgeListFactory - factory to use for subsequently created edge lists (this call has no effect on existing edge lists)

vertexSet

public Set vertexSet()
Specified by:
vertexSet in interface Graph