From 0d5b44d6223ce3c88d143a07c3b9063ab7b68b38 Mon Sep 17 00:00:00 2001 From: Saurav Bhattacharya Date: Tue, 24 Mar 2026 11:49:25 -0700 Subject: [PATCH] fix: ensure edge-only vertices are tracked in ParseResult.getVertices() When vertices appear only in edge lines (not in the 'nodes' section), they were added to the JUNG graph by addEdge() but missing from ParseResult.getVertices(). This caused inconsistencies where graph.getVertexCount() != result.getVertices().size(), breaking downstream code that relies on the vertex set for iteration, metrics, or export. Now edge endpoints are explicitly added to both the vertex set and the graph before edge insertion, ensuring consistency regardless of whether vertices are declared in the nodes section. --- Gvisual/src/gvisual/GraphFileParser.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Gvisual/src/gvisual/GraphFileParser.java b/Gvisual/src/gvisual/GraphFileParser.java index 3c43608..f8e06eb 100644 --- a/Gvisual/src/gvisual/GraphFileParser.java +++ b/Gvisual/src/gvisual/GraphFileParser.java @@ -164,6 +164,11 @@ public static ParseResult parse(String filePath, Predicate visibleFilter typeList.add(curEdge); } + // Ensure edge endpoints are tracked in the vertex set + // (they may not appear in the "nodes" section) + if (vertices.add(parts[1])) g.addVertex(parts[1]); + if (vertices.add(parts[2])) g.addVertex(parts[2]); + // Only add to graph if this type is visible if (visibleFilter.test(parts[0])) { g.addEdge(curEdge, parts[1], parts[2]);