Package com.google.common.graph
Class ValueGraphBuilder<N,V>
java.lang.Object
com.google.common.graph.ValueGraphBuilder<N,V>
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 Summary
Modifier and TypeMethodDescriptionallowsSelfLoops
(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 emptyMutableValueGraph
with the properties of thisValueGraphBuilder
.static ValueGraphBuilder
<Object, Object> directed()
Returns aValueGraphBuilder
for building directed graphs.expectedNodeCount
(int expectedNodeCount) Specifies the expected number of nodes in the graph.static <N> ValueGraphBuilder
<N, Object> Returns aValueGraphBuilder
initialized 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
<Object, Object> Returns aValueGraphBuilder
for building undirected graphs.
-
Method Details
-
directed
Returns aValueGraphBuilder
for building directed graphs. -
undirected
Returns aValueGraphBuilder
for building undirected graphs. -
from
Returns aValueGraphBuilder
initialized with all properties queryable fromgraph
.The "queryable" properties are those that are exposed through the
Graph
interface, such asGraph.isDirected()
. Other properties, such asexpectedNodeCount(int)
, are not set in the new builder. -
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
Specifies the expected number of nodes in the graph.- Throws:
IllegalArgumentException
- ifexpectedNodeCount
is negative
-
nodeOrder
Specifies the order of iteration for the elements ofGraph.nodes()
. -
build
Returns an emptyMutableValueGraph
with the properties of thisValueGraphBuilder
.
-