N
- Node parameter typeV
- Value parameter typefinal class ConfigurableMutableValueGraph<N,V> extends ConfigurableValueGraph<N,V> implements MutableValueGraph<N,V>
MutableValueGraph
that supports both directed and
undirected graphs. Instances of this class should be constructed with ValueGraphBuilder
.
Time complexities for mutation methods are all O(1) except for removeNode(N node)
,
which is in O(d_node) where d_node is the degree of node
.
edgeCount, nodeConnections
Constructor and Description |
---|
ConfigurableMutableValueGraph(AbstractGraphBuilder<? super N> builder)
Constructs a mutable graph with the properties specified in
builder . |
Modifier and Type | Method and Description |
---|---|
boolean |
addNode(N node)
Adds
node if it is not already present. |
private GraphConnections<N,V> |
addNodeInternal(N node)
Adds
node to the graph and returns the associated GraphConnections . |
private GraphConnections<N,V> |
newConnections() |
V |
putEdgeValue(N nodeU,
N nodeV,
V value)
Adds an edge connecting
nodeU to nodeV if one is not already present; associate
that edge with value . |
V |
removeEdge(java.lang.Object nodeU,
java.lang.Object nodeV)
Removes the edge connecting
nodeU to nodeV , if it is present. |
boolean |
removeNode(java.lang.Object node)
Removes
node if it is present; all edges incident to node will also be removed. |
adjacentNodes, allowsSelfLoops, checkedConnections, containsNode, edgeCount, edgeValueOrDefault, isDirected, nodeOrder, nodes, predecessors, successors
edgeValue, toString
degree, edges, inDegree, outDegree
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
edgeValue, edgeValueOrDefault, equals, hashCode
adjacentNodes, allowsSelfLoops, degree, edges, inDegree, isDirected, nodeOrder, nodes, outDegree, predecessors, successors
ConfigurableMutableValueGraph(AbstractGraphBuilder<? super N> builder)
builder
.public boolean addNode(N node)
MutableValueGraph
node
if it is not already present.
Nodes must be unique, just as Map
keys must be. They must also be non-null.
addNode
in interface MutableValueGraph<N,V>
true
if the graph was modified as a result of this callprivate GraphConnections<N,V> addNodeInternal(N node)
node
to the graph and returns the associated GraphConnections
.java.lang.IllegalStateException
- if node
is already presentpublic V putEdgeValue(N nodeU, N nodeV, V value)
MutableValueGraph
nodeU
to nodeV
if one is not already present; associate
that edge with value
. In an undirected graph, the edge will also connect nodeV
to nodeU
.
Values do not have to be unique. However, values must be non-null.
Behavior if nodeU
and nodeV
are not already present in this graph is
implementation-dependent. Suggested behaviors include (a) silently adding
nodeU
and nodeV
to the graph (this is the behavior of the default
implementations) or (b) throwing IllegalArgumentException
.
putEdgeValue
in interface MutableValueGraph<N,V>
nodeU
to nodeV
, or null if there was no such edge.public boolean removeNode(java.lang.Object node)
MutableValueGraph
node
if it is present; all edges incident to node
will also be removed.removeNode
in interface MutableValueGraph<N,V>
true
if the graph was modified as a result of this callpublic V removeEdge(java.lang.Object nodeU, java.lang.Object nodeV)
MutableValueGraph
nodeU
to nodeV
, if it is present.removeEdge
in interface MutableValueGraph<N,V>
nodeU
to nodeV
, or null if there was no such edge.private GraphConnections<N,V> newConnections()