Class ValueGraphBuilder<N,V>
- java.lang.Object
-
- com.google.common.graph.ValueGraphBuilder<N,V>
-
- Type Parameters:
N
- The most general node type this builder will support. This is normallyObject
unless it is constrained by using a method likenodeOrder(com.google.common.graph.ElementOrder<N1>)
, or the builder is constructed based on an existingValueGraph
usingfrom(ValueGraph)
.V
- The most general value type this builder will support. This is normallyObject
unless the builder is constructed based on an existingGraph
usingfrom(ValueGraph)
.
@Beta public final class ValueGraphBuilder<N,V> extends Object
A builder for constructing instances ofMutableValueGraph
orImmutableValueGraph
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)
ValueGraph
s 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
-
-
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 emptyMutableValueGraph
with the properties of thisValueGraphBuilder
.static ValueGraphBuilder<Object,Object>
directed()
Returns aValueGraphBuilder
for building directed graphs.ValueGraphBuilder<N,V>
expectedNodeCount(int expectedNodeCount)
Specifies the expected number of nodes in the graph.static <N,V>
ValueGraphBuilder<N,V>from(ValueGraph<N,V> graph)
Returns aValueGraphBuilder
initialized with all properties queryable fromgraph
.<N1 extends N,V1 extends V>
ImmutableValueGraph.Builder<N1,V1>immutable()
Returns anImmutableValueGraph.Builder
with the properties of thisValueGraphBuilder
.<N1 extends N>
ValueGraphBuilder<N1,V>incidentEdgeOrder(ElementOrder<N1> incidentEdgeOrder)
Specifies the order of iteration for the elements ofValueGraph.edges()
,ValueGraph.adjacentNodes(Object)
,ValueGraph.predecessors(Object)
,ValueGraph.successors(Object)
andValueGraph.incidentEdges(Object)
.<N1 extends N>
ValueGraphBuilder<N1,V>nodeOrder(ElementOrder<N1> nodeOrder)
Specifies the order of iteration for the elements ofGraph.nodes()
.static ValueGraphBuilder<Object,Object>
undirected()
Returns aValueGraphBuilder
for building undirected graphs.
-
-
-
Method Detail
-
directed
public static ValueGraphBuilder<Object,Object> directed()
Returns aValueGraphBuilder
for building directed graphs.
-
undirected
public static ValueGraphBuilder<Object,Object> undirected()
Returns aValueGraphBuilder
for building undirected graphs.
-
from
public static <N,V> ValueGraphBuilder<N,V> from(ValueGraph<N,V> graph)
Returns aValueGraphBuilder
initialized with all properties queryable fromgraph
.The "queryable" properties are those that are exposed through the
ValueGraph
interface, such asValueGraph.isDirected()
. Other properties, such asexpectedNodeCount(int)
, are not set in the new builder.
-
immutable
public <N1 extends N,V1 extends V> ImmutableValueGraph.Builder<N1,V1> immutable()
Returns anImmutableValueGraph.Builder
with the properties of thisValueGraphBuilder
.The returned builder can be used for populating an
ImmutableValueGraph
.Note that the returned builder will always have
incidentEdgeOrder(com.google.common.graph.ElementOrder<N1>)
set toElementOrder.stable()
, regardless of the value that was set in this builder.- Since:
- 28.0
-
allowsSelfLoops
@CanIgnoreReturnValue 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
.The default value is
false
.
-
expectedNodeCount
@CanIgnoreReturnValue public ValueGraphBuilder<N,V> expectedNodeCount(int expectedNodeCount)
Specifies the expected number of nodes in the graph.- Throws:
IllegalArgumentException
- ifexpectedNodeCount
is negative
-
nodeOrder
public <N1 extends N> ValueGraphBuilder<N1,V> nodeOrder(ElementOrder<N1> nodeOrder)
Specifies the order of iteration for the elements ofGraph.nodes()
.The default value is
insertion order
.
-
incidentEdgeOrder
public <N1 extends N> ValueGraphBuilder<N1,V> incidentEdgeOrder(ElementOrder<N1> incidentEdgeOrder)
Specifies the order of iteration for the elements ofValueGraph.edges()
,ValueGraph.adjacentNodes(Object)
,ValueGraph.predecessors(Object)
,ValueGraph.successors(Object)
andValueGraph.incidentEdges(Object)
.The default value is
unordered
for mutable graphs. For immutable graphs, this value is ignored; they always have astable
order.- Throws:
IllegalArgumentException
- ifincidentEdgeOrder
is not eitherElementOrder.unordered()
orElementOrder.stable()
.- Since:
- 29.0
-
build
public <N1 extends N,V1 extends V> MutableValueGraph<N1,V1> build()
Returns an emptyMutableValueGraph
with the properties of thisValueGraphBuilder
.
-
-