- java.lang.Object
-
- org.jgrapht.graph.specifics.DirectedSpecifics<V,E>
-
- Type Parameters:
V- the graph vertex typeE- 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, useFastLookupDirectedSpecifics.- Author:
- Barak Naveh, Joris Kinable
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected EdgeSetFactory<V,E>edgeSetFactoryprotected Graph<V,E>graphprotected Map<V,DirectedEdgeContainer<V,E>>vertexMap
-
Constructor Summary
Constructors Constructor Description DirectedSpecifics(Graph<V,E> graph, Map<V,DirectedEdgeContainer<V,E>> vertexMap, EdgeSetFactory<V,E> edgeSetFactory)Construct a new directed specifics.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddEdgeToTouchingVertices(V sourceVertex, V targetVertex, E e)Adds the specified edge to the edge containers of its source and target vertices.booleanaddEdgeToTouchingVerticesIfAbsent(V sourceVertex, V targetVertex, E e)Adds the specified edge to the edge containers of its source and target vertices only if the edge is not already in the graph.booleanaddVertex(V v)Adds a vertex.EcreateEdgeToTouchingVerticesIfAbsent(V sourceVertex, V targetVertex, Supplier<E> edgeSupplier)Creates an edge given an edge supplier and adds it to the edge containers of its source and target vertices only if the graph does not contain other edges with the same source and target vertices.intdegreeOf(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.EgetEdge(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.intinDegreeOf(V vertex)Returns the "in degree" of the specified vertex.intoutDegreeOf(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.voidremoveEdgeFromTouchingVertices(V sourceVertex, V targetVertex, E e)Removes the specified edge from the edge containers of its source and target vertices.
-
-
-
Constructor Detail
-
DirectedSpecifics
public DirectedSpecifics(Graph<V,E> graph, Map<V,DirectedEdgeContainer<V,E>> vertexMap, EdgeSetFactory<V,E> edgeSetFactory)
Construct a new directed specifics.- Parameters:
graph- the graph for which these specifics are forvertexMap- map for the storage of vertex edge sets. Needs to have a predictable iteration order.edgeSetFactory- factory for the creation of vertex edge sets
-
-
Method Detail
-
addVertex
public boolean addVertex(V v)
Adds a vertex.
-
getVertexSet
public Set<V> getVertexSet()
Get the vertex set.- Specified by:
getVertexSetin interfaceSpecifics<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 isnull, returnsnull. If both vertices exist but no edges found, returns an empty set.- Specified by:
getAllEdgesin interfaceSpecifics<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 returnsnull. If any of the specified vertices isnullreturnsnullIn undirected graphs, the returned edge may have its source and target vertices in the opposite order.
-
addEdgeToTouchingVertices
public boolean addEdgeToTouchingVertices(V sourceVertex, V targetVertex, E e)
Adds the specified edge to the edge containers of its source and target vertices.- Specified by:
addEdgeToTouchingVerticesin interfaceSpecifics<V,E>- Parameters:
sourceVertex- the source vertextargetVertex- the target vertexe- the edge- Returns:
- true if the edge was added, false otherwise
-
addEdgeToTouchingVerticesIfAbsent
public boolean addEdgeToTouchingVerticesIfAbsent(V sourceVertex, V targetVertex, E e)
Description copied from interface:SpecificsAdds the specified edge to the edge containers of its source and target vertices only if the edge is not already in the graph.- Specified by:
addEdgeToTouchingVerticesIfAbsentin interfaceSpecifics<V,E>- Parameters:
sourceVertex- the source vertextargetVertex- the target vertexe- the edge- Returns:
- true if the edge was added, false otherwise
-
createEdgeToTouchingVerticesIfAbsent
public E createEdgeToTouchingVerticesIfAbsent(V sourceVertex, V targetVertex, Supplier<E> edgeSupplier)
Description copied from interface:SpecificsCreates an edge given an edge supplier and adds it to the edge containers of its source and target vertices only if the graph does not contain other edges with the same source and target vertices.- Specified by:
createEdgeToTouchingVerticesIfAbsentin interfaceSpecifics<V,E>- Parameters:
sourceVertex- the source vertextargetVertex- the target vertexedgeSupplier- the function which will create the edge- Returns:
- the newly created edge or null if an edge with the same source and target vertices was already present
-
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.
-
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.
-
inDegreeOf
public int inDegreeOf(V vertex)
Returns the "in degree" of the specified vertex.- Specified by:
inDegreeOfin interfaceSpecifics<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:
incomingEdgesOfin interfaceSpecifics<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:
outDegreeOfin interfaceSpecifics<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:
outgoingEdgesOfin interfaceSpecifics<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(V sourceVertex, V targetVertex, E e)
Removes the specified edge from the edge containers of its source and target vertices.- Specified by:
removeEdgeFromTouchingVerticesin interfaceSpecifics<V,E>- Parameters:
sourceVertex- the source vertextargetVertex- the target vertexe- 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
-
-