Package com.google.common.graph
Class NetworkBuilder<N,E>
- java.lang.Object
- 
- com.google.common.graph.NetworkBuilder<N,E>
 
- 
- Type Parameters:
- N- The most general node type this builder will support. This is normally- Objectunless it is constrained by using a method like- nodeOrder(com.google.common.graph.ElementOrder<N1>), or the builder is constructed based on an existing- Networkusing- from(Network).
- E- The most general edge type this builder will support. This is normally- Objectunless it is constrained by using a method like- edgeOrder, or the builder is constructed based on an existing- Networkusing- from(Network).
 
 @Beta public final class NetworkBuilder<N,E> extends Object A builder for constructing instances ofMutableNetworkorImmutableNetworkwith 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
 Examples of use: // Building a mutable network MutableNetwork<String, Integer> network = NetworkBuilder.directed().allowsParallelEdges(true).build(); flightNetwork.addEdge("LAX", "ATL", 3025); flightNetwork.addEdge("LAX", "ATL", 1598); flightNetwork.addEdge("ATL", "LAX", 2450); // Building a immutable network ImmutableNetwork<String, Integer> immutableNetwork = NetworkBuilder.directed() .allowsParallelEdges(true) .<String, Integer>immutable() .addEdge("LAX", "ATL", 3025) .addEdge("LAX", "ATL", 1598) .addEdge("ATL", "LAX", 2450) .build();- Since:
- 20.0
- Author:
- James Sexton, Joshua O'Madadhain
 
- 
- 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description NetworkBuilder<N,E>allowsParallelEdges(boolean allowsParallelEdges)Specifies whether the network will allow parallel edges.NetworkBuilder<N,E>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 emptyMutableNetworkwith the properties of thisNetworkBuilder.static NetworkBuilder<Object,Object>directed()Returns aNetworkBuilderfor building directed networks.<E1 extends E>
 NetworkBuilder<N,E1>edgeOrder(ElementOrder<E1> edgeOrder)Specifies the order of iteration for the elements ofNetwork.edges().NetworkBuilder<N,E>expectedEdgeCount(int expectedEdgeCount)Specifies the expected number of edges in the network.NetworkBuilder<N,E>expectedNodeCount(int expectedNodeCount)Specifies the expected number of nodes in the network.static <N,E>
 NetworkBuilder<N,E>from(Network<N,E> network)Returns aNetworkBuilderinitialized with all properties queryable fromnetwork.<N1 extends N,E1 extends E>
 ImmutableNetwork.Builder<N1,E1>immutable()Returns anImmutableNetwork.Builderwith the properties of thisNetworkBuilder.<N1 extends N>
 NetworkBuilder<N1,E>nodeOrder(ElementOrder<N1> nodeOrder)Specifies the order of iteration for the elements ofNetwork.nodes().static NetworkBuilder<Object,Object>undirected()Returns aNetworkBuilderfor building undirected networks.
 
- 
- 
- 
Method Detail- 
directedpublic static NetworkBuilder<Object,Object> directed() Returns aNetworkBuilderfor building directed networks.
 - 
undirectedpublic static NetworkBuilder<Object,Object> undirected() Returns aNetworkBuilderfor building undirected networks.
 - 
frompublic static <N,E> NetworkBuilder<N,E> from(Network<N,E> network) Returns aNetworkBuilderinitialized with all properties queryable fromnetwork.The "queryable" properties are those that are exposed through the Networkinterface, such asNetwork.isDirected(). Other properties, such asexpectedNodeCount(int), are not set in the new builder.
 - 
immutablepublic <N1 extends N,E1 extends E> ImmutableNetwork.Builder<N1,E1> immutable() Returns anImmutableNetwork.Builderwith the properties of thisNetworkBuilder.The returned builder can be used for populating an ImmutableNetwork.- Since:
- 28.0
 
 - 
allowsParallelEdgespublic NetworkBuilder<N,E> allowsParallelEdges(boolean 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.The default value is false.
 - 
allowsSelfLoopspublic NetworkBuilder<N,E> allowsSelfLoops(boolean 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.The default value is false.
 - 
expectedNodeCountpublic NetworkBuilder<N,E> expectedNodeCount(int expectedNodeCount) Specifies the expected number of nodes in the network.- Throws:
- IllegalArgumentException- if- expectedNodeCountis negative
 
 - 
expectedEdgeCountpublic NetworkBuilder<N,E> expectedEdgeCount(int expectedEdgeCount) Specifies the expected number of edges in the network.- Throws:
- IllegalArgumentException- if- expectedEdgeCountis negative
 
 - 
nodeOrderpublic <N1 extends N> NetworkBuilder<N1,E> nodeOrder(ElementOrder<N1> nodeOrder) Specifies the order of iteration for the elements ofNetwork.nodes().The default value is insertion order.
 - 
edgeOrderpublic <E1 extends E> NetworkBuilder<N,E1> edgeOrder(ElementOrder<E1> edgeOrder) Specifies the order of iteration for the elements ofNetwork.edges().The default value is insertion order.
 - 
buildpublic <N1 extends N,E1 extends E> MutableNetwork<N1,E1> build() Returns an emptyMutableNetworkwith the properties of thisNetworkBuilder.
 
- 
 
-