Interface MutableValueGraph<N,V>
- Type Parameters:
N- Node parameter typeV- Value parameter type
- All Superinterfaces:
PredecessorsFunction<N>, SuccessorsFunction<N>, ValueGraph<N,V>
ValueGraph which adds mutation methods. When mutation is not required,
users should prefer the ValueGraph interface.- Since:
- 20.0
- Author:
- James Sexton
-
Method Summary
Modifier and TypeMethodDescriptionbooleanAddsnodeif it is not already present.Network<N, EndpointPair<N>> Returns a live view of this graph as aNetworkwhose edgesEareEndpointPair<N>objects (that is, aNetwork<N, EndpointPair<N>>).putEdgeValue(EndpointPair<N> endpoints, V value) Adds an edge connectingendpointsif one is not already present, and sets a value for that edge tovalue(overwriting the existing value, if any).putEdgeValue(N nodeU, N nodeV, V value) Adds an edge connectingnodeUtonodeVif one is not already present, and sets a value for that edge tovalue(overwriting the existing value, if any).removeEdge(EndpointPair<N> endpoints) Removes the edge connectingendpoints, if it is present.removeEdge(N nodeU, N nodeV) Removes the edge connectingnodeUtonodeV, if it is present.booleanremoveNode(N node) Removesnodeif it is present; all edges incident tonodewill also be removed.Methods inherited from interface ValueGraph
adjacentNodes, allowsSelfLoops, asGraph, degree, edges, edgeValueOrDefault, edgeValueOrDefault, equals, hasEdgeConnecting, hasEdgeConnecting, hashCode, incidentEdgeOrder, incidentEdges, inDegree, isDirected, nodeOrder, nodes, outDegree, predecessors, successorsModifier and TypeMethodDescriptionadjacentNodes(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).asGraph()Returns a live view of this graph as aGraph.intReturns the count ofnode's incident edges, counting self-loops twice (equivalently, the number of times an edge touchesnode).Set<EndpointPair<N>> edges()Returns all edges in this graph.edgeValueOrDefault(EndpointPair<N> endpoints, V defaultValue) Returns the value of the edge that connectsendpoints(in the order, if any, specified byendpoints), if one is present; otherwise, returnsdefaultValue.edgeValueOrDefault(N nodeU, N nodeV, V defaultValue) Returns the value of the edge that connectsnodeUtonodeV, if one is present; otherwise, returnsdefaultValue.booleanReturnstrueiffobjectis aValueGraphthat has the same elements and the same structural relationships as those in this graph.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 graph.Returns anElementOrderthat specifies the order of iteration for the elements ofValueGraph.edges(),ValueGraph.adjacentNodes(Object),ValueGraph.predecessors(Object),ValueGraph.successors(Object)andValueGraph.incidentEdges(Object).Set<EndpointPair<N>> incidentEdges(N node) Returns a live view of the edges in this graph whose endpoints includenode.intReturns the count ofnode's incoming edges (equal topredecessors(node).size()) in a directed graph.booleanReturns true if the edges in this graph are directed.Returns the order of iteration for the elements ofValueGraph.nodes().nodes()Returns all nodes in this graph, in the order specified byValueGraph.nodeOrder().intReturns the count ofnode's outgoing edges (equal tosuccessors(node).size()) in a directed graph.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.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.
-
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 graph was modified as a result of this call
-
putEdgeValue
Adds an edge connectingnodeUtonodeVif one is not already present, and sets a value for that edge tovalue(overwriting the existing value, if any).If the graph is directed, the resultant edge will be directed; otherwise, it will be undirected.
Values do not have to be unique. However, values must be non-null.
If
nodeUandnodeVare not already present in this graph, this method will silentlyaddnodeUandnodeVto the graph.- Returns:
- the value previously associated with the edge connecting
nodeUtonodeV, or null if there was no such edge. - Throws:
IllegalArgumentException- if the introduction of the edge would violateValueGraph.allowsSelfLoops()
-
putEdgeValue
Adds an edge connectingendpointsif one is not already present, and sets a value for that edge tovalue(overwriting the existing value, if any).If the graph is directed, the resultant edge will be directed; otherwise, it will be undirected.
If this graph is directed,
endpointsmust be ordered.Values do not have to be unique. However, values must 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.- Returns:
- the value previously associated with the edge connecting
nodeUtonodeV, or null if there was no such edge. - Throws:
IllegalArgumentException- if the introduction of the edge would violateValueGraph.allowsSelfLoops()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 graph was modified as a result of this call
-
removeEdge
-
removeEdge
Removes the edge connectingendpoints, if it is present.If this graph is directed,
endpointsmust be ordered.- Returns:
- the value previously associated with the edge connecting
endpoints, or null if there was no such edge. - Since:
- 27.1
-
asNetwork
Network<N, EndpointPair<N>> asNetwork()Returns a live view of this graph as aNetworkwhose edgesEareEndpointPair<N>objects (that is, aNetwork<N, EndpointPair<N>>). The resultingNetwork's edge-oriented methods (such asinEdges()) will return views transformed from the corresponding node-oriented methods (such aspredecessors()).This capability facilitates writing implementations of edge-oriented code.
- Since:
- 33.6.0
-