Package com.google.common.graph
Class NetworkBuilder<N,E>
java.lang.Object
com.google.common.graph.NetworkBuilder<N,E>
A builder for constructing instances of
MutableNetwork
with user-defined properties.
A network built by this class will have the following properties by default:
- does not allow parallel edges
- does not allow self-loops
- orders
Network.nodes()
andNetwork.edges()
in the order in which the elements were added
Example of use:
MutableNetwork<String, Integer> flightNetwork =
NetworkBuilder.directed().allowsParallelEdges(true).build();
flightNetwork.addEdge("LAX", "ATL", 3025);
flightNetwork.addEdge("LAX", "ATL", 1598);
flightNetwork.addEdge("ATL", "LAX", 2450);
- Since:
- 20.0
-
Method Summary
Modifier and TypeMethodDescriptionallowsParallelEdges
(boolean allowsParallelEdges) Specifies whether the network will allow parallel edges.allowsSelfLoops
(boolean allowsSelfLoops) Specifies whether the network will allow self-loops (edges that connect a node to itself).<N1 extends N,
E1 extends E>
MutableNetwork<N1, E1> build()
Returns an emptyMutableNetwork
with the properties of thisNetworkBuilder
.static NetworkBuilder
<Object, Object> directed()
Returns aNetworkBuilder
for building directed networks.<E1 extends E>
NetworkBuilder<N, E1> edgeOrder
(ElementOrder<E1> edgeOrder) Specifies the order of iteration for the elements ofNetwork.edges()
.expectedEdgeCount
(int expectedEdgeCount) Specifies the expected number of edges in the network.expectedNodeCount
(int expectedNodeCount) Specifies the expected number of nodes in the network.static <N,
E> NetworkBuilder <N, E> Returns aNetworkBuilder
initialized with all properties queryable fromnetwork
.<N1 extends N>
NetworkBuilder<N1, E> nodeOrder
(ElementOrder<N1> nodeOrder) Specifies the order of iteration for the elements ofNetwork.nodes()
.static NetworkBuilder
<Object, Object> Returns aNetworkBuilder
for building undirected networks.
-
Method Details
-
directed
Returns aNetworkBuilder
for building directed networks. -
undirected
Returns aNetworkBuilder
for building undirected networks. -
from
Returns aNetworkBuilder
initialized with all properties queryable fromnetwork
.The "queryable" properties are those that are exposed through the
Network
interface, such asNetwork.isDirected()
. Other properties, such asexpectedNodeCount(int)
, are not set in the new builder. -
allowsParallelEdges
Specifies whether the network will allow parallel edges. Attempting to add a parallel edge to a network that does not allow them will throw anUnsupportedOperationException
. -
allowsSelfLoops
Specifies whether the network will allow 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 anUnsupportedOperationException
. -
expectedNodeCount
Specifies the expected number of nodes in the network.- Throws:
IllegalArgumentException
- ifexpectedNodeCount
is negative
-
expectedEdgeCount
Specifies the expected number of edges in the network.- Throws:
IllegalArgumentException
- ifexpectedEdgeCount
is negative
-
nodeOrder
Specifies the order of iteration for the elements ofNetwork.nodes()
. -
edgeOrder
Specifies the order of iteration for the elements ofNetwork.edges()
. -
build
Returns an emptyMutableNetwork
with the properties of thisNetworkBuilder
.
-