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

Commit 1fd90c8

Browse files
Remove dead fields and duplicate BFS in report generators
- NetworkReportGenerator: remove 5 unused private edge-type fields (friendEdges, fsEdges, classmateEdges, strangerEdges, studyGEdges) that were assigned in the constructor but never read — generate() already uses the edgesByType map directly. - NetworkReportGenerator: replace duplicate countComponents() BFS with existing GraphUtils.findComponents(graph).size(), eliminating ~20 lines of duplicated traversal logic. - GraphSummarizer: remove 5 unused private edge-type fields that were only needed to construct GraphStats — use local variables instead.
1 parent 9d54235 commit 1fd90c8

2 files changed

Lines changed: 8 additions & 48 deletions

File tree

Gvisual/src/gvisual/GraphSummarizer.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ public class GraphSummarizer {
2828
private final Graph<String, Edge> graph;
2929
private final GraphStats stats;
3030
private final CommunityDetector communities;
31-
private final List<Edge> friendEdges;
32-
private final List<Edge> fsEdges;
33-
private final List<Edge> classmateEdges;
34-
private final List<Edge> strangerEdges;
35-
private final List<Edge> studyGEdges;
3631

3732
/**
3833
* Creates a new GraphSummarizer.
@@ -55,13 +50,12 @@ public GraphSummarizer(Graph<String, Edge> graph,
5550
throw new IllegalArgumentException("Graph must not be null");
5651
}
5752
this.graph = graph;
58-
this.friendEdges = friendEdges != null ? friendEdges : new ArrayList<Edge>();
59-
this.fsEdges = fsEdges != null ? fsEdges : new ArrayList<Edge>();
60-
this.classmateEdges = classmateEdges != null ? classmateEdges : new ArrayList<Edge>();
61-
this.strangerEdges = strangerEdges != null ? strangerEdges : new ArrayList<Edge>();
62-
this.studyGEdges = studyGEdges != null ? studyGEdges : new ArrayList<Edge>();
63-
this.stats = new GraphStats(graph, this.friendEdges, this.fsEdges,
64-
this.classmateEdges, this.strangerEdges, this.studyGEdges);
53+
List<Edge> fe = friendEdges != null ? friendEdges : new ArrayList<Edge>();
54+
List<Edge> fse = fsEdges != null ? fsEdges : new ArrayList<Edge>();
55+
List<Edge> ce = classmateEdges != null ? classmateEdges : new ArrayList<Edge>();
56+
List<Edge> se = strangerEdges != null ? strangerEdges : new ArrayList<Edge>();
57+
List<Edge> sge = studyGEdges != null ? studyGEdges : new ArrayList<Edge>();
58+
this.stats = new GraphStats(graph, fe, fse, ce, se, sge);
6559
this.communities = new CommunityDetector(graph);
6660
}
6761

Gvisual/src/gvisual/NetworkReportGenerator.java

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@
3434
public class NetworkReportGenerator {
3535

3636
private final Graph<String, Edge> graph;
37-
private final List<Edge> friendEdges;
38-
private final List<Edge> fsEdges;
39-
private final List<Edge> classmateEdges;
40-
private final List<Edge> strangerEdges;
41-
private final List<Edge> studyGEdges;
4237
private final Map<String, List<Edge>> edgesByType;
4338
private String title = "Network Analysis Report";
4439

@@ -60,12 +55,6 @@ public NetworkReportGenerator(Graph<String, Edge> graph,
6055
this.edgesByType.put(e.getKey(), e.getValue() != null ? e.getValue() : Collections.<Edge>emptyList());
6156
}
6257
}
63-
// Maintain backward-compatible field access for subclasses/tests
64-
this.friendEdges = this.edgesByType.containsKey("f") ? this.edgesByType.get("f") : Collections.<Edge>emptyList();
65-
this.fsEdges = this.edgesByType.containsKey("fs") ? this.edgesByType.get("fs") : Collections.<Edge>emptyList();
66-
this.classmateEdges = this.edgesByType.containsKey("c") ? this.edgesByType.get("c") : Collections.<Edge>emptyList();
67-
this.strangerEdges = this.edgesByType.containsKey("s") ? this.edgesByType.get("s") : Collections.<Edge>emptyList();
68-
this.studyGEdges = this.edgesByType.containsKey("sg") ? this.edgesByType.get("sg") : Collections.<Edge>emptyList();
6958
}
7059

7160
/**
@@ -162,8 +151,8 @@ public int compare(Map.Entry<String, Integer> a, Map.Entry<String, Integer> b) {
162151
int totalEdgeTypes = 0;
163152
for (int c : edgeTypeCounts) totalEdgeTypes += c;
164153

165-
// Components (simple BFS)
166-
int componentCount = countComponents();
154+
// Components
155+
int componentCount = GraphUtils.findComponents(graph).size();
167156

168157
// Network health score (0-100)
169158
int healthScore = computeHealthScore(nodeCount, edgeCount, density, isolatedCount, componentCount);
@@ -256,29 +245,6 @@ public int compare(Map.Entry<String, Integer> a, Map.Entry<String, Integer> b) {
256245
return sb.toString();
257246
}
258247

259-
private int countComponents() {
260-
Set<String> visited = new HashSet<String>();
261-
int components = 0;
262-
for (String v : graph.getVertices()) {
263-
if (!visited.contains(v)) {
264-
components++;
265-
Queue<String> queue = new ArrayDeque<String>();
266-
queue.add(v);
267-
visited.add(v);
268-
while (!queue.isEmpty()) {
269-
String curr = queue.poll();
270-
for (String neighbor : graph.getNeighbors(curr)) {
271-
if (!visited.contains(neighbor)) {
272-
visited.add(neighbor);
273-
queue.add(neighbor);
274-
}
275-
}
276-
}
277-
}
278-
}
279-
return components;
280-
}
281-
282248
private int computeHealthScore(int nodes, int edges, double density, int isolated, int components) {
283249
int score = 100;
284250
// Penalize for too many isolated nodes

0 commit comments

Comments
 (0)