Interface MutableNetwork<N,E>
- Type Parameters:
N- Node parameter typeE- Edge parameter type
- All Superinterfaces:
Network<N,E>, PredecessorsFunction<N>, SuccessorsFunction<N>
-
Method Summary
Modifier and TypeMethodDescriptionbooleanaddEdge(EndpointPair<N> endpoints, E edge) Addsedgeconnectingendpoints.booleanAddsedgeconnectingnodeUtonodeV.booleanAddsnodeif it is not already present.adjacentNodes(N node) Returns a live view of the nodes which have an incident edge in common withnodein this graph.booleanReturns true if this graph allows self-loops (edges that connect a node to itself).booleanReturns true if the edges in this graph are directed.Returns the order of iteration for the elements ofnodes().nodes()Returns all nodes in this graph, in the order specified bynodeOrder().predecessors(N node) Returns a live view of all nodes in this graph adjacent tonodewhich can be reached by traversingnode's incoming edges against the direction (if any) of the edge.booleanremoveEdge(E edge) Removesedgefrom this network, if it is present.booleanremoveNode(N node) Removesnodeif it is present; all edges incident tonodewill also be removed.successors(N node) Returns a live view of all nodes in this graph adjacent tonodewhich can be reached by traversingnode's outgoing edges in the direction (if any) of the edge.Methods inherited from interface Network
adjacentEdges, allowsParallelEdges, asGraph, degree, edgeConnecting, edgeConnecting, edgeConnectingOrNull, edgeConnectingOrNull, edgeOrder, edges, edgesConnecting, edgesConnecting, equals, hasEdgeConnecting, hasEdgeConnecting, hashCode, incidentEdges, incidentNodes, inDegree, inEdges, outDegree, outEdges
-
Method Details
-
addNode
Addsnodeif it is not already present.Nodes must be unique, just as
Mapkeys must be. They must also be non-null.- Returns:
trueif the network was modified as a result of this call
-
addEdge
AddsedgeconnectingnodeUtonodeV.If the graph is directed,
edgewill be directed in this graph; otherwise, it will be undirected.edgemust be unique to this graph, just as aMapkey must be. It must also be non-null.If
nodeUandnodeVare not already present in this graph, this method will silentlyaddnodeUandnodeVto the graph.If
edgealready connectsnodeUtonodeV(in the specified order if this networkisDirected(), else in any order), then this method will have no effect.- Returns:
trueif the network was modified as a result of this call- Throws:
IllegalArgumentException- ifedgealready exists in the graph and does not connectnodeUtonodeVIllegalArgumentException- if the introduction of the edge would violateNetwork.allowsParallelEdges()orallowsSelfLoops()
-
addEdge
Addsedgeconnectingendpoints. In an undirected network,edgewill also connectnodeVtonodeU.If this graph is directed,
edgewill be directed in this graph; if it is undirected,edgewill be undirected in this graph.If this graph is directed,
endpointsmust be ordered.edgemust be unique to this graph, just as aMapkey must be. It must also be non-null.If either or both endpoints are not already present in this graph, this method will silently
addeach missing endpoint to the graph.If
edgealready connects an endpoint pair equal toendpoints, then this method will have no effect.- Returns:
trueif the network was modified as a result of this call- Throws:
IllegalArgumentException- ifedgealready exists in the graph and connects some other endpoint pair that is not equal toendpointsIllegalArgumentException- if the introduction of the edge would violateNetwork.allowsParallelEdges()orallowsSelfLoops()IllegalArgumentException- if the endpoints are unordered and the graph is directed- Since:
- 27.1
-
removeNode
Removesnodeif it is present; all edges incident tonodewill also be removed.- Returns:
trueif the network was modified as a result of this call
-
removeEdge
Removesedgefrom this network, if it is present.- Returns:
trueif the network was modified as a result of this call
-
nodes
Returns all nodes in this graph, in the order specified bynodeOrder(). -
isDirected
boolean isDirected()Returns true if the edges in this graph are directed. Directed edges connect asource nodeto atarget 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 anIllegalArgumentException. -
nodeOrder
ElementOrder<N> nodeOrder()Returns the order of iteration for the elements ofnodes(). -
adjacentNodes
Returns a live view of the nodes which have an incident edge in common withnodein this graph.This is equal to the union of
PredecessorsFunction.predecessors(Object)andSuccessorsFunction.successors(Object).If
nodeis removed from the graph after this method is called, theSetviewreturned by this method will be invalidated, and will throwIllegalStateExceptionif it is accessed in any way, with the following exceptions:view.equals(view)evaluates totrue(but any other `equals()` expression involvingviewwill throw)hashCode()does not throw- if
nodeis re-added to the graph after having been removed,view's behavior is undefined
- Throws:
IllegalArgumentException- ifnodeis not an element of this graph
-
predecessors
Returns a live view of all nodes in this graph adjacent tonodewhich can be reached by traversingnode's incoming edges against the direction (if any) of the edge.In an undirected graph, this is equivalent to
adjacentNodes(Object).If
nodeis removed from the graph after this method is called, theSetviewreturned by this method will be invalidated, and will throwIllegalStateExceptionif it is accessed in any way, with the following exceptions:view.equals(view)evaluates totrue(but any other `equals()` expression involvingviewwill throw)hashCode()does not throw- if
nodeis re-added to the graph after having been removed,view's behavior is undefined
- Specified by:
predecessorsin interfacePredecessorsFunction<N>- Throws:
IllegalArgumentException- ifnodeis not an element of this graph
-
successors
Returns a live view of all nodes in this graph adjacent tonodewhich can be reached by traversingnode'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
nodeby following outgoing edges". For that functionality, seeGraphs.reachableNodes(Graph, Object).If
nodeis removed from the graph after this method is called, theSetviewreturned by this method will be invalidated, and will throwIllegalStateExceptionif it is accessed in any way, with the following exceptions:view.equals(view)evaluates totrue(but any other `equals()` expression involvingviewwill throw)hashCode()does not throw- if
nodeis re-added to the graph after having been removed,view's behavior is undefined
- Specified by:
successorsin interfaceSuccessorsFunction<N>- Throws:
IllegalArgumentException- ifnodeis not an element of this graph
-