Class ConfigurableNetwork<N,E>
- java.lang.Object
-
- com.google.common.graph.AbstractNetwork<N,E>
-
- com.google.common.graph.ConfigurableNetwork<N,E>
-
- Type Parameters:
N- Node parameter typeE- Edge parameter type
- All Implemented Interfaces:
Network<N,E>,PredecessorsFunction<N>,SuccessorsFunction<N>
- Direct Known Subclasses:
ConfigurableMutableNetwork,ImmutableNetwork
class ConfigurableNetwork<N,E> extends AbstractNetwork<N,E>
Configurable implementation ofNetworkthat supports the options supplied byNetworkBuilder.This class maintains a map of nodes to
NetworkConnections. This class also maintains a map of edges to reference nodes. The reference node is defined to be the edge's source node on directed graphs, and an arbitrary endpoint of the edge on undirected graphs.Collection-returning accessors return unmodifiable views: the view returned will reflect changes to the graph (if the graph is mutable) but may not be modified by the user.
The time complexity of all collection-returning accessors is O(1), since views are returned.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanallowsParallelEdgesprivate booleanallowsSelfLoopsprivate ElementOrder<E>edgeOrderprotected MapIteratorCache<E,N>edgeToReferenceNodeprivate booleanisDirectedprotected MapIteratorCache<N,NetworkConnections<N,E>>nodeConnectionsprivate ElementOrder<N>nodeOrder
-
Constructor Summary
Constructors Constructor Description ConfigurableNetwork(NetworkBuilder<? super N,? super E> builder)Constructs a graph with the properties specified inbuilder.ConfigurableNetwork(NetworkBuilder<? super N,? super E> builder, java.util.Map<N,NetworkConnections<N,E>> nodeConnections, java.util.Map<E,N> edgeToReferenceNode)Constructs a graph with the properties specified inbuilder, initialized with the given node and edge maps.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Set<N>adjacentNodes(N node)Returns the nodes which have an incident edge in common withnodein this network.booleanallowsParallelEdges()Returns true if this network allows parallel edges.booleanallowsSelfLoops()Returns true if this network allows self-loops (edges that connect a node to itself).protected NetworkConnections<N,E>checkedConnections(N node)protected NcheckedReferenceNode(E edge)protected booleancontainsEdge(E edge)protected booleancontainsNode(N node)ElementOrder<E>edgeOrder()Returns the order of iteration for the elements ofNetwork.edges().java.util.Set<E>edges()Returns all edges in this network, in the order specified byNetwork.edgeOrder().java.util.Set<E>edgesConnecting(N nodeU, N nodeV)Returns the set of edges that each directly connectnodeUtonodeV.java.util.Set<E>incidentEdges(N node)Returns the edges whoseincident nodesin this network includenode.EndpointPair<N>incidentNodes(E edge)Returns the nodes which are the endpoints ofedgein this network.java.util.Set<E>inEdges(N node)Returns all edges in this network which can be traversed in the direction (if any) of the edge to end atnode.booleanisDirected()Returns true if the edges in this network are directed.ElementOrder<N>nodeOrder()Returns the order of iteration for the elements ofNetwork.nodes().java.util.Set<N>nodes()Returns all nodes in this network, in the order specified byNetwork.nodeOrder().java.util.Set<E>outEdges(N node)Returns all edges in this network which can be traversed in the direction (if any) of the edge starting fromnode.java.util.Set<N>predecessors(N node)Returns all nodes in this network adjacent tonodewhich can be reached by traversingnode's incoming edges against the direction (if any) of the edge.java.util.Set<N>successors(N node)Returns all nodes in this network adjacent tonodewhich can be reached by traversingnode's outgoing edges in the direction (if any) of the edge.-
Methods inherited from class com.google.common.graph.AbstractNetwork
adjacentEdges, asGraph, degree, edgeConnecting, edgeConnecting, edgeConnectingOrNull, edgeConnectingOrNull, edgesConnecting, equals, hasEdgeConnecting, hasEdgeConnecting, hashCode, inDegree, isOrderingCompatible, outDegree, toString, validateEndpoints
-
-
-
-
Field Detail
-
isDirected
private final boolean isDirected
-
allowsParallelEdges
private final boolean allowsParallelEdges
-
allowsSelfLoops
private final boolean allowsSelfLoops
-
nodeOrder
private final ElementOrder<N> nodeOrder
-
edgeOrder
private final ElementOrder<E> edgeOrder
-
nodeConnections
protected final MapIteratorCache<N,NetworkConnections<N,E>> nodeConnections
-
edgeToReferenceNode
protected final MapIteratorCache<E,N> edgeToReferenceNode
-
-
Constructor Detail
-
ConfigurableNetwork
ConfigurableNetwork(NetworkBuilder<? super N,? super E> builder)
Constructs a graph with the properties specified inbuilder.
-
ConfigurableNetwork
ConfigurableNetwork(NetworkBuilder<? super N,? super E> builder, java.util.Map<N,NetworkConnections<N,E>> nodeConnections, java.util.Map<E,N> edgeToReferenceNode)
Constructs a graph with the properties specified inbuilder, initialized with the given node and edge maps.
-
-
Method Detail
-
nodes
public java.util.Set<N> nodes()
Description copied from interface:NetworkReturns all nodes in this network, in the order specified byNetwork.nodeOrder().
-
edges
public java.util.Set<E> edges()
Description copied from interface:NetworkReturns all edges in this network, in the order specified byNetwork.edgeOrder().
-
isDirected
public boolean isDirected()
Description copied from interface:NetworkReturns true if the edges in this network are directed. Directed edges connect asource nodeto atarget node, while undirected edges connect a pair of nodes to each other.
-
allowsParallelEdges
public boolean allowsParallelEdges()
Description copied from interface:NetworkReturns true if this network allows parallel edges. Attempting to add a parallel edge to a network that does not allow them will throw anIllegalArgumentException.
-
allowsSelfLoops
public boolean allowsSelfLoops()
Description copied from interface:NetworkReturns true if this network allows self-loops (edges that connect a node to itself). Attempting to add a self-loop to a network that does not allow them will throw anIllegalArgumentException.
-
nodeOrder
public ElementOrder<N> nodeOrder()
Description copied from interface:NetworkReturns the order of iteration for the elements ofNetwork.nodes().
-
edgeOrder
public ElementOrder<E> edgeOrder()
Description copied from interface:NetworkReturns the order of iteration for the elements ofNetwork.edges().
-
incidentEdges
public java.util.Set<E> incidentEdges(N node)
Description copied from interface:NetworkReturns the edges whoseincident nodesin this network includenode.This is equal to the union of
Network.inEdges(Object)andNetwork.outEdges(Object).
-
incidentNodes
public EndpointPair<N> incidentNodes(E edge)
Description copied from interface:NetworkReturns the nodes which are the endpoints ofedgein this network.
-
adjacentNodes
public java.util.Set<N> adjacentNodes(N node)
Description copied from interface:NetworkReturns the nodes which have an incident edge in common withnodein this network.This is equal to the union of
Network.predecessors(Object)andNetwork.successors(Object).
-
edgesConnecting
public java.util.Set<E> edgesConnecting(N nodeU, N nodeV)
Description copied from interface:NetworkReturns the set of edges that each directly connectnodeUtonodeV.In an undirected network, this is equal to
edgesConnecting(nodeV, nodeU).The resulting set of edges will be parallel (i.e. have equal
Network.incidentNodes(Object). If this network does notallow parallel edges, the resulting set will contain at most one edge (equivalent toedgeConnecting(nodeU, nodeV).asSet()).- Specified by:
edgesConnectingin interfaceNetwork<N,E>- Overrides:
edgesConnectingin classAbstractNetwork<N,E>
-
inEdges
public java.util.Set<E> inEdges(N node)
Description copied from interface:NetworkReturns all edges in this network which can be traversed in the direction (if any) of the edge to end atnode.In a directed network, an incoming edge's
EndpointPair.target()equalsnode.In an undirected network, this is equivalent to
Network.incidentEdges(Object).
-
outEdges
public java.util.Set<E> outEdges(N node)
Description copied from interface:NetworkReturns all edges in this network which can be traversed in the direction (if any) of the edge starting fromnode.In a directed network, an outgoing edge's
EndpointPair.source()equalsnode.In an undirected network, this is equivalent to
Network.incidentEdges(Object).
-
predecessors
public java.util.Set<N> predecessors(N node)
Description copied from interface:NetworkReturns all nodes in this network adjacent tonodewhich can be reached by traversingnode's incoming edges against the direction (if any) of the edge.In an undirected network, this is equivalent to
Network.adjacentNodes(Object).
-
successors
public java.util.Set<N> successors(N node)
Description copied from interface:NetworkReturns all nodes in this network adjacent tonodewhich can be reached by traversingnode's outgoing edges in the direction (if any) of the edge.In an undirected network, this is equivalent to
Network.adjacentNodes(Object).This is not the same as "all nodes reachable from
nodeby following outgoing edges". For that functionality, seeGraphs.reachableNodes(Graph, Object).
-
checkedConnections
protected final NetworkConnections<N,E> checkedConnections(N node)
-
containsNode
protected final boolean containsNode(N node)
-
containsEdge
protected final boolean containsEdge(E edge)
-
-