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, edgeConnectingOrNull, edgeConnectingOrNull, edgeOrder, edges, edgesConnecting, edgesConnecting, equals, hasEdgeConnecting, hasEdgeConnecting, hashCode, incidentEdges, incidentNodes, inDegree, inEdges, outDegree, outEdgesModifier and TypeMethodDescriptionadjacentEdges(E edge) Returns a live view of the edges which have anincident nodein common withedge.booleanReturns true if this network allows parallel edges.asGraph()Returns a live view of this network as aGraph.intReturns the count ofnode'sincident edges, counting self-loops twice (equivalently, the number of times an edge touchesnode).edgeConnectingOrNull(EndpointPair<N> endpoints) Returns the single edge that directly connectsendpoints(in the order, if any, specified byendpoints), if one is present, ornullif no such edge exists.edgeConnectingOrNull(N nodeU, N nodeV) Returns the single edge that directly connectsnodeUtonodeV, if one is present, ornullif no such edge exists.Returns the order of iteration for the elements ofNetwork.edges().edges()Returns all edges in this network, in the order specified byNetwork.edgeOrder().edgesConnecting(EndpointPair<N> endpoints) Returns a live view of the set of edges that each directly connectendpoints(in the order, if any, specified byendpoints).edgesConnecting(N nodeU, N nodeV) Returns a live view of the set of edges that each directly connectnodeUtonodeV.booleanReturnstrueiffobjectis aNetworkthat has the same elements and the same structural relationships as those in this network.booleanhasEdgeConnecting(EndpointPair<N> endpoints) Returns true if there is an edge that directly connectsendpoints(in the order, if any, specified byendpoints).booleanhasEdgeConnecting(N nodeU, N nodeV) Returns true if there is an edge that directly connectsnodeUtonodeV.inthashCode()Returns the hash code for this network.incidentEdges(N node) Returns a live view of the edges whoseincident nodesin this network includenode.incidentNodes(E edge) Returns the nodes which are the endpoints ofedgein this network.intReturns the count ofnode'sincoming edgesin a directed network.Returns a live view of all edges in this network which can be traversed in the direction (if any) of the edge to end atnode.intReturns the count ofnode'soutgoing edgesin a directed network.Returns a live view of all edges in this network which can be traversed in the direction (if any) of the edge starting fromnode.
-
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 otherequals(...)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 otherequals(...)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 otherequals(...)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
-