Skip to content

Commit

Permalink
Implement third feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
theViz343 committed Oct 8, 2023
1 parent 64a24a0 commit 86547b1
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/GraphData.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,36 @@ public void addNodes(String[] labels) {
addNode(label);
}
}

public void addEdge(String srcLabel, String dstLabel) {
boolean srcnodeexisting = graphObject.vertexSet().stream().anyMatch(v -> Objects.equals(v, srcLabel));
boolean dstnodeexisting = graphObject.vertexSet().stream().anyMatch(v -> Objects.equals(v, dstLabel));
DefaultEdge edgeexisting = graphObject.getEdge(srcLabel, dstLabel);
if (edgeexisting!=null) {
System.out.println("Edge "+ edgeexisting + " already exists!");
return;
}
if (!srcnodeexisting) {
System.out.println("Node "+ srcLabel+" does not exist!");
} else if (!dstnodeexisting) {
System.out.println("Node "+ dstLabel+" does not exist!");
} else {
graphObject.addEdge(srcLabel, dstLabel);
}
}
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());
graphApi.addEdge("Z", "X");
System.out.println(graphApi.toString());
graphApi.addEdge("Z", "X");
System.out.println(graphApi.toString());





Expand Down

0 comments on commit 86547b1

Please sign in to comment.