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 normallyObject
unless it is constrained by using a method likenodeOrder(com.google.common.graph.ElementOrder<N1>)
, or the builder is constructed based on an existingNetwork
usingfrom(Network)
.E
- The most general edge type this builder will support. This is normallyObject
unless it is constrained by using a method likeedgeOrder
, or the builder is constructed based on an existingNetwork
usingfrom(Network)
.
A builder for constructing instances of
MutableNetwork
or ImmutableNetwork
with
user-defined properties.
A Network
built by this class has the following default properties:
- does not allow parallel edges
- does not allow self-loops
- orders
Network.nodes()
andNetwork.edges()
in the order in which the elements were added (insertion order)
Network
s built by this class also guarantee that each collection-returning accessor
returns a (live) unmodifiable view; see the external
documentation for details.
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 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,
E1 extends E>
ImmutableNetwork.Builder<N1, E1> Returns anImmutableNetwork.Builder
with 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> 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. -
immutable
Returns anImmutableNetwork.Builder
with the properties of thisNetworkBuilder
.The returned builder can be used for populating an
ImmutableNetwork
.- Since:
- 28.0
-
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
. -
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
. -
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()
.The default value is
insertion order
. -
edgeOrder
Specifies the order of iteration for the elements ofNetwork.edges()
.The default value is
insertion order
. -
build
Returns an emptyMutableNetwork
with the properties of thisNetworkBuilder
.
-