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 TypeMethodDescriptionboolean
addEdge
(EndpointPair<N> endpoints, E edge) Addsedge
connectingendpoints
.boolean
Addsedge
connectingnodeU
tonodeV
.boolean
Addsnode
if it is not already present.adjacentNodes
(N node) Returns a live view of the nodes which have an incident edge in common withnode
in this graph.boolean
Returns true if this graph allows self-loops (edges that connect a node to itself).boolean
Returns 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 tonode
which can be reached by traversingnode
's incoming edges against the direction (if any) of the edge.boolean
removeEdge
(E edge) Removesedge
from this network, if it is present.boolean
removeNode
(N node) Removesnode
if it is present; all edges incident tonode
will also be removed.successors
(N node) Returns a live view of all nodes in this graph adjacent tonode
which 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
Addsnode
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
Addsedge
connectingnodeU
tonodeV
.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 aMap
key must be. It must also be non-null.If
nodeU
andnodeV
are not already present in this graph, this method will silentlyadd
nodeU
andnodeV
to the graph.If
edge
already connectsnodeU
tonodeV
(in the specified order if this networkisDirected()
, 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:
IllegalArgumentException
- ifedge
already exists in the graph and does not connectnodeU
tonodeV
IllegalArgumentException
- if the introduction of the edge would violateNetwork.allowsParallelEdges()
orallowsSelfLoops()
-
addEdge
Addsedge
connectingendpoints
. In an undirected network,edge
will also connectnodeV
tonodeU
.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 aMap
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 toendpoints
, then this method will have no effect.- Returns:
true
if the network was modified as a result of this call- Throws:
IllegalArgumentException
- ifedge
already exists in the graph and connects some other endpoint pair that is not equal toendpoints
IllegalArgumentException
- 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
Removesnode
if it is present; all edges incident tonode
will also be removed.- Returns:
true
if the network was modified as a result of this call
-
removeEdge
Removesedge
from this network, if it is present.- Returns:
true
if 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 node
to 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 withnode
in this graph.This is equal to the union of
PredecessorsFunction.predecessors(Object)
andSuccessorsFunction.successors(Object)
.If
node
is removed from the graph after this method is called, theSet
view
returned by this method will be invalidated, and will throwIllegalStateException
if it is accessed in any way, with the following exceptions:view.equals(view)
evaluates totrue
(but any other `equals()` expression involvingview
will throw)hashCode()
does not throw- if
node
is re-added to the graph after having been removed,view
's behavior is undefined
- Throws:
IllegalArgumentException
- ifnode
is not an element of this graph
-
predecessors
Returns a live view of all nodes in this graph adjacent tonode
which 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
node
is removed from the graph after this method is called, theSet
view
returned by this method will be invalidated, and will throwIllegalStateException
if it is accessed in any way, with the following exceptions:view.equals(view)
evaluates totrue
(but any other `equals()` expression involvingview
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 interfacePredecessorsFunction<N>
- Throws:
IllegalArgumentException
- ifnode
is not an element of this graph
-
successors
Returns a live view of all nodes in this graph adjacent tonode
which 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
node
by following outgoing edges". For that functionality, seeGraphs.reachableNodes(Graph, Object)
.If
node
is removed from the graph after this method is called, theSet
view
returned by this method will be invalidated, and will throwIllegalStateException
if it is accessed in any way, with the following exceptions:view.equals(view)
evaluates totrue
(but any other `equals()` expression involvingview
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 interfaceSuccessorsFunction<N>
- Throws:
IllegalArgumentException
- ifnode
is not an element of this graph
-