Interface MutableNetwork<N,E>
-
- Type Parameters:
N- Node parameter typeE- Edge parameter type
- All Superinterfaces:
Network<N,E>,PredecessorsFunction<N>,SuccessorsFunction<N>
public interface MutableNetwork<N,E> extends Network<N,E>
A subinterface ofNetworkwhich adds mutation methods. When mutation is not required, users should prefer theNetworkinterface.- Since:
- 20.0
- Author:
- James Sexton, Joshua O'Madadhain
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanaddEdge(EndpointPair<N> endpoints, E edge)Addsedgeconnectingendpoints.booleanaddEdge(N nodeU, N nodeV, E edge)AddsedgeconnectingnodeUtonodeV.booleanaddNode(N node)Addsnodeif it is not already present.java.util.Set<N>adjacentNodes(N node)Returns a live view of the nodes which have an incident edge in common withnodein this graph.booleanallowsSelfLoops()Returns true if this graph allows self-loops (edges that connect a node to itself).booleanisDirected()Returns true if the edges in this graph are directed.ElementOrder<N>nodeOrder()Returns the order of iteration for the elements ofnodes().java.util.Set<N>nodes()Returns all nodes in this graph, in the order specified bynodeOrder().java.util.Set<N>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.java.util.Set<N>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 com.google.common.graph.Network
adjacentEdges, allowsParallelEdges, asGraph, degree, edgeConnecting, edgeConnecting, edgeConnectingOrNull, edgeConnectingOrNull, edgeOrder, edges, edgesConnecting, edgesConnecting, equals, hasEdgeConnecting, hasEdgeConnecting, hashCode, incidentEdges, incidentNodes, inDegree, inEdges, outDegree, outEdges
-
-
-
-
Method Detail
-
addNode
@CanIgnoreReturnValue boolean addNode(N node)
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
@CanIgnoreReturnValue boolean addEdge(N nodeU, N nodeV, E edge)
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:
java.lang.IllegalArgumentException- ifedgealready exists in the graph and does not connectnodeUtonodeVjava.lang.IllegalArgumentException- if the introduction of the edge would violateNetwork.allowsParallelEdges()orallowsSelfLoops()
-
addEdge
@CanIgnoreReturnValue boolean addEdge(EndpointPair<N> endpoints, E edge)
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:
java.lang.IllegalArgumentException- ifedgealready exists in the graph and connects some other endpoint pair that is not equal toendpointsjava.lang.IllegalArgumentException- if the introduction of the edge would violateNetwork.allowsParallelEdges()orallowsSelfLoops()java.lang.IllegalArgumentException- if the endpoints are unordered and the graph is directed- Since:
- 27.1
-
removeNode
@CanIgnoreReturnValue boolean removeNode(N node)
Removesnodeif it is present; all edges incident tonodewill also be removed.- Returns:
trueif the network was modified as a result of this call
-
removeEdge
@CanIgnoreReturnValue boolean removeEdge(E edge)
Removesedgefrom this network, if it is present.- Returns:
trueif 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 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
java.util.Set<N> adjacentNodes(N node)
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:
java.lang.IllegalArgumentException- ifnodeis 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 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:
java.lang.IllegalArgumentException- ifnodeis 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 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:
java.lang.IllegalArgumentException- ifnodeis not an element of this graph
-
-