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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add given vertex to the graph.protected abstract EdgeType
allocateEdge
(VertexType source, VertexType target) boolean
Determine 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.int
Get the number of numeric labels that have been assigned to edges.int
Get number of edges in the graph.int
getNumIncomingEdges
(VertexType vertex) Get number of edges going into given vertex.int
getNumOutgoingEdges
(VertexType vertex) Get number of edges going out of given vertex.int
Get the number of numeric (integer) labels that have been assigned to vertices in the graph.int
Get 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.void
removeEdge
(EdgeType edge) Remove given edge from the graph.void
Remove given vertex from the graph.void
setNumEdgeLabels
(int numLabels) Reset the number of edge labels.void
setNumVertexLabels
(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:Graph
Get number of edges in the graph.- Specified by:
getNumEdges
in interfaceGraph<EdgeType extends AbstractEdge<EdgeType,
VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
getNumVertices
public int getNumVertices()Description copied from interface:Graph
Get number of vertices in the graph.- Specified by:
getNumVertices
in interfaceGraph<EdgeType extends AbstractEdge<EdgeType,
VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
edgeIterator
Description copied from interface:Graph
Get Iterator over all edges in the graph.- Specified by:
edgeIterator
in interfaceGraph<EdgeType extends AbstractEdge<EdgeType,
VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
vertexIterator
Description copied from interface:Graph
Get Iterator over all vertices in the graph.- Specified by:
vertexIterator
in interfaceGraph<EdgeType extends AbstractEdge<EdgeType,
VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
vertices
-
addVertex
Description copied from interface:Graph
Add given vertex to the graph. The vertex should not be part of any other graph.- Specified by:
addVertex
in interfaceGraph<EdgeType extends AbstractEdge<EdgeType,
VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>> - Parameters:
v
- the vertex to add
-
containsVertex
Description copied from interface:Graph
Determine if the graph contains the given vertex.- Specified by:
containsVertex
in 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:Graph
Add a new edge to the graph. Duplicate edges (with same source and target vertices) are allowed.- Specified by:
createEdge
in 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:Graph
Look up an edge by source and target vertex. If multiple edges with same source and target vertex exist, one is selected arbitrarily.- Specified by:
lookupEdge
in 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:Graph
Get 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:
getNumVertexLabels
in interfaceGraph<EdgeType extends AbstractEdge<EdgeType,
VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
setNumVertexLabels
public void setNumVertexLabels(int numLabels) Description copied from interface:Graph
Reset number of (integer) labels. This might be necessary if an algorithm has assigned new labels to a graph's vertices.- Specified by:
setNumVertexLabels
in interfaceGraph<EdgeType extends AbstractEdge<EdgeType,
VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
getNumEdgeLabels
public int getNumEdgeLabels()Description copied from interface:Graph
Get the number of numeric labels that have been assigned to edges.- Specified by:
getNumEdgeLabels
in interfaceGraph<EdgeType extends AbstractEdge<EdgeType,
VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
setNumEdgeLabels
public void setNumEdgeLabels(int numLabels) Description copied from interface:Graph
Reset the number of edge labels.- Specified by:
setNumEdgeLabels
in interfaceGraph<EdgeType extends AbstractEdge<EdgeType,
VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
removeEdge
Description copied from interface:Graph
Remove given edge from the graph.- Specified by:
removeEdge
in interfaceGraph<EdgeType extends AbstractEdge<EdgeType,
VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
removeVertex
Description copied from interface:Graph
Remove given vertex from the graph. Note that all edges referencing the vertex will be removed.- Specified by:
removeVertex
in interfaceGraph<EdgeType extends AbstractEdge<EdgeType,
VertexType>, VertexType extends AbstractVertex<EdgeType, VertexType>>
-
outgoingEdgeIterator
Description copied from interface:Graph
Get an Iterator over outgoing edges from given vertex.- Specified by:
outgoingEdgeIterator
in 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:Graph
Get an Iterator over incoming edges to a given vertex.- Specified by:
incomingEdgeIterator
in 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:Graph
Get number of edges going into given vertex.- Specified by:
getNumIncomingEdges
in 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:Graph
Get number of edges going out of given vertex.- Specified by:
getNumOutgoingEdges
in 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:Graph
Get an iterator over the successors of this vertex; i.e., the targets of the vertex's outgoing edges.- Specified by:
successorIterator
in 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:Graph
Get an iterator over the predecessors of this vertex; i.e., the sources of the vertex's incoming edges.- Specified by:
predecessorIterator
in 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
-