Class StandardMutableValueGraph<N,V>
- java.lang.Object
-
- com.google.common.graph.AbstractBaseGraph<N>
-
- com.google.common.graph.AbstractValueGraph<N,V>
-
- com.google.common.graph.StandardValueGraph<N,V>
-
- com.google.common.graph.StandardMutableValueGraph<N,V>
-
- Type Parameters:
N- Node parameter typeV- Value parameter type
- All Implemented Interfaces:
BaseGraph<N>,MutableValueGraph<N,V>,PredecessorsFunction<N>,SuccessorsFunction<N>,ValueGraph<N,V>
final class StandardMutableValueGraph<N,V> extends StandardValueGraph<N,V> implements MutableValueGraph<N,V>
Standard implementation ofMutableValueGraphthat supports both directed and undirected graphs. Instances of this class should be constructed withValueGraphBuilder.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 ofnode.
-
-
Field Summary
Fields Modifier and Type Field Description private ElementOrder<N>incidentEdgeOrder-
Fields inherited from class com.google.common.graph.StandardValueGraph
edgeCount, nodeConnections
-
-
Constructor Summary
Constructors Constructor Description StandardMutableValueGraph(AbstractGraphBuilder<? super N> builder)Constructs a mutable graph with the properties specified inbuilder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddNode(N node)Addsnodeif it is not already present.private GraphConnections<N,V>addNodeInternal(N node)Addsnodeto the graph and returns the associatedGraphConnections.ElementOrder<N>incidentEdgeOrder()Returns anElementOrderthat specifies the order of iteration for the elements ofBaseGraph.edges(),BaseGraph.adjacentNodes(Object),BaseGraph.predecessors(Object),BaseGraph.successors(Object)andBaseGraph.incidentEdges(Object).private GraphConnections<N,V>newConnections()VputEdgeValue(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).VputEdgeValue(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).VremoveEdge(EndpointPair<N> endpoints)Removes the edge connectingendpoints, if it is present.VremoveEdge(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 class com.google.common.graph.StandardValueGraph
adjacentNodes, allowsSelfLoops, checkedConnections, containsNode, edgeCount, edgeValueOrDefault, edgeValueOrDefault, edgeValueOrDefault_internal, hasEdgeConnecting, hasEdgeConnecting, hasEdgeConnecting_internal, incidentEdges, isDirected, nodeOrder, nodes, predecessors, successors
-
Methods inherited from class com.google.common.graph.AbstractValueGraph
asGraph, edgeValue, edgeValue, equals, hashCode, toString
-
Methods inherited from class com.google.common.graph.AbstractBaseGraph
degree, edges, inDegree, isOrderingCompatible, outDegree, validateEndpoints
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.google.common.graph.ValueGraph
adjacentNodes, allowsSelfLoops, asGraph, degree, edges, edgeValue, edgeValue, edgeValueOrDefault, edgeValueOrDefault, equals, hasEdgeConnecting, hasEdgeConnecting, hashCode, incidentEdges, inDegree, isDirected, nodeOrder, nodes, outDegree, predecessors, successors
-
-
-
-
Field Detail
-
incidentEdgeOrder
private final ElementOrder<N> incidentEdgeOrder
-
-
Constructor Detail
-
StandardMutableValueGraph
StandardMutableValueGraph(AbstractGraphBuilder<? super N> builder)
Constructs a mutable graph with the properties specified inbuilder.
-
-
Method Detail
-
incidentEdgeOrder
public ElementOrder<N> incidentEdgeOrder()
Description copied from interface:BaseGraphReturns anElementOrderthat specifies the order of iteration for the elements ofBaseGraph.edges(),BaseGraph.adjacentNodes(Object),BaseGraph.predecessors(Object),BaseGraph.successors(Object)andBaseGraph.incidentEdges(Object).- Specified by:
incidentEdgeOrderin interfaceBaseGraph<N>- Specified by:
incidentEdgeOrderin interfaceValueGraph<N,V>- Overrides:
incidentEdgeOrderin classAbstractBaseGraph<N>
-
addNode
public boolean addNode(N node)
Description copied from interface:MutableValueGraphAddsnodeif it is not already present.Nodes must be unique, just as
Mapkeys must be. They must also be non-null.- Specified by:
addNodein interfaceMutableValueGraph<N,V>- Returns:
trueif the graph was modified as a result of this call
-
addNodeInternal
private GraphConnections<N,V> addNodeInternal(N node)
Addsnodeto the graph and returns the associatedGraphConnections.- Throws:
java.lang.IllegalStateException- ifnodeis already present
-
putEdgeValue
public V putEdgeValue(N nodeU, N nodeV, V value)
Description copied from interface:MutableValueGraphAdds 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.- Specified by:
putEdgeValuein interfaceMutableValueGraph<N,V>- Returns:
- the value previously associated with the edge connecting
nodeUtonodeV, or null if there was no such edge.
-
putEdgeValue
public V putEdgeValue(EndpointPair<N> endpoints, V value)
Description copied from interface:MutableValueGraphAdds 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.- Specified by:
putEdgeValuein interfaceMutableValueGraph<N,V>- Returns:
- the value previously associated with the edge connecting
nodeUtonodeV, or null if there was no such edge.
-
removeNode
public boolean removeNode(N node)
Description copied from interface:MutableValueGraphRemovesnodeif it is present; all edges incident tonodewill also be removed.- Specified by:
removeNodein interfaceMutableValueGraph<N,V>- Returns:
trueif the graph was modified as a result of this call
-
removeEdge
public V removeEdge(N nodeU, N nodeV)
Description copied from interface:MutableValueGraphRemoves the edge connectingnodeUtonodeV, if it is present.- Specified by:
removeEdgein interfaceMutableValueGraph<N,V>- Returns:
- the value previously associated with the edge connecting
nodeUtonodeV, or null if there was no such edge.
-
removeEdge
public V removeEdge(EndpointPair<N> endpoints)
Description copied from interface:MutableValueGraphRemoves the edge connectingendpoints, if it is present.If this graph is directed,
endpointsmust be ordered.- Specified by:
removeEdgein interfaceMutableValueGraph<N,V>- Returns:
- the value previously associated with the edge connecting
endpoints, or null if there was no such edge.
-
newConnections
private GraphConnections<N,V> newConnections()
-
-