CommitGraphBuilder { static UndirectedGraph<String, String> build(final Set<String> files) { UndirectedGraph<String, String> graph = new UndirectedSparseGraph<>(); for (String file : files) { String[] pathToFile = file.split(PATH_SEPARATOR); StringBuilder parent = new StringBuilder(); for (String child : pathToFile) { String childPath; if (parent.length() > 0) { childPath = parent.toString() + PATH_SEPARATOR + child; } else { parent.append(child); continue; } if (!graph.containsVertex(childPath)) { graph.addEdge(parent.toString() + childPath, parent.toString(), childPath); } parent.append(PATH_SEPARATOR).append(child); } } return graph; }   static final String PATH_SEPARATOR; }
@Test public void testBuildGraphWithoutAddingRoot() { UndirectedGraph<String, String> graph = CommitGraphBuilder.build(files); Assert.assertEquals(14, graph.getVertexCount()); }