Skip to content
This repository was archived by the owner on Jun 18, 2026. It is now read-only.

Commit 260efaa

Browse files
fix: remove 20 unused imports, deduplicate BFS implementations (#76)
Two improvements: 1. Code cleanup — removed 20 unused imports across 18 files: - 8 files had unused UndirectedSparseGraph/DirectedSparseGraph/ UndirectedGraph imports from edu.uci.ics.jung.graph - 10 files had unused java.util.stream.Collectors imports 2. Refactor — eliminated duplicate BFS implementations: - GraphNetworkProfiler: removed 19-line private bfs() method, replaced 3 call sites with GraphUtils.bfsDistances() - ForceDirectedLayout: removed 10-line private bfsDistances() method, replaced 1 call site with GraphUtils.bfsDistances() - GraphUtils.bfsDistances() already provides the same functionality; these were unnecessary copies
1 parent 8db3a63 commit 260efaa

20 files changed

Lines changed: 4 additions & 53 deletions

Gvisual/src/gvisual/CycleAnalyzer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import edu.uci.ics.jung.graph.DirectedSparseGraph;
44
import edu.uci.ics.jung.graph.Graph;
5-
import edu.uci.ics.jung.graph.UndirectedSparseGraph;
65

76
import java.util.*;
87

Gvisual/src/gvisual/EulerianPathAnalyzer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package gvisual;
22

33
import edu.uci.ics.jung.graph.Graph;
4-
import edu.uci.ics.jung.graph.UndirectedGraph;
54

65
import java.util.*;
76

Gvisual/src/gvisual/FeedbackVertexSetAnalyzer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package gvisual;
22

33
import edu.uci.ics.jung.graph.Graph;
4-
import edu.uci.ics.jung.graph.UndirectedSparseGraph;
54
import edu.uci.ics.jung.graph.DirectedSparseGraph;
65

76
import java.util.*;

Gvisual/src/gvisual/ForceDirectedLayout.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ public double computeStress() {
506506
Map<String, Map<String, Integer>> shortestPaths =
507507
new HashMap<String, Map<String, Integer>>();
508508
for (String v : vertexList) {
509-
shortestPaths.put(v, bfsDistances(v));
509+
shortestPaths.put(v, GraphUtils.bfsDistances(graph, v));
510510
}
511511

512512
double stress = 0;
@@ -762,14 +762,4 @@ private boolean onSegment(double[] p, double[] q, double[] r) {
762762
r[1] <= Math.max(p[1], q[1]) && r[1] >= Math.min(p[1], q[1]);
763763
}
764764

765-
private Map<String, Integer> bfsDistances(String start) {
766-
return GraphUtils.bfsDistances(graph, start);
767-
}
768-
769-
private String escapeXml(String s) {
770-
return s.replace("&", "&amp;")
771-
.replace("<", "&lt;")
772-
.replace(">", "&gt;")
773-
.replace("\"", "&quot;");
774-
}
775765
}

Gvisual/src/gvisual/GraphAnnotationManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import edu.uci.ics.jung.graph.Graph;
44
import java.io.*;
55
import java.util.*;
6-
import java.util.stream.Collectors;
76

87
/**
98
* Manages annotations (notes, tags, colors) on graph nodes and edges

Gvisual/src/gvisual/GraphCompressor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import edu.uci.ics.jung.graph.UndirectedSparseGraph;
55

66
import java.util.*;
7-
import java.util.stream.Collectors;
87

98
/**
109
* Compresses a graph by merging groups of nodes into supernodes,

Gvisual/src/gvisual/GraphDistanceDistribution.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import edu.uci.ics.jung.graph.Graph;
44
import java.util.*;
5-
import java.util.stream.Collectors;
65

76
/**
87
* Analyses the all-pairs shortest-path distance distribution of a graph,

Gvisual/src/gvisual/GraphMinorAnalyzer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import edu.uci.ics.jung.graph.Graph;
44
import edu.uci.ics.jung.graph.UndirectedSparseGraph;
55
import java.util.*;
6-
import java.util.stream.Collectors;
76

87
/**
98
* Graph Minor Analyzer — operations and analysis based on graph minor theory.

Gvisual/src/gvisual/GraphNetworkProfiler.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ private void computeDiameter(int n) {
241241
Collections.shuffle(vertices, random);
242242
int maxDist = 0;
243243
for (int i = 0; i < samples; i++) {
244-
Map<String, Integer> dist = bfs(vertices.get(i));
244+
Map<String, Integer> dist = GraphUtils.bfsDistances(graph, vertices.get(i));
245245
for (int d : dist.values()) {
246246
if (d > maxDist) maxDist = d;
247247
}
@@ -276,7 +276,7 @@ private void computeComponents(int n) {
276276
int largestSize = 0;
277277
for (String v : graph.getVertices()) {
278278
if (!visited.contains(v)) {
279-
Map<String, Integer> dist = bfs(v);
279+
Map<String, Integer> dist = GraphUtils.bfsDistances(graph, v);
280280
visited.addAll(dist.keySet());
281281
count++;
282282
if (dist.size() > largestSize) largestSize = dist.size();
@@ -293,7 +293,7 @@ private void computeAvgPathLength(int n) {
293293
long totalDist = 0;
294294
long pairCount = 0;
295295
for (int i = 0; i < samples; i++) {
296-
Map<String, Integer> dist = bfs(vertices.get(i));
296+
Map<String, Integer> dist = GraphUtils.bfsDistances(graph, vertices.get(i));
297297
for (int d : dist.values()) {
298298
if (d > 0) { totalDist += d; pairCount++; }
299299
}
@@ -571,25 +571,6 @@ private void setEmptyDefaults() {
571571
overallScore = 0;
572572
}
573573

574-
// ── BFS helper ──────────────────────────────────────────────
575-
576-
private Map<String, Integer> bfs(String source) {
577-
Map<String, Integer> dist = new HashMap<>();
578-
Queue<String> queue = new LinkedList<>();
579-
dist.put(source, 0);
580-
queue.add(source);
581-
while (!queue.isEmpty()) {
582-
String v = queue.poll();
583-
int d = dist.get(v);
584-
for (String neighbor : graph.getNeighbors(v)) {
585-
if (!dist.containsKey(neighbor)) {
586-
dist.put(neighbor, d + 1);
587-
queue.add(neighbor);
588-
}
589-
}
590-
}
591-
return dist;
592-
}
593574

594575
// ── Public getters ──────────────────────────────────────────
595576

Gvisual/src/gvisual/GraphResilienceAnalyzer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package gvisual;
22

33
import edu.uci.ics.jung.graph.Graph;
4-
import edu.uci.ics.jung.graph.UndirectedSparseGraph;
54
import java.util.*;
65

76
/**

0 commit comments

Comments
 (0)