Package org.pf4j.util
Class DirectedGraph<V>
- java.lang.Object
-
- org.pf4j.util.DirectedGraph<V>
-
public class DirectedGraph<V> extends java.lang.ObjectSee Wikipedia for more information.
-
-
Constructor Summary
Constructors Constructor Description DirectedGraph()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddEdge(V from, V to)Add an edge to the graph; if either vertex does not exist, it's added.voidaddVertex(V vertex)Add a vertex to the graph.booleancontainsVertex(V vertex)True if graph contains vertex.java.util.List<V>getNeighbors(V vertex)java.util.Map<V,java.lang.Integer>inDegree()Report (as aMap) the in-degree (the number of head ends adjacent to a vertex) of each vertex.booleanisDag()True if graph is a dag (directed acyclic graph).java.util.Map<V,java.lang.Integer>outDegree()Report (as a Map) the out-degree (the number of tail ends adjacent to a vertex) of each vertex.voidremoveEdge(V from, V to)Remove an edge from the graph.voidremoveVertex(V vertex)java.util.List<V>reverseTopologicalSort()Report (as a List) the reverse topological sort of the vertices; null for no such sort.java.util.List<V>topologicalSort()Report (as a List) the topological sort of the vertices; null for no such sort.java.lang.StringtoString()String representation of graph.
-
-
-
Method Detail
-
addVertex
public void addVertex(V vertex)
Add a vertex to the graph. Nothing happens if vertex is already in graph.
-
containsVertex
public boolean containsVertex(V vertex)
True if graph contains vertex.
-
removeVertex
public void removeVertex(V vertex)
-
addEdge
public void addEdge(V from, V to)
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
public void removeEdge(V from, V to)
Remove an edge from the graph. Nothing happens if no such edge.
-
outDegree
public java.util.Map<V,java.lang.Integer> outDegree()
Report (as a Map) the out-degree (the number of tail ends adjacent to a vertex) of each vertex.
-
inDegree
public java.util.Map<V,java.lang.Integer> inDegree()
Report (as aMap) the in-degree (the number of head ends adjacent to a vertex) of each vertex.
-
topologicalSort
public java.util.List<V> topologicalSort()
Report (as a List) the topological sort of the vertices; null for no such sort. See this for more information.
-
reverseTopologicalSort
public java.util.List<V> 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
public java.lang.String toString()
String representation of graph.- Overrides:
toStringin classjava.lang.Object
-
-