Class ValueGraphBuilder<N,​V>


  • @Beta
    public final class ValueGraphBuilder<N,​V>
    extends java.lang.Object
    A builder for constructing instances of MutableValueGraph 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:

    
     MutableValueGraph<String, Double> graph =
         ValueGraphBuilder.undirected().allowsSelfLoops(true).build();
     graph.putEdgeValue("San Francisco", "San Francisco", 0.0);
     graph.putEdgeValue("San Jose", "San Jose", 0.0);
     graph.putEdgeValue("San Francisco", "San Jose", 48.4);
     
    Since:
    20.0
    • Method Detail

      • allowsSelfLoops

        public ValueGraphBuilder<N,​V> 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 ValueGraphBuilder<N,​V> expectedNodeCount​(int expectedNodeCount)
        Specifies the expected number of nodes in the graph.
        Throws:
        java.lang.IllegalArgumentException - if expectedNodeCount is negative