From 2a33cfb2983ac06523156c20aaf5ce544d44707f Mon Sep 17 00:00:00 2001 From: Eduardo Ramos Date: Thu, 3 Aug 2017 20:21:39 +0200 Subject: [PATCH] Fix unreleased locks --- .../shortestpath/BellmanFordShortestPathAlgorithm.java | 5 ++++- .../main/java/org/gephi/io/exporter/plugin/ExporterDL.java | 7 ++++--- .../java/org/gephi/io/exporter/plugin/ExporterGEXF.java | 1 + .../org/gephi/layout/plugin/noverlap/NoverlapLayout.java | 5 ++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/AlgorithmsPlugin/src/main/java/org/gephi/algorithms/shortestpath/BellmanFordShortestPathAlgorithm.java b/modules/AlgorithmsPlugin/src/main/java/org/gephi/algorithms/shortestpath/BellmanFordShortestPathAlgorithm.java index 777909b898..0a44fdf808 100644 --- a/modules/AlgorithmsPlugin/src/main/java/org/gephi/algorithms/shortestpath/BellmanFordShortestPathAlgorithm.java +++ b/modules/AlgorithmsPlugin/src/main/java/org/gephi/algorithms/shortestpath/BellmanFordShortestPathAlgorithm.java @@ -45,6 +45,7 @@ Development and Distribution License("CDDL") (collectively, the import java.util.Map; import org.gephi.graph.api.DirectedGraph; import org.gephi.graph.api.Edge; +import org.gephi.graph.api.EdgeIterable; import org.gephi.graph.api.Node; /** @@ -92,8 +93,10 @@ public void compute() { } //Check for negative-weight cycles - for (Edge edge : graph.getEdges()) { + EdgeIterable edgesIterable = graph.getEdges(); + for (Edge edge : edgesIterable) { if (distances.get(edge.getSource()) + edgeWeight(edge) < distances.get(edge.getTarget())) { + edgesIterable.doBreak(); throw new RuntimeException("The Graph contains a negative-weighted cycle"); } } diff --git a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterDL.java b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterDL.java index 766b0b82c6..ff2a4d2f4e 100644 --- a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterDL.java +++ b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterDL.java @@ -184,12 +184,13 @@ private void saveAsEdgeList1(boolean useLabels, Graph graph) throws IOException writer.write("labels embedded:\n"); writer.write("data:\n"); - Iterator edgeIterator = graph.getEdges().iterator(); - while (edgeIterator.hasNext()) { + EdgeIterable edgesIterable = graph.getEdges(); + for (Edge edge : edgesIterable) { if (cancel) { + edgesIterable.doBreak(); break; } - Edge edge = edgeIterator.next(); + double weight = edge.getWeight(graph.getView()); if (useLabels) { diff --git a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGEXF.java b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGEXF.java index bb3c1ee110..f53467e101 100644 --- a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGEXF.java +++ b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGEXF.java @@ -601,6 +601,7 @@ private void writeEdges(XMLStreamWriter xmlWriter, Graph graph) throws Exception xmlWriter.writeEndElement(); Progress.progress(progress); if (cancel) { + edgeIterable.doBreak(); break; } } diff --git a/modules/LayoutPlugin/src/main/java/org/gephi/layout/plugin/noverlap/NoverlapLayout.java b/modules/LayoutPlugin/src/main/java/org/gephi/layout/plugin/noverlap/NoverlapLayout.java index 24e8f83cc2..82c86e46dd 100755 --- a/modules/LayoutPlugin/src/main/java/org/gephi/layout/plugin/noverlap/NoverlapLayout.java +++ b/modules/LayoutPlugin/src/main/java/org/gephi/layout/plugin/noverlap/NoverlapLayout.java @@ -54,6 +54,7 @@ Development and Distribution License("CDDL") (collectively, the import java.util.HashMap; import java.util.List; import java.util.Map; +import org.gephi.graph.api.NodeIterable; import org.openide.util.Exceptions; /** @@ -168,7 +169,8 @@ public void goAlgo() { // Proximities are built ! // Apply repulsion force - along proximities... - for (Node n1 : graph.getNodes()) { + NodeIterable nodesIterable = graph.getNodes(); + for (Node n1 : nodesIterable) { NoverlapLayoutData lald = n1.getLayoutData(); for (Node n2 : lald.neighbours) { float n1x = n1.x(); @@ -202,6 +204,7 @@ public void goAlgo() { } } if (cancel) { + nodesIterable.doBreak(); break; } }