Class DirectedGraph<D>


@DefaultQualifier(org.checkerframework.checker.nullness.qual.NonNull.class) public class DirectedGraph<@NonNull D> extends Object
A directed graph type for performing graph operations.
  • Constructor Details

    • DirectedGraph

      public DirectedGraph()
  • Method Details

    • getNodeCount

      public int getNodeCount()
      Gets the count of nodes in the graph.
    • getEdgeCount

      public int getEdgeCount()
      Gets the count of edges in the graph.
    • contains

      public boolean contains(@NonNull D data)
      Gets if the graph contains a node with the given data.
    • get

      public @Nullable DirectedGraph.DataNode<D> get(@NonNull D data)
      Gets the node corresponding to the given data.
    • addEdge

      public void addEdge(@NonNull D from, @NonNull D to)
      Adds a directed edge between the two given nodes. If either the start or the end data does not have a corresponding node in the graph then a new node is added.
    • getNodes

      public Collection<DirectedGraph.DataNode<D>> getNodes()
      Gets all nodes in the graph.
    • reverse

      public DirectedGraph<D> reverse()
      Returns a directed graph which represents the reverse of this graph. The reverse of a directed graph is a graph with the same nodes but the direction of each edge is reversed.
    • add

      public DirectedGraph.DataNode<D> add(@NonNull D d)
      Adds the given node to the graph.
    • remove

      public boolean remove(@NonNull D n)
      Deletes the given node from the graph, and all edges that originated from or connected to the node.
    • clear

      public void clear()
      Clears all nodes and edges from this graph.
    • toString

      public String toString()
      toString in class Object