Class StandardMutableValueGraph<N,V>

Type Parameters:
N - Node parameter type
V - Value parameter type
All Implemented Interfaces:
BaseGraph<N>, MutableValueGraph<N,V>, PredecessorsFunction<N>, SuccessorsFunction<N>, ValueGraph<N,V>

final class StandardMutableValueGraph<N,V> extends StandardValueGraph<N,V> implements MutableValueGraph<N,V>
Standard implementation of MutableValueGraph that supports both directed and undirected graphs. Instances of this class should be constructed with ValueGraphBuilder.

Time complexities for mutation methods are all O(1) except for removeNode(N node), which is in O(d_node) where d_node is the degree of node.

  • Field Details

    • incidentEdgeOrder

      private final ElementOrder<N> incidentEdgeOrder
  • Constructor Details

    • StandardMutableValueGraph

      StandardMutableValueGraph(AbstractGraphBuilder<? super N> builder)
      Constructs a mutable graph with the properties specified in builder.
  • Method Details

    • incidentEdgeOrder

      public ElementOrder<N> incidentEdgeOrder()
      Description copied from interface: BaseGraph
      Specified by:
      incidentEdgeOrder in interface BaseGraph<N>
      Specified by:
      incidentEdgeOrder in interface ValueGraph<N,V>
      Overrides:
      incidentEdgeOrder in class AbstractBaseGraph<N>
    • addNode

      public boolean addNode(N node)
      Description copied from interface: MutableValueGraph
      Adds node if it is not already present.

      Nodes must be unique, just as Map keys must be. They must also be non-null.

      Specified by:
      addNode in interface MutableValueGraph<N,V>
      Returns:
      true if the graph was modified as a result of this call
    • addNodeInternal

      private GraphConnections<N,V> addNodeInternal(N node)
      Adds node to the graph and returns the associated GraphConnections.
      Throws:
      IllegalStateException - if node is already present
    • putEdgeValue

      @CheckForNull public V putEdgeValue(N nodeU, N nodeV, V value)
      Description copied from interface: MutableValueGraph
      Adds an edge connecting nodeU to nodeV if one is not already present, and sets a value for that edge to value (overwriting the existing value, if any).

      If the graph is directed, the resultant edge will be directed; otherwise, it will be undirected.

      Values do not have to be unique. However, values must be non-null.

      If nodeU and nodeV are not already present in this graph, this method will silently add nodeU and nodeV to the graph.

      Specified by:
      putEdgeValue in interface MutableValueGraph<N,V>
      Returns:
      the value previously associated with the edge connecting nodeU to nodeV, or null if there was no such edge.
    • putEdgeValue

      @CheckForNull public V putEdgeValue(EndpointPair<N> endpoints, V value)
      Description copied from interface: MutableValueGraph
      Adds an edge connecting endpoints if one is not already present, and sets a value for that edge to value (overwriting the existing value, if any).

      If the graph is directed, the resultant edge will be directed; otherwise, it will be undirected.

      If this graph is directed, endpoints must be ordered.

      Values do not have to be unique. However, values must be non-null.

      If either or both endpoints are not already present in this graph, this method will silently add each missing endpoint to the graph.

      Specified by:
      putEdgeValue in interface MutableValueGraph<N,V>
      Returns:
      the value previously associated with the edge connecting nodeU to nodeV, or null if there was no such edge.
    • removeNode

      public boolean removeNode(N node)
      Description copied from interface: MutableValueGraph
      Removes node if it is present; all edges incident to node will also be removed.
      Specified by:
      removeNode in interface MutableValueGraph<N,V>
      Returns:
      true if the graph was modified as a result of this call
    • removeEdge

      @CheckForNull public V removeEdge(N nodeU, N nodeV)
      Description copied from interface: MutableValueGraph
      Removes the edge connecting nodeU to nodeV, if it is present.
      Specified by:
      removeEdge in interface MutableValueGraph<N,V>
      Returns:
      the value previously associated with the edge connecting nodeU to nodeV, or null if there was no such edge.
    • removeEdge

      @CheckForNull public V removeEdge(EndpointPair<N> endpoints)
      Description copied from interface: MutableValueGraph
      Removes the edge connecting endpoints, if it is present.

      If this graph is directed, endpoints must be ordered.

      Specified by:
      removeEdge in interface MutableValueGraph<N,V>
      Returns:
      the value previously associated with the edge connecting endpoints, or null if there was no such edge.
    • newConnections

      private GraphConnections<N,V> newConnections()