Package org.pf4j.util

Class DirectedGraph<V>


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

      Fields 
      Modifier and Type Field Description
      private java.util.Map<V,​java.util.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 Summary

      Constructors 
      Constructor Description
      DirectedGraph()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      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.
      java.util.List<V> getNeighbors​(V vertex)  
      java.util.Map<V,​java.lang.Integer> inDegree()
      Report (as a Map) 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).
      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.
      void removeEdge​(V from, V to)
      Remove an edge from the graph.
      void removeVertex​(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.String toString()
      String representation of graph.
      • Methods inherited from class java.lang.Object

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

      • neighbors

        private java.util.Map<V,​java.util.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 Detail

      • DirectedGraph

        public DirectedGraph()
    • 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.
      • getNeighbors

        public java.util.List<V> getNeighbors​(V vertex)
      • 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 a Map) 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:
        toString in class java.lang.Object