Package com.google.common.graph
Class DirectedGraphConnections<N,V>
- java.lang.Object
-
- com.google.common.graph.DirectedGraphConnections<N,V>
-
- Type Parameters:
N- Node parameter typeV- Value parameter type
- All Implemented Interfaces:
GraphConnections<N,V>
final class DirectedGraphConnections<N,V> extends java.lang.Object implements GraphConnections<N,V>
An implementation ofGraphConnectionsfor directed graphs.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classDirectedGraphConnections.NodeConnection<N>A value class representing single connection between the origin node and another node.private static classDirectedGraphConnections.PredAndSuccA wrapper class to indicate a node is both a predecessor and successor while still providing the successor value.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<N,java.lang.Object>adjacentNodeValuesprivate java.util.List<DirectedGraphConnections.NodeConnection<N>>orderedNodeConnectionsAll node connections in this graph, in edge insertion order.private static java.lang.ObjectPREDprivate intpredecessorCountprivate intsuccessorCount
-
Constructor Summary
Constructors Modifier Constructor Description privateDirectedGraphConnections(java.util.Map<N,java.lang.Object> adjacentNodeValues, java.util.List<DirectedGraphConnections.NodeConnection<N>> orderedNodeConnections, int predecessorCount, int successorCount)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPredecessor(N node, V unused)Addnodeas a predecessor to the origin node.VaddSuccessor(N node, V value)Addnodeas a successor to the origin node.java.util.Set<N>adjacentNodes()java.util.Iterator<EndpointPair<N>>incidentEdgeIterator(N thisNode)Returns an iterator over the incident edges.private static booleanisPredecessor(java.lang.Object value)private static booleanisSuccessor(java.lang.Object value)(package private) static <N,V>
DirectedGraphConnections<N,V>of(ElementOrder<N> incidentEdgeOrder)(package private) static <N,V>
DirectedGraphConnections<N,V>ofImmutable(N thisNode, java.lang.Iterable<EndpointPair<N>> incidentEdges, Function<N,V> successorNodeToValueFn)java.util.Set<N>predecessors()voidremovePredecessor(N node)Removenodefrom the set of predecessors.VremoveSuccessor(java.lang.Object node)Removenodefrom the set of successors.java.util.Set<N>successors()Vvalue(N node)Returns the value associated with the edge connecting the origin node tonode, or null if there is no such edge.
-
-
-
Field Detail
-
PRED
private static final java.lang.Object PRED
-
adjacentNodeValues
private final java.util.Map<N,java.lang.Object> adjacentNodeValues
-
orderedNodeConnections
private final java.util.List<DirectedGraphConnections.NodeConnection<N>> orderedNodeConnections
All node connections in this graph, in edge insertion order.Note: This field and
adjacentNodeValuescannot be combined into a single LinkedHashMap because one target node may be mapped to both a predecessor and a successor. A LinkedHashMap combines two such edges into a single node-value pair, even though the edges may not have been inserted consecutively.
-
predecessorCount
private int predecessorCount
-
successorCount
private int successorCount
-
-
Constructor Detail
-
DirectedGraphConnections
private DirectedGraphConnections(java.util.Map<N,java.lang.Object> adjacentNodeValues, java.util.List<DirectedGraphConnections.NodeConnection<N>> orderedNodeConnections, int predecessorCount, int successorCount)
-
-
Method Detail
-
of
static <N,V> DirectedGraphConnections<N,V> of(ElementOrder<N> incidentEdgeOrder)
-
ofImmutable
static <N,V> DirectedGraphConnections<N,V> ofImmutable(N thisNode, java.lang.Iterable<EndpointPair<N>> incidentEdges, Function<N,V> successorNodeToValueFn)
-
adjacentNodes
public java.util.Set<N> adjacentNodes()
- Specified by:
adjacentNodesin interfaceGraphConnections<N,V>
-
predecessors
public java.util.Set<N> predecessors()
- Specified by:
predecessorsin interfaceGraphConnections<N,V>
-
successors
public java.util.Set<N> successors()
- Specified by:
successorsin interfaceGraphConnections<N,V>
-
incidentEdgeIterator
public java.util.Iterator<EndpointPair<N>> incidentEdgeIterator(N thisNode)
Description copied from interface:GraphConnectionsReturns an iterator over the incident edges.- Specified by:
incidentEdgeIteratorin interfaceGraphConnections<N,V>- Parameters:
thisNode- The node that this all of the connections in this class are connected to.
-
value
public V value(N node)
Description copied from interface:GraphConnectionsReturns the value associated with the edge connecting the origin node tonode, or null if there is no such edge.- Specified by:
valuein interfaceGraphConnections<N,V>
-
removePredecessor
public void removePredecessor(N node)
Description copied from interface:GraphConnectionsRemovenodefrom the set of predecessors.- Specified by:
removePredecessorin interfaceGraphConnections<N,V>
-
removeSuccessor
public V removeSuccessor(java.lang.Object node)
Description copied from interface:GraphConnectionsRemovenodefrom the set of successors. Returns the value previously associated with the edge connecting the two nodes.- Specified by:
removeSuccessorin interfaceGraphConnections<N,V>
-
addPredecessor
public void addPredecessor(N node, V unused)
Description copied from interface:GraphConnectionsAddnodeas a predecessor to the origin node. In the case of an undirected graph, it also becomes a successor. Associatesvaluewith the edge connecting the two nodes.- Specified by:
addPredecessorin interfaceGraphConnections<N,V>
-
addSuccessor
public V addSuccessor(N node, V value)
Description copied from interface:GraphConnectionsAddnodeas a successor to the origin node. In the case of an undirected graph, it also becomes a predecessor. Associatesvaluewith the edge connecting the two nodes. Returns the value previously associated with the edge connecting the two nodes.- Specified by:
addSuccessorin interfaceGraphConnections<N,V>
-
isPredecessor
private static boolean isPredecessor(java.lang.Object value)
-
isSuccessor
private static boolean isSuccessor(java.lang.Object value)
-
-