Class NetworkBuilder<N,​E>


  • @Beta
    public final class NetworkBuilder<N,​E>
    extends java.lang.Object
    A builder for constructing instances of MutableNetwork with user-defined properties.

    A network built by this class will have the following properties by default:

    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);
     
    Since:
    20.0
    • Method Detail

      • directed

        public static NetworkBuilder<java.lang.Object,​java.lang.Object> directed()
        Returns a NetworkBuilder for building directed networks.
      • undirected

        public static NetworkBuilder<java.lang.Object,​java.lang.Object> undirected()
        Returns a NetworkBuilder for building undirected networks.
      • allowsParallelEdges

        public 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 an UnsupportedOperationException.
      • allowsSelfLoops

        public 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 an UnsupportedOperationException.
      • expectedNodeCount

        public NetworkBuilder<N,​E> expectedNodeCount​(int expectedNodeCount)
        Specifies the expected number of nodes in the network.
        Throws:
        java.lang.IllegalArgumentException - if expectedNodeCount is negative
      • expectedEdgeCount

        public NetworkBuilder<N,​E> expectedEdgeCount​(int expectedEdgeCount)
        Specifies the expected number of edges in the network.
        Throws:
        java.lang.IllegalArgumentException - if expectedEdgeCount is negative