Package edu.umd.cs.findbugs.graph
Class AbstractGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>,VertexType extends AbstractVertex<EdgeType,VertexType>>
java.lang.Object
edu.umd.cs.findbugs.graph.AbstractGraph<EdgeType,VertexType>
- All Implemented Interfaces:
Graph<EdgeType,VertexType>
- Direct Known Subclasses:
CallGraph,CFG,ConstraintGraph,InheritanceGraph,InterproceduralCallGraph
public abstract class AbstractGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>,VertexType extends AbstractVertex<EdgeType,VertexType>>
extends Object
implements Graph<EdgeType,VertexType>
A simple Graph implementation where the vertex objects store a list of
incoming and outgoing edges. The edge link fields are stored in the edge
objects, which means a fairly low space overhead.
The abstract allocateEdge() method must be implemented.
- Author:
- David Hovemeyer
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd given vertex to the graph.protected abstract EdgeTypeallocateEdge(VertexType source, VertexType target) booleanDetermine if the graph contains the given vertex.createEdge(VertexType source, VertexType target) Add a new edge to the graph.Get Iterator over all edges in the graph.intGet the number of numeric labels that have been assigned to edges.intGet number of edges in the graph.intgetNumIncomingEdges(VertexType vertex) Get number of edges going into given vertex.intgetNumOutgoingEdges(VertexType vertex) Get number of edges going out of given vertex.intGet the number of numeric (integer) labels that have been assigned to vertices in the graph.intGet number of vertices in the graph.incomingEdgeIterator(VertexType target) Get an Iterator over incoming edges to a given vertex.lookupEdge(VertexType source, VertexType target) Look up an edge by source and target vertex.outgoingEdgeIterator(VertexType source) Get an Iterator over outgoing edges from given vertex.predecessorIterator(VertexType target) Get an iterator over the predecessors of this vertex; i.e., the sources of the vertex's incoming edges.voidremoveEdge(EdgeType edge) Remove given edge from the graph.voidRemove given vertex from the graph.voidsetNumEdgeLabels(int numLabels) Reset the number of edge labels.voidsetNumVertexLabels(int numLabels) Reset number of (integer) labels.successorIterator(VertexType source) Get an iterator over the successors of this vertex; i.e., the targets of the vertex's outgoing edges.Get Iterator over all vertices in the graph.vertices()
-
Constructor Details
-
AbstractGraph
public AbstractGraph()
-
-
Method Details
-
getNumEdges
public int getNumEdges()Description copied from interface:GraphGet number of edges in the graph.- Specified by:
getNumEdgesin interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
getNumVertices
public int getNumVertices()Description copied from interface:GraphGet number of vertices in the graph.- Specified by:
getNumVerticesin interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
edgeIterator
Description copied from interface:GraphGet Iterator over all edges in the graph.- Specified by:
edgeIteratorin interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
vertexIterator
Description copied from interface:GraphGet Iterator over all vertices in the graph.- Specified by:
vertexIteratorin interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
vertices
-
addVertex
Description copied from interface:GraphAdd given vertex to the graph. The vertex should not be part of any other graph.- Specified by:
addVertexin interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>> - Parameters:
v- the vertex to add
-
containsVertex
Description copied from interface:GraphDetermine if the graph contains the given vertex.- Specified by:
containsVertexin interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>> - Parameters:
v- the vertex- Returns:
- true if the vertex is part of the graph, false if not
-
createEdge
Description copied from interface:GraphAdd a new edge to the graph. Duplicate edges (with same source and target vertices) are allowed.- Specified by:
createEdgein interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>> - Parameters:
source- the source vertextarget- the target vertex- Returns:
- the new edge
-
lookupEdge
Description copied from interface:GraphLook up an edge by source and target vertex. If multiple edges with same source and target vertex exist, one is selected arbitrarily.- Specified by:
lookupEdgein interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>> - Parameters:
source- the source vertextarget- the target vertex- Returns:
- a matching edge, or null if there is no matching edge
-
getNumVertexLabels
public int getNumVertexLabels()Description copied from interface:GraphGet the number of numeric (integer) labels that have been assigned to vertices in the graph. All vertices in the graph are guaranteed to have labels in the range 0..n, where n is the value returned by this method.- Specified by:
getNumVertexLabelsin interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
setNumVertexLabels
public void setNumVertexLabels(int numLabels) Description copied from interface:GraphReset number of (integer) labels. This might be necessary if an algorithm has assigned new labels to a graph's vertices.- Specified by:
setNumVertexLabelsin interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
getNumEdgeLabels
public int getNumEdgeLabels()Description copied from interface:GraphGet the number of numeric labels that have been assigned to edges.- Specified by:
getNumEdgeLabelsin interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
setNumEdgeLabels
public void setNumEdgeLabels(int numLabels) Description copied from interface:GraphReset the number of edge labels.- Specified by:
setNumEdgeLabelsin interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
removeEdge
Description copied from interface:GraphRemove given edge from the graph.- Specified by:
removeEdgein interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
removeVertex
Description copied from interface:GraphRemove given vertex from the graph. Note that all edges referencing the vertex will be removed.- Specified by:
removeVertexin interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
outgoingEdgeIterator
Description copied from interface:GraphGet an Iterator over outgoing edges from given vertex.- Specified by:
outgoingEdgeIteratorin interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>> - Parameters:
source- the source vertex- Returns:
- an Iterator over outgoing edges
-
incomingEdgeIterator
Description copied from interface:GraphGet an Iterator over incoming edges to a given vertex.- Specified by:
incomingEdgeIteratorin interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>> - Parameters:
target- the target vertex- Returns:
- an Iterator over incoming edges
-
getNumIncomingEdges
Description copied from interface:GraphGet number of edges going into given vertex.- Specified by:
getNumIncomingEdgesin interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>> - Parameters:
vertex- the vertex- Returns:
- number of edges going into the vertex
-
getNumOutgoingEdges
Description copied from interface:GraphGet number of edges going out of given vertex.- Specified by:
getNumOutgoingEdgesin interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>> - Parameters:
vertex- the vertex- Returns:
- number of edges going out of the vertex
-
successorIterator
Description copied from interface:GraphGet an iterator over the successors of this vertex; i.e., the targets of the vertex's outgoing edges.- Specified by:
successorIteratorin interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>> - Parameters:
source- the source vertex- Returns:
- an Iterator over the successors of the vertex
-
predecessorIterator
Description copied from interface:GraphGet an iterator over the predecessors of this vertex; i.e., the sources of the vertex's incoming edges.- Specified by:
predecessorIteratorin interfaceGraph<EdgeType extends AbstractEdge<EdgeType,VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>> - Parameters:
target- the target vertex- Returns:
- an Iterator over the predecessors of the vertex
-
allocateEdge
-