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)
.E
- 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
or ImmutableNetwork
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
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();
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,E1 extends E> |
immutable()
Returns an
ImmutableNetwork.Builder with the properties of this NetworkBuilder . |
<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 <N1 extends N,E1 extends E> ImmutableNetwork.Builder<N1,E1> immutable()
ImmutableNetwork.Builder
with the properties of this NetworkBuilder
.
The returned builder can be used for populating an ImmutableNetwork
.
public NetworkBuilder<N,E> allowsParallelEdges(boolean allowsParallelEdges)
UnsupportedOperationException
.
The default value is false
.
public NetworkBuilder<N,E> allowsSelfLoops(boolean allowsSelfLoops)
UnsupportedOperationException
.
The default value is false
.
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()
.
The default value is insertion order
.
public <E1 extends E> NetworkBuilder<N,E1> edgeOrder(ElementOrder<E1> edgeOrder)
Network.edges()
.
The default value is insertion order
.
public <N1 extends N,E1 extends E> MutableNetwork<N1,E1> build()
MutableNetwork
with the properties of this NetworkBuilder
.Copyright © 2010–2020. All rights reserved.