jgrapht/jgrapht — pull request #82 by tfeicht (2014-04-18 05:40:55+00:00)
Title: Feature/builder

followup on MR#81: I moved the builder into the respective graph classes as a static class. now it is possible to create a new graph like this:

```java
new SimpleGraph.Builder(DefaultEdge.class) ...
```

What
-----
Builders for SimpleGraph and SimpleWeightedGraph.

Why
-----
Right now initializing graphs is very verbose:
* create an empty graph
* add vertices one by one
* add edges
* possibly set weights

With the builder object this can be done in a much more concise way.

Example:

```java
g = new SimpleWeightedGraph.Builder(DefaultWeightedEdge.class)
.edge(V1, V2, 1.0).edge(V1, V3, 2.0).edge(V3, V4, 3.0).edge(V2, V4, 4.0).build();
```
vs.

```java
g = new SimpleWeightedGraph(DefaultWeightedEdge.class);

regularWeightedGraph.addVertex(V1);
regularWeightedGraph.addVertex(V2);
regularWeightedGraph.addVertex(V3);
regularWeightedGraph.addVertex(V4);

regularWeightedGraph.setEdgeWeight(regularWeightedGraph.addEdge(V1, V2), 1.0);
regularWeightedGraph.setEdgeWeight(regularWeightedGraph.addEdge(V1, V3), 2.0);
regularWeightedGraph.setEdgeWeight(regularWeightedGraph.addEdge(V3, V4), 3.0);
regularWeightedGraph.setEdgeWeight(regularWeightedGraph.addEdge(V2, V4), 4.0);
```

If you think this is useful I will be open to implement builders for the other graph types.