org.jgrapht.graph.specifics

## Class DirectedSpecifics<V,E>

• Type Parameters:
V - the graph vertex type
E - the graph edge type
All Implemented Interfaces:
Serializable, Specifics<V,E>
Direct Known Subclasses:
FastLookupDirectedSpecifics

public class DirectedSpecifics<V,E>
extends Object
implements Specifics<V,E>, Serializable
Plain implementation of DirectedSpecifics. This implementation requires the least amount of memory, at the expense of slow edge retrievals. Methods which depend on edge retrievals, e.g. getEdge(V u, V v), containsEdge(V u, V v), addEdge(V u, V v), etc may be relatively slow when the average degree of a vertex is high (dense graphs). For a fast implementation, use FastLookupDirectedSpecifics.
Author:
Barak Naveh, Joris Kinable
Serialized Form
• ### Field Summary

Fields
Modifier and Type Field and Description
protected AbstractBaseGraph<V,E> abstractBaseGraph
protected EdgeSetFactory<V,E> edgeSetFactory
protected Map<V,DirectedEdgeContainer<V,E>> vertexMapDirected
• ### Constructor Summary

Constructors
Constructor and Description
DirectedSpecifics(AbstractBaseGraph<V,E> abstractBaseGraph)
Construct a new directed specifics.
DirectedSpecifics(AbstractBaseGraph<V,E> abstractBaseGraph, Map<V,DirectedEdgeContainer<V,E>> vertexMap)
Construct a new directed specifics.
DirectedSpecifics(AbstractBaseGraph<V,E> abstractBaseGraph, Map<V,DirectedEdgeContainer<V,E>> vertexMap, EdgeSetFactory<V,E> edgeSetFactory)
Construct a new directed specifics.
• ### Method Summary

All Methods
Modifier and Type Method and Description
void addEdgeToTouchingVertices(E e)
Adds the specified edge to the edge containers of its source and target vertices.
boolean addVertex(V v)
int degreeOf(V vertex)
Returns the degree of the specified vertex.
Set<E> edgesOf(V vertex)
Returns a set of all edges touching the specified vertex.
Set<E> getAllEdges(V sourceVertex, V targetVertex)
Returns a set of all edges connecting source vertex to target vertex if such vertices exist in this graph.
E getEdge(V sourceVertex, V targetVertex)
Returns an edge connecting source vertex to target vertex if such vertices and such edge exist in this graph.
protected DirectedEdgeContainer<V,E> getEdgeContainer(V vertex)
Get the edge container for specified vertex.
Set<V> getVertexSet()
Get the vertex set.
Set<E> incomingEdgesOf(V vertex)
Returns a set of all edges incoming into the specified vertex.
int inDegreeOf(V vertex)
Returns the "in degree" of the specified vertex.
int outDegreeOf(V vertex)
Returns the "out degree" of the specified vertex.
Set<E> outgoingEdgesOf(V vertex)
Returns a set of all edges outgoing from the specified vertex.
void removeEdgeFromTouchingVertices(E e)
Removes the specified edge from the edge containers of its source and target vertices.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Field Detail

• #### abstractBaseGraph

protected AbstractBaseGraph<V,E> abstractBaseGraph
• #### vertexMapDirected

protected Map<V,DirectedEdgeContainer<V,E>> vertexMapDirected
• #### edgeSetFactory

protected EdgeSetFactory<V,E> edgeSetFactory
• ### Constructor Detail

• #### DirectedSpecifics

public DirectedSpecifics(AbstractBaseGraph<V,E> abstractBaseGraph)
Construct a new directed specifics.
Parameters:
abstractBaseGraph - the graph for which these specifics are for
• #### DirectedSpecifics

public DirectedSpecifics(AbstractBaseGraph<V,E> abstractBaseGraph,
Map<V,DirectedEdgeContainer<V,E>> vertexMap)
Construct a new directed specifics.
Parameters:
abstractBaseGraph - the graph for which these specifics are for
vertexMap - map for the storage of vertex edge sets
• #### DirectedSpecifics

public DirectedSpecifics(AbstractBaseGraph<V,E> abstractBaseGraph,
Map<V,DirectedEdgeContainer<V,E>> vertexMap,
EdgeSetFactory<V,E> edgeSetFactory)
Construct a new directed specifics.
Parameters:
abstractBaseGraph - the graph for which these specifics are for
vertexMap - map for the storage of vertex edge sets
edgeSetFactory - factory for the creation of vertex edge sets
• ### Method Detail

public boolean addVertex(V v)
Specified by:
addVertex in interface Specifics<V,E>
Parameters:
v - vertex to be added.
Returns:
true if the vertex was added, false if the vertex was already present
• #### getVertexSet

public Set<V> getVertexSet()
Get the vertex set.
Specified by:
getVertexSet in interface Specifics<V,E>
Returns:
the vertex set
• #### getAllEdges

public Set<E> getAllEdges(V sourceVertex,
V targetVertex)
Returns a set of all edges connecting source vertex to target vertex if such vertices exist in this graph. If any of the vertices does not exist or is null, returns null. If both vertices exist but no edges found, returns an empty set.
Specified by:
getAllEdges in interface Specifics<V,E>
Parameters:
sourceVertex - source vertex of the edge.
targetVertex - target vertex of the edge.
Returns:
a set of all edges connecting source vertex to target vertex.
• #### getEdge

public E getEdge(V sourceVertex,
V targetVertex)
Returns an edge connecting source vertex to target vertex if such vertices and such edge exist in this graph. Otherwise returns  null. If any of the specified vertices is null returns null

In undirected graphs, the returned edge may have its source and target vertices in the opposite order.

Specified by:
getEdge in interface Specifics<V,E>
Parameters:
sourceVertex - source vertex of the edge.
targetVertex - target vertex of the edge.
Returns:
an edge connecting source vertex to target vertex.

public void addEdgeToTouchingVertices(E e)
Adds the specified edge to the edge containers of its source and target vertices.
Specified by:
addEdgeToTouchingVertices in interface Specifics<V,E>
Parameters:
e - the edge
• #### degreeOf

public int degreeOf(V vertex)
Returns the degree of the specified vertex. A degree of a vertex in an undirected graph is the number of edges touching that vertex.
Specified by:
degreeOf in interface Specifics<V,E>
Parameters:
vertex - vertex whose degree is to be calculated.
Returns:
the degree of the specified vertex.
• #### edgesOf

public Set<E> edgesOf(V vertex)
Returns a set of all edges touching the specified vertex. If no edges are touching the specified vertex returns an empty set.
Specified by:
edgesOf in interface Specifics<V,E>
Parameters:
vertex - the vertex for which a set of touching edges is to be returned.
Returns:
a set of all edges touching the specified vertex.
• #### inDegreeOf

public int inDegreeOf(V vertex)
Returns the "in degree" of the specified vertex.
Specified by:
inDegreeOf in interface Specifics<V,E>
Parameters:
vertex - vertex whose in degree is to be calculated.
Returns:
the in degree of the specified vertex.
• #### incomingEdgesOf

public Set<E> incomingEdgesOf(V vertex)
Returns a set of all edges incoming into the specified vertex.
Specified by:
incomingEdgesOf in interface Specifics<V,E>
Parameters:
vertex - the vertex for which the list of incoming edges to be returned.
Returns:
a set of all edges incoming into the specified vertex.
• #### outDegreeOf

public int outDegreeOf(V vertex)
Returns the "out degree" of the specified vertex.
Specified by:
outDegreeOf in interface Specifics<V,E>
Parameters:
vertex - vertex whose out degree is to be calculated.
Returns:
the out degree of the specified vertex.
• #### outgoingEdgesOf

public Set<E> outgoingEdgesOf(V vertex)
Returns a set of all edges outgoing from the specified vertex.
Specified by:
outgoingEdgesOf in interface Specifics<V,E>
Parameters:
vertex - the vertex for which the list of outgoing edges to be returned.
Returns:
a set of all edges outgoing from the specified vertex.
• #### removeEdgeFromTouchingVertices

public void removeEdgeFromTouchingVertices(E e)
Removes the specified edge from the edge containers of its source and target vertices.
Specified by:
removeEdgeFromTouchingVertices in interface Specifics<V,E>
Parameters:
e - the edge
• #### getEdgeContainer

protected DirectedEdgeContainer<V,E> getEdgeContainer(V vertex)
Get the edge container for specified vertex.
Parameters:
vertex - a vertex in this graph.
Returns:
an edge container