Skip to content

Commit

Permalink
Refactor GraphCanvas internals
Browse files Browse the repository at this point in the history
  • Loading branch information
FeldrinH committed Oct 23, 2023
1 parent c8ef58e commit 139676c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/java/ee/ut/dendroloj/GraphCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ public final class GraphCanvas<T> {
final List<Edge<T>> edges = new ArrayList<>();

public void drawVertex(T vertex) {
drawVertex(vertex, vertex.toString(), null);
if (vertex == null) throw new NullPointerException("Vertex must not be null");
vertices.add(new Vertex<>(vertex, vertex.toString(), null));
}

public void drawVertex(T vertex, String label) {
drawVertex(vertex, label, null);
if (vertex == null) throw new NullPointerException("Vertex must not be null");
vertices.add(new Vertex<>(vertex, label, null));
}

public void drawVertex(T vertex, String label, Color color) {
Expand All @@ -31,11 +33,13 @@ public void drawVertex(T vertex, String label, Color color) {
}

public void drawEdge(T from, T to) {
drawEdge(from, to, null, null);
if (from == null || to == null) throw new NullPointerException("Target vertices must not be null");
edges.add(new Edge<>(from, to, null, null));
}

public void drawEdge(T from, T to, String label) {
drawEdge(from, to, label, null);
if (from == null || to == null) throw new NullPointerException("Target vertices must not be null");
edges.add(new Edge<>(from, to, label, null));
}

public void drawEdge(T from, T to, String label, Color color) {
Expand Down

0 comments on commit 139676c

Please sign in to comment.