@Beta public final class ValueGraphBuilder<N,V> extends AbstractGraphBuilder<N>
MutableValueGraph
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
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);
allowsSelfLoops, directed, expectedNodeCount, nodeOrder
Modifier | Constructor and Description |
---|---|
private |
ValueGraphBuilder(boolean directed)
Creates a new instance with the specified edge directionality.
|
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 . |
private <N1 extends N,V1 extends V> |
cast() |
static ValueGraphBuilder<java.lang.Object,java.lang.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> ValueGraphBuilder<N,java.lang.Object> |
from(Graph<N> graph)
Returns a
ValueGraphBuilder initialized with all properties queryable from graph . |
<N1 extends N> |
nodeOrder(ElementOrder<N1> nodeOrder)
Specifies the order of iteration for the elements of
Graph.nodes() . |
static ValueGraphBuilder<java.lang.Object,java.lang.Object> |
undirected()
Returns a
ValueGraphBuilder for building undirected graphs. |
private ValueGraphBuilder(boolean directed)
public static ValueGraphBuilder<java.lang.Object,java.lang.Object> directed()
ValueGraphBuilder
for building directed graphs.public static ValueGraphBuilder<java.lang.Object,java.lang.Object> undirected()
ValueGraphBuilder
for building undirected graphs.public static <N> ValueGraphBuilder<N,java.lang.Object> from(Graph<N> graph)
ValueGraphBuilder
initialized with all properties queryable from graph
.
The "queryable" properties are those that are exposed through the Graph
interface,
such as Graph.isDirected()
. Other properties, such as expectedNodeCount(int)
,
are not set in the new builder.
public ValueGraphBuilder<N,V> allowsSelfLoops(boolean allowsSelfLoops)
UnsupportedOperationException
.public ValueGraphBuilder<N,V> expectedNodeCount(int expectedNodeCount)
java.lang.IllegalArgumentException
- if expectedNodeCount
is negativepublic <N1 extends N> ValueGraphBuilder<N1,V> nodeOrder(ElementOrder<N1> nodeOrder)
Graph.nodes()
.public <N1 extends N,V1 extends V> MutableValueGraph<N1,V1> build()
MutableValueGraph
with the properties of this ValueGraphBuilder
.private <N1 extends N,V1 extends V> ValueGraphBuilder<N1,V1> cast()