CommitGraphBuilder { static UndirectedGraph<String, String> buildAddingRoot(final Set<String> files) { UndirectedGraph<String, String> graph = new UndirectedSparseGraph<>(); String root = "root"; graph.addVertex(root); for (String file : files) { String[] pathToFile = file.split(PATH_SEPARATOR); StringBuilder parent = new StringBuilder(root); for (String child : pathToFile) { String childPath = parent.toString() + PATH_SEPARATOR + child; 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 testBuildGraphAddingRoot() { UndirectedGraph<String, String> graph = CommitGraphBuilder.buildAddingRoot(files); Assert.assertEquals(15, graph.getVertexCount()); }