Package com.google.common.graph
Class ValueGraphBuilder<N,V>
- java.lang.Object
-
- com.google.common.graph.ValueGraphBuilder<N,V>
-
@Beta public final class ValueGraphBuilder<N,V> extends java.lang.Object
A builder for constructing instances ofMutableValueGraphwith 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 Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ValueGraphBuilder<N,V>allowsSelfLoops(boolean allowsSelfLoops)Specifies whether the graph will allow self-loops (edges that connect a node to itself).<N1 extends N,V1 extends V>
MutableValueGraph<N1,V1>build()Returns an emptyMutableValueGraphwith the properties of thisValueGraphBuilder.static ValueGraphBuilder<java.lang.Object,java.lang.Object>directed()Returns aValueGraphBuilderfor building directed graphs.ValueGraphBuilder<N,V>expectedNodeCount(int expectedNodeCount)Specifies the expected number of nodes in the graph.static <N> ValueGraphBuilder<N,java.lang.Object>from(Graph<N> graph)Returns aValueGraphBuilderinitialized with all properties queryable fromgraph.<N1 extends N>
ValueGraphBuilder<N1,V>nodeOrder(ElementOrder<N1> nodeOrder)Specifies the order of iteration for the elements ofGraph.nodes().static ValueGraphBuilder<java.lang.Object,java.lang.Object>undirected()Returns aValueGraphBuilderfor building undirected graphs.
-
-
-
Method Detail
-
directed
public static ValueGraphBuilder<java.lang.Object,java.lang.Object> directed()
Returns aValueGraphBuilderfor building directed graphs.
-
undirected
public static ValueGraphBuilder<java.lang.Object,java.lang.Object> undirected()
Returns aValueGraphBuilderfor building undirected graphs.
-
from
public static <N> ValueGraphBuilder<N,java.lang.Object> from(Graph<N> graph)
Returns aValueGraphBuilderinitialized with all properties queryable fromgraph.The "queryable" properties are those that are exposed through the
Graphinterface, such asGraph.isDirected(). Other properties, such asexpectedNodeCount(int), are not set in the new builder.
-
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 anUnsupportedOperationException.
-
expectedNodeCount
public ValueGraphBuilder<N,V> expectedNodeCount(int expectedNodeCount)
Specifies the expected number of nodes in the graph.- Throws:
java.lang.IllegalArgumentException- ifexpectedNodeCountis negative
-
nodeOrder
public <N1 extends N> ValueGraphBuilder<N1,V> nodeOrder(ElementOrder<N1> nodeOrder)
Specifies the order of iteration for the elements ofGraph.nodes().
-
build
public <N1 extends N,V1 extends V> MutableValueGraph<N1,V1> build()
Returns an emptyMutableValueGraphwith the properties of thisValueGraphBuilder.
-
-