N
- The most general node type this builder will support. This is normally Object
unless it is constrained by using a method like nodeOrder(com.google.common.graph.ElementOrder<N1>)
, or the builder is
constructed based on an existing Network
using from(Network)
.N
- The most general edge type this builder will support. This is normally Object
unless it is constrained by using a method like edgeOrder
, or the builder is
constructed based on an existing Network
using from(Network)
.@Beta public final class NetworkBuilder<N,E> extends Object
MutableNetwork
with user-defined properties.
A network built by this class will have the following properties by default:
Network.nodes()
and Network.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);
Modifier and Type | Method and 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> |
build()
Returns an empty
MutableNetwork with the properties of this NetworkBuilder . |
static NetworkBuilder<Object,Object> |
directed()
Returns a
NetworkBuilder for building directed networks. |
<E1 extends E> |
edgeOrder(ElementOrder<E1> edgeOrder)
Specifies the order of iteration for the elements of
Network.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 a
NetworkBuilder initialized with all properties queryable from network . |
<N1 extends N> |
nodeOrder(ElementOrder<N1> nodeOrder)
Specifies the order of iteration for the elements of
Network.nodes() . |
static NetworkBuilder<Object,Object> |
undirected()
Returns a
NetworkBuilder for building undirected networks. |
public static NetworkBuilder<Object,Object> directed()
NetworkBuilder
for building directed networks.public static NetworkBuilder<Object,Object> undirected()
NetworkBuilder
for building undirected networks.public static <N,E> NetworkBuilder<N,E> from(Network<N,E> network)
NetworkBuilder
initialized with all properties queryable from network
.
The "queryable" properties are those that are exposed through the Network
interface,
such as Network.isDirected()
. Other properties, such as expectedNodeCount(int)
, are not set in the new builder.
public NetworkBuilder<N,E> allowsParallelEdges(boolean allowsParallelEdges)
UnsupportedOperationException
.public NetworkBuilder<N,E> allowsSelfLoops(boolean allowsSelfLoops)
UnsupportedOperationException
.public NetworkBuilder<N,E> expectedNodeCount(int expectedNodeCount)
IllegalArgumentException
- if expectedNodeCount
is negativepublic NetworkBuilder<N,E> expectedEdgeCount(int expectedEdgeCount)
IllegalArgumentException
- if expectedEdgeCount
is negativepublic <N1 extends N> NetworkBuilder<N1,E> nodeOrder(ElementOrder<N1> nodeOrder)
Network.nodes()
.public <E1 extends E> NetworkBuilder<N,E1> edgeOrder(ElementOrder<E1> edgeOrder)
Network.edges()
.public <N1 extends N,E1 extends E> MutableNetwork<N1,E1> build()
MutableNetwork
with the properties of this NetworkBuilder
.Copyright © 2010–2019. All rights reserved.