Class ImmutableNetwork.Builder<N,​E>

  • Enclosing class:
    ImmutableNetwork<N,​E>

    public static class ImmutableNetwork.Builder<N,​E>
    extends Object
    A builder for creating ImmutableNetwork instances, especially static final networks. Example:
    
     static final ImmutableNetwork<City, Train> TRAIN_NETWORK =
         NetworkBuilder.undirected()
             .allowsParallelEdges(true)
             .<City, Train>immutable()
             .addEdge(PARIS, BRUSSELS, Thalys.trainNumber("1111"))
             .addEdge(PARIS, BRUSSELS, RegionalTrain.trainNumber("2222"))
             .addEdge(LONDON, PARIS, Eurostar.trainNumber("3333"))
             .addEdge(LONDON, BRUSSELS, Eurostar.trainNumber("4444"))
             .addNode(REYKJAVIK)
             .build();
     

    Builder instances can be reused; it is safe to call build() multiple times to build multiple networks in series. Each new network contains all the elements of the ones created before it.

    Since:
    28.0
    • Method Detail

      • addEdge

        @CanIgnoreReturnValue
        public ImmutableNetwork.Builder<N,​EaddEdge​(EndpointPair<N> endpoints,
                                                           E edge)
        Adds edge connecting endpoints. In an undirected network, edge will also connect nodeV to nodeU.

        If this network is directed, edge will be directed in this network; if it is undirected, edge will be undirected in this network.

        If this network is directed, endpoints must be ordered.

        edge must be unique to this network, just as a Map key must be. It must also be non-null.

        If either or both endpoints are not already present in this network, this method will silently add each missing endpoint to the network.

        If edge already connects an endpoint pair equal to endpoints, then this method will have no effect.

        Returns:
        this Builder object
        Throws:
        IllegalArgumentException - if edge already exists in the network and connects some other endpoint pair that is not equal to endpoints
        IllegalArgumentException - if the introduction of the edge would violate Network.allowsParallelEdges() or Network.allowsSelfLoops()
        IllegalArgumentException - if the endpoints are unordered and the network is directed
      • build

        public ImmutableNetwork<N,​Ebuild()
        Returns a newly-created ImmutableNetwork based on the contents of this Builder.