Reputation: 25236
While it's good that JGraphT separates the act of adding vertices and adding edges, surely there's a case when you'd want to combine the two? In other words, if you try to add an edge where either (or both) of the vertices aren't in the graph, then add them?
Does JGraphT have such a shortcut to writing 3 method calls?
Upvotes: 2
Views: 474
Reputation: 147
You could simply override JGraphT's method to make it add vertices that are not yet present in the graph:
@Override
public E addEdge(V sourceVertex, V targetVertex) {
if (!containsVertex(sourceVertex)) {
addVertex(sourceVertex);
}
if (!containsVertex(targetVertex)) {
addVertex(targetVertex);
}
return super.addEdge(sourceVertex, targetVertex);
}
Upvotes: 1