Skip to content

Commit

Permalink
Implement second feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
theViz343 committed Oct 8, 2023
1 parent 41c210e commit 64a24a0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/GraphData.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,31 @@ public void outputGraph(String filepath) throws IOException {
String opt = toString();
Files.writeString(Paths.get(filepath), opt, StandardCharsets.ISO_8859_1);
}

public void addNode(String label) {
boolean existing = graphObject.vertexSet().stream().anyMatch(v -> Objects.equals(v, label));

if (existing) {
System.out.println("Node with label "+label+" already exists!");
}
else {
graphObject.addVertex(label);
}
}

public void addNodes(String[] labels) {
for(String label: labels) {
addNode(label);
}
}
public static void main(String[] args) throws IOException {
GraphData graphApi = new GraphData();
graphApi.parseGraph("src/main/example.dot");
System.out.println(graphApi.toString());
graphApi.outputGraph("src/main/output.txt");
graphApi.addNodes(new String[]{"Z", "X"});
System.out.println(graphApi.toString());




Expand Down

0 comments on commit 64a24a0

Please sign in to comment.