Class GraphBuilder<N>


  • @Beta
    public final class GraphBuilder<N>
    extends java.lang.Object
    A builder for constructing instances of MutableGraph with user-defined properties.

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

    • does not allow self-loops
    • orders Graph.nodes() in the order in which the elements were added

    Example of use:

    
     MutableGraph<String> graph = GraphBuilder.undirected().allowsSelfLoops(true).build();
     graph.putEdge("bread", "bread");
     graph.putEdge("chocolate", "peanut butter");
     graph.putEdge("peanut butter", "jelly");
     
    Since:
    20.0
    • Method Detail

      • directed

        public static GraphBuilder<java.lang.Object> directed()
        Returns a GraphBuilder for building directed graphs.
      • undirected

        public static GraphBuilder<java.lang.Object> undirected()
        Returns a GraphBuilder for building undirected graphs.
      • allowsSelfLoops

        public GraphBuilder<N> allowsSelfLoops​(boolean allowsSelfLoops)
        Specifies whether the graph will allow self-loops (edges that connect a node to itself). Attempting to add a self-loop to a graph that does not allow them will throw an UnsupportedOperationException.
      • expectedNodeCount

        public GraphBuilder<N> expectedNodeCount​(int expectedNodeCount)
        Specifies the expected number of nodes in the graph.
        Throws:
        java.lang.IllegalArgumentException - if expectedNodeCount is negative