diff --git a/src/main/java/GraphModificationFunctions.java b/src/main/java/GraphModificationFunctions.java index 490f17f..624e6a1 100644 --- a/src/main/java/GraphModificationFunctions.java +++ b/src/main/java/GraphModificationFunctions.java @@ -9,15 +9,17 @@ public interface GraphModificationFunctions { static Map filterByOverlapThresholds(SimpleWeightedGraph graph, int low, int high, boolean saveEdges) { Map removedEdges = new HashMap<>(); + Set edgesToRemove = new HashSet<>(); for (DefaultWeightedEdge e : graph.edgeSet()) { if ((graph.getEdgeWeight(e) > high) || (graph.getEdgeWeight(e) < low)) { if(saveEdges) { Vertex[] vertices = {graph.getEdgeSource(e), graph.getEdgeTarget(e)}; removedEdges.put(e, vertices); } - graph.removeEdge(e); + edgesToRemove.add(e); } } + edgesToRemove.forEach(graph::removeEdge); return removedEdges; } @@ -25,6 +27,7 @@ public interface GraphModificationFunctions { static Map filterByRelativeOccupancy(SimpleWeightedGraph graph, Integer maxOccupancyDifference, boolean saveEdges) { Map removedEdges = new HashMap<>(); + Set edgesToRemove = new HashSet<>(); for (DefaultWeightedEdge e : graph.edgeSet()) { Integer alphaOcc = graph.getEdgeSource(e).getOccupancy(); Integer betaOcc = graph.getEdgeTarget(e).getOccupancy(); @@ -33,9 +36,10 @@ public interface GraphModificationFunctions { Vertex[] vertices = {graph.getEdgeSource(e), graph.getEdgeTarget(e)}; removedEdges.put(e, vertices); } - graph.removeEdge(e); + edgesToRemove.add(e); } } + edgesToRemove.forEach(graph::removeEdge); return removedEdges; } @@ -44,6 +48,7 @@ public interface GraphModificationFunctions { Integer minOverlapPercent, boolean saveEdges) { Map removedEdges = new HashMap<>(); + Set edgesToRemove = new HashSet<>(); for (DefaultWeightedEdge e : graph.edgeSet()) { Integer alphaOcc = graph.getEdgeSource(e).getOccupancy(); Integer betaOcc = graph.getEdgeTarget(e).getOccupancy(); @@ -54,9 +59,10 @@ public interface GraphModificationFunctions { Vertex[] vertices = {graph.getEdgeSource(e), graph.getEdgeTarget(e)}; removedEdges.put(e, vertices); } - graph.removeEdge(e); + edgesToRemove.add(e); } } + edgesToRemove.forEach(graph::removeEdge); return removedEdges; }