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 Object
MutableValueGraph
or ImmutableValueGraph
with user-defined properties.
A graph built by this class will have the following properties by default:
Graph.nodes()
in the order in which the elements were added
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();
Modifier and Type | Method and 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> |
build()
Returns an empty
MutableValueGraph with the properties of this ValueGraphBuilder . |
static ValueGraphBuilder<Object,Object> |
directed()
Returns a
ValueGraphBuilder 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 a
ValueGraphBuilder initialized with all properties queryable from graph . |
<N1 extends N,V1 extends V> |
immutable()
Returns an
ImmutableValueGraph.Builder with the properties of this ValueGraphBuilder . |
<N1 extends N> |
incidentEdgeOrder(ElementOrder<N1> incidentEdgeOrder)
Specifies the order of iteration for the elements of
ValueGraph.edges() , ValueGraph.adjacentNodes(Object) , ValueGraph.predecessors(Object) , ValueGraph.successors(Object) and ValueGraph.incidentEdges(Object) . |
<N1 extends N> |
nodeOrder(ElementOrder<N1> nodeOrder)
Specifies the order of iteration for the elements of
Graph.nodes() . |
static ValueGraphBuilder<Object,Object> |
undirected()
Returns a
ValueGraphBuilder for building undirected graphs. |
public static ValueGraphBuilder<Object,Object> directed()
ValueGraphBuilder
for building directed graphs.public static ValueGraphBuilder<Object,Object> undirected()
ValueGraphBuilder
for building undirected graphs.public static <N,V> ValueGraphBuilder<N,V> from(ValueGraph<N,V> graph)
ValueGraphBuilder
initialized with all properties queryable from graph
.
The "queryable" properties are those that are exposed through the ValueGraph
interface, such as ValueGraph.isDirected()
. Other properties, such as expectedNodeCount(int)
, are not set in the new builder.
public <N1 extends N,V1 extends V> ImmutableValueGraph.Builder<N1,V1> immutable()
ImmutableValueGraph.Builder
with the properties of this ValueGraphBuilder
.
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 to ElementOrder.stable()
, regardless of the value that was set in this builder.
public ValueGraphBuilder<N,V> allowsSelfLoops(boolean allowsSelfLoops)
UnsupportedOperationException
.
The default value is false
.
public ValueGraphBuilder<N,V> expectedNodeCount(int expectedNodeCount)
IllegalArgumentException
- if expectedNodeCount
is negativepublic <N1 extends N> ValueGraphBuilder<N1,V> nodeOrder(ElementOrder<N1> nodeOrder)
Graph.nodes()
.
The default value is insertion order
.
public <N1 extends N> ValueGraphBuilder<N1,V> incidentEdgeOrder(ElementOrder<N1> incidentEdgeOrder)
ValueGraph.edges()
, ValueGraph.adjacentNodes(Object)
, ValueGraph.predecessors(Object)
, ValueGraph.successors(Object)
and ValueGraph.incidentEdges(Object)
.
The default value is unordered
for mutable graphs. For
immutable graphs, this value is ignored; they always have a stable
order.
IllegalArgumentException
- if incidentEdgeOrder
is not either ElementOrder.unordered()
or ElementOrder.stable()
.public <N1 extends N,V1 extends V> MutableValueGraph<N1,V1> build()
MutableValueGraph
with the properties of this ValueGraphBuilder
.Copyright © 2010–2020. All rights reserved.