Class ValueGraphBuilder<N,​V>

  • Type Parameters:
    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 ValueGraph using from(ValueGraph).
    V - The most general value type this builder will support. This is normally Object unless the builder is constructed based on an existing Graph using from(ValueGraph).

    @Beta
    public final class ValueGraphBuilder<N,​V>
    extends java.lang.Object
    A builder for constructing instances of MutableValueGraph or ImmutableValueGraph with user-defined properties.

    A ValueGraph built by this class has the following default properties:

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

    ValueGraphs built by this class also guarantee that each collection-returning accessor returns a (live) unmodifiable view; see the external documentation for details.

    Examples of use:

    
     // Building a mutable value graph
     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);
    
     // Building an immutable value graph
     ImmutableValueGraph<String, Double> immutableGraph =
         ValueGraphBuilder.undirected()
             .allowsSelfLoops(true)
             .<String, Double>immutable()
             .putEdgeValue("San Francisco", "San Francisco", 0.0)
             .putEdgeValue("San Jose", "San Jose", 0.0)
             .putEdgeValue("San Francisco", "San Jose", 48.4)
             .build();
     
    Since:
    20.0
    Author:
    James Sexton, Joshua O'Madadhain