Interface MutableNetwork<N,​E>

    • Method Detail

      • addNode

        @CanIgnoreReturnValue
        boolean addNode​(N node)
        Adds node if it is not already present.

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

        Returns:
        true if the network was modified as a result of this call
      • addEdge

        @CanIgnoreReturnValue
        boolean addEdge​(N nodeU,
                        N nodeV,
                        E edge)
        Adds edge connecting nodeU to nodeV.

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

        edge must be unique to this graph, just as a Map key must be. It must also 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.

        If edge already connects nodeU to nodeV (in the specified order if this network isDirected(), else in any order), then this method will have no effect.

        Returns:
        true if the network was modified as a result of this call
        Throws:
        java.lang.IllegalArgumentException - if edge already exists in the graph and does not connect nodeU to nodeV
        java.lang.IllegalArgumentException - if the introduction of the edge would violate Network.allowsParallelEdges() or allowsSelfLoops()
      • addEdge

        @CanIgnoreReturnValue
        boolean addEdge​(EndpointPair<N> endpoints,
                        E edge)
        Adds edge connecting endpoints. In an undirected network, edge will also connect nodeV to nodeU.

        If this graph is directed, edge will be directed in this graph; if it is undirected, edge will be undirected in this graph.

        If this graph is directed, endpoints must be ordered.

        edge must be unique to this graph, just as a Map key must be. It must also 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.

        If edge already connects an endpoint pair equal to endpoints, then this method will have no effect.

        Returns:
        true if the network was modified as a result of this call
        Throws:
        java.lang.IllegalArgumentException - if edge already exists in the graph and connects some other endpoint pair that is not equal to endpoints
        java.lang.IllegalArgumentException - if the introduction of the edge would violate Network.allowsParallelEdges() or allowsSelfLoops()
        java.lang.IllegalArgumentException - if the endpoints are unordered and the graph is directed
        Since:
        27.1
      • removeNode

        @CanIgnoreReturnValue
        boolean removeNode​(N node)
        Removes node if it is present; all edges incident to node will also be removed.
        Returns:
        true if the network was modified as a result of this call
      • removeEdge

        @CanIgnoreReturnValue
        boolean removeEdge​(E edge)
        Removes edge from this network, if it is present.
        Returns:
        true if the network was modified as a result of this call
      • nodes

        java.util.Set<N> nodes()
        Returns all nodes in this graph, in the order specified by nodeOrder().
      • isDirected

        boolean isDirected()
        Returns true if the edges in this graph are directed. Directed edges connect a source node to a target node, while undirected edges connect a pair of nodes to each other.
      • allowsSelfLoops

        boolean allowsSelfLoops()
        Returns true if this graph allows self-loops (edges that connect a node to itself). Attempting to add a self-loop to a graph that does not allow them will throw an IllegalArgumentException.
      • nodeOrder

        ElementOrder<N> nodeOrder()
        Returns the order of iteration for the elements of nodes().
      • adjacentNodes

        java.util.Set<N> adjacentNodes​(N node)
        Returns a live view of the nodes which have an incident edge in common with node in this graph.

        This is equal to the union of PredecessorsFunction.predecessors(Object) and SuccessorsFunction.successors(Object).

        If node is removed from the graph after this method is called, the Set view returned by this method will be invalidated, and will throw IllegalStateException if it is accessed in any way, with the following exceptions:

        • view.equals(view) evaluates to true (but any other equals(...) expression involving view will throw)
        • hashCode() does not throw
        • if node is re-added to the graph after having been removed, view's behavior is undefined
        Throws:
        java.lang.IllegalArgumentException - if node is not an element of this graph
      • predecessors

        java.util.Set<N> predecessors​(N node)
        Returns a live view of all nodes in this graph adjacent to node which can be reached by traversing node's incoming edges against the direction (if any) of the edge.

        In an undirected graph, this is equivalent to adjacentNodes(Object).

        If node is removed from the graph after this method is called, the Set view returned by this method will be invalidated, and will throw IllegalStateException if it is accessed in any way, with the following exceptions:

        • view.equals(view) evaluates to true (but any other equals(...) expression involving view will throw)
        • hashCode() does not throw
        • if node is re-added to the graph after having been removed, view's behavior is undefined
        Specified by:
        predecessors in interface PredecessorsFunction<N>
        Throws:
        java.lang.IllegalArgumentException - if node is not an element of this graph
      • successors

        java.util.Set<N> successors​(N node)
        Returns a live view of all nodes in this graph adjacent to node which can be reached by traversing node's outgoing edges in the direction (if any) of the edge.

        In an undirected graph, this is equivalent to adjacentNodes(Object).

        This is not the same as "all nodes reachable from node by following outgoing edges". For that functionality, see Graphs.reachableNodes(Graph, Object).

        If node is removed from the graph after this method is called, the Set view returned by this method will be invalidated, and will throw IllegalStateException if it is accessed in any way, with the following exceptions:

        • view.equals(view) evaluates to true (but any other equals(...) expression involving view will throw)
        • hashCode() does not throw
        • if node is re-added to the graph after having been removed, view's behavior is undefined
        Specified by:
        successors in interface SuccessorsFunction<N>
        Throws:
        java.lang.IllegalArgumentException - if node is not an element of this graph