Package org.pf4j.util
Class DirectedGraph<V>
java.lang.Object
org.pf4j.util.DirectedGraph<V>
See Wikipedia for more information.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add an edge to the graph; if either vertex does not exist, it's added.void
Add a vertex to the graph.boolean
containsVertex
(V vertex) True if graph contains vertex.getNeighbors
(V vertex) inDegree()
Report (as aMap
) the in-degree (the number of head ends adjacent to a vertex) of each vertex.boolean
isDag()
True if graph is a dag (directed acyclic graph).Report (as a Map) the out-degree (the number of tail ends adjacent to a vertex) of each vertex.void
removeEdge
(V from, V to) Remove an edge from the graph.void
removeVertex
(V vertex) Report (as a List) the reverse topological sort of the vertices; null for no such sort.Report (as a List) the topological sort of the vertices; null for no such sort.toString()
String representation of graph.
-
Field Details
-
neighbors
The implementation here is basically an adjacency list, but instead of an array of lists, a Map is used to map each vertex to its list of adjacent vertices.
-
-
Constructor Details
-
DirectedGraph
public DirectedGraph()
-
-
Method Details
-
addVertex
Add a vertex to the graph. Nothing happens if vertex is already in graph. -
containsVertex
True if graph contains vertex. -
removeVertex
-
addEdge
Add an edge to the graph; if either vertex does not exist, it's added. This implementation allows the creation of multi-edges and self-loops. -
removeEdge
Remove an edge from the graph. Nothing happens if no such edge. -
getNeighbors
-
outDegree
Report (as a Map) the out-degree (the number of tail ends adjacent to a vertex) of each vertex. -
inDegree
Report (as aMap
) the in-degree (the number of head ends adjacent to a vertex) of each vertex. -
topologicalSort
Report (as a List) the topological sort of the vertices; null for no such sort. See this for more information. -
reverseTopologicalSort
Report (as a List) the reverse topological sort of the vertices; null for no such sort. -
isDag
public boolean isDag()True if graph is a dag (directed acyclic graph). -
toString
String representation of graph.
-