Package org.pf4j.util

Class DirectedGraph<V>

java.lang.Object
org.pf4j.util.DirectedGraph<V>

public class DirectedGraph<V> extends Object
See Wikipedia for more information.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Map<V,List<V>>
    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 Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addEdge(V from, V to)
    Add an edge to the graph; if either vertex does not exist, it's added.
    void
    addVertex(V vertex)
    Add a vertex to the graph.
    boolean
    containsVertex(V vertex)
    True if graph contains vertex.
    getNeighbors(V vertex)
     
    Report (as a Map) the in-degree (the number of head ends adjacent to a vertex) of each vertex.
    boolean
    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.
    String representation of graph.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • neighbors

      private Map<V,List<V>> 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

      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.
    • getNeighbors

      public List<V> getNeighbors(V vertex)
    • outDegree

      public Map<V,Integer> outDegree()
      Report (as a Map) the out-degree (the number of tail ends adjacent to a vertex) of each vertex.
    • inDegree

      public Map<V,Integer> inDegree()
      Report (as a Map) the in-degree (the number of head ends adjacent to a vertex) of each vertex.
    • topologicalSort

      public 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 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 String toString()
      String representation of graph.
      Overrides:
      toString in class Object