Skip to content

Users: MigrationTo0.7

Timofey Chudakov edited this page Jan 25, 2020 · 1 revision

The following breaking changes were made to JGraphT interfaces during the transition from 0.6 to 0.7. (By itself, the addition of generics does not count as a breaking change because of type-erasure at the source level, and the usage of retroweaver at the classfile level.) The biggest changes relate to the fact that the edge interface/package was deleted and all connectivity and weighting info moved to the Graph interface.

  • rename package org._3pq.jgrapht to org.jgrapht
  • delete package org.jgrapht.edge
  • GraphHelper: rename to Graphs (for consistency with java.util Arrays/Collections convention), leaving old class behind as a deprecated subclass; change many method signatures to match Graph interface changes below
  • Graph.addAllEdges: move to GraphHelper and take source graph parameter
  • Graph.addAllVertices: move to GraphHelper (for consistency with addAllEdges)
  • Graph.addEdge: remove addEdge(E) variant; introduce addEdge(V, V, E) variant
  • Graph.getEdgeSource: new method
  • Graph.getEdgeTarget: new method
  • Graph.getEdgeWeight: new method
  • WeightedGraph.setEdgeWeight: new method
  • introduce new classes DefaultEdge, DefaultWeightedEdge, ClassBasedEdgeFactory in org.jgrapht.graph
  • for "gallery" classes in org.jgrapht.graph, remove default constructors and introduce new constructor taking Class
  • rename EdgeListFactory to EdgeSetFactory, and change edge collections from Lists to Sets
  • remove LabeledElement
  • remove all deprecated methods such as verifyIntegrity methods on Subgraph

So, where before you might have written:

DirectedGraph g = getYerGraph(…);
Iterator iter = g.outgoingEdgesOf(v).iterator();
while (iter.hasNext()) {
    YerEdge e = (YerEdge) iter.next();
    YerVertex v = (YerVertex) e.getTarget();
    System.out.println("target = " + v);
}

now you'll write:

DirectedGraph<YerVertex, YerEdge> g = getYerGraph(&#8230;);
for (YerEdge e : g.outgoingEdgesOf(v)) {
    YerVertex v = g.getEdgeTarget(e);
    System.out.println("target = " + v);
}

Because the gallery graphs no longer have default constructors, graph instantiation now looks like this:

DirectedGraph<YerVertex, YerEdge> g =
    new DefaultDirectedGraph<YerVertex, YerEdge>(YerEdge.class);

The edge-class object passed into the constructor is used as a factory to create new edge instances. (Unfortunately, Java generics do not allow new edge objects to be created based on the generic type parameter alone.)

If you are not using generics, you still have to pass something (typically DefaultEdge.class or DefaultWeightedEdge.class):

DirectedGraph g = new DefaultDirectedGraph(DefaultEdge.class);
Clone this wiki locally