From fd19e8985fdc4bea2fefc793a9882db8ec62dbcb Mon Sep 17 00:00:00 2001 From: dcisse2 Date: Tue, 21 Oct 2025 00:59:16 +0200 Subject: [PATCH] [Amelioration] --- src/main/java/m1graphs2025/Edge.java | 51 ++- src/main/java/m1graphs2025/Graph.java | 568 +++++++++++++++++++++----- src/main/java/m1graphs2025/Node.java | 9 + 3 files changed, 527 insertions(+), 101 deletions(-) diff --git a/src/main/java/m1graphs2025/Edge.java b/src/main/java/m1graphs2025/Edge.java index 9b601bf..9bb4742 100644 --- a/src/main/java/m1graphs2025/Edge.java +++ b/src/main/java/m1graphs2025/Edge.java @@ -43,17 +43,46 @@ public class Edge implements Comparable { this.weight = weight; } - /** Arête non pondérée à partir d’IDs de nœuds dans un graphe donné */ + /** Arête pondérée à partir d’IDs de nœuds dans un graphe donné */ public Edge(int fromId, int toId, Graph g) { - this.from = new Node(fromId, g); - this.to = new Node(toId, g); - this.weight = null; + if (g == null) { + throw new IllegalArgumentException("Le graphe ne peut pas être null."); + } + Node from = g.getNode(fromId); + Node to = g.getNode(toId); + + if (from == null) { + from = new Node(fromId, g); + g.addNode(from); + } + if (to == null) { + to = new Node(toId, g); + g.addNode(to); + } + + this.from = from; + this.to = to; + this.weight = 0; // ou une valeur par défaut } - /** Arête pondérée à partir d’IDs de nœuds dans un graphe donné */ - public Edge(int fromId, int toId, Integer weight, Graph g) { - this.from = new Node(fromId, g); - this.to = new Node(toId, g); + public Edge(int fromId, int toId, int weight, Graph g) { + if (g == null) { + throw new IllegalArgumentException("Le graphe ne peut pas être null."); + } + Node from = g.getNode(fromId); + Node to = g.getNode(toId); + + if (from == null) { + from = new Node(fromId, g); + g.addNode(from); + } + if (to == null) { + to = new Node(toId, g); + g.addNode(to); + } + + this.from = from; + this.to = to; this.weight = weight; } @@ -167,4 +196,10 @@ public class Edge implements Comparable { public int hashCode() { return Objects.hash(from, to, weight); } + + @Override + public String toString() { + return "Edge(" + from.getId() + " -> " + to.getId() + ", w=" + weight + ")"; + } + } \ No newline at end of file diff --git a/src/main/java/m1graphs2025/Graph.java b/src/main/java/m1graphs2025/Graph.java index 69d32fb..7711640 100644 --- a/src/main/java/m1graphs2025/Graph.java +++ b/src/main/java/m1graphs2025/Graph.java @@ -32,9 +32,9 @@ public class Graph { public Graph(int... successorArray) { int taille = successorArray.length; Map> adjEdList = new HashMap<>(); - int i = 0; int id = 1; + while (i < taille) { List list = new ArrayList<>(); Node node = new Node(id, this); @@ -63,59 +63,136 @@ public class Graph { } public boolean usesNode(Node n) { + if (n == null) { + System.err.println("Erreur: tentative de vérification d’un nœud null."); + return false; + } return usesNode(n.getId()); } public boolean usesNode(int id) { + if (id <= 0) { + System.err.println("Erreur: identifiant de nœud invalide (" + id + ")."); + return false; + } return getNode(id) != null; } public boolean holdsNode(Node n) { + if (n == null) { + System.err.println("Erreur: tentative de vérification d’un nœud null."); + return false; + } return usesNode(n) && n.getGraph() == this; } public Node getNode(int id) { + if (id <= 0) { + System.err.println("Erreur: identifiant de nœud invalide (" + id + ")."); + return null; + } + if (adjEdList == null || adjEdList.isEmpty()) { + System.err.println("Avertissement: la liste d’adjacence est vide ou non initialisée."); + return null; + } for (Node entry : adjEdList.keySet()) { - if (entry.getId() == id) return entry; + if (entry != null && entry.getId() == id) return entry; } + System.err.println("Aucun nœud trouvé avec l’id " + id + "."); return null; } public boolean addNode(Node n) { + if (n == null) { + System.err.println("Erreur: tentative d’ajout d’un nœud null."); + return false; + } + if (n.getId() <= 0) { + System.err.println("Erreur: identifiant de nœud invalide (" + n.getId() + ")."); + return false; + } if (!usesNode(n)) { - adjEdList.put(n, new ArrayList<>()); - return true; + try { + adjEdList.put(n, new ArrayList<>()); + return true; + } catch (Exception e) { + System.err.println("Erreur lors de l’ajout du nœud " + n.getId() + " : " + e.getMessage()); + return false; + } + } else { + System.err.println("Le nœud " + n.getId() + " existe déjà dans le graphe."); } return false; } public boolean addNode(int id) { + if (id <= 0) { + System.err.println("Erreur: identifiant de nœud invalide (" + id + ")."); + return false; + } if (!usesNode(id)) { - Node node = new Node(id, this); - adjEdList.put(node, new ArrayList<>()); - return true; + try { + Node node = new Node(id, this); + adjEdList.put(node, new ArrayList<>()); + return true; + } catch (Exception e) { + System.err.println("Erreur lors de la création du nœud " + id + " : " + e.getMessage()); + return false; + } + } else { + System.err.println("Le nœud " + id + " existe déjà dans le graphe."); } return false; } public boolean removeNode(Node n) { - if (!usesNode(n)) return false; - // Supprimer les arêtes entrantes - for (List edges : adjEdList.values()) { - edges.removeIf(e -> e.getNodeTo().equals(n)); + if (n == null) { + System.err.println("Erreur: tentative de suppression d’un nœud null."); + return false; + } + if (!usesNode(n)) { + System.err.println("Nœud " + n.getId() + " introuvable dans le graphe."); + return false; + } + + try { + // Supprimer les arêtes entrantes + for (List edges : adjEdList.values()) { + edges.removeIf(e -> e != null && e.getNodeTo().equals(n)); + } + + // Supprimer le nœud et ses arêtes sortantes + adjEdList.remove(n); + return true; + } catch (Exception e) { + System.err.println("Erreur lors de la suppression du nœud " + n.getId() + " : " + e.getMessage()); + return false; } - // Supprimer le nœud et ses arêtes sortantes - adjEdList.remove(n); - return true; } + public boolean removeNode() { return removeNode(0); } public boolean removeNode(int id) { + if (id <= 0) { + System.err.println("Erreur: identifiant de nœud invalide (" + id + ")."); + return false; + } + Node n = getNode(id); - return n != null && removeNode(n); + if (n == null) { + System.err.println("Erreur: aucun nœud trouvé avec l’identifiant " + id + "."); + return false; + } + + try { + return removeNode(n); + } catch (Exception e) { + System.err.println("Erreur lors de la suppression du nœud " + id + " : " + e.getMessage()); + return false; + } } public List getAllNodes() { @@ -123,61 +200,168 @@ public class Graph { } public int largestNodeId() { - return adjEdList.keySet().stream().mapToInt(Node::getId).max().orElse(Integer.MIN_VALUE); + if (adjEdList == null || adjEdList.isEmpty()) { + System.err.println("Avertissement: le graphe est vide."); + return Integer.MIN_VALUE; + } + + int maxId = Integer.MIN_VALUE; + for (Node n : adjEdList.keySet()) { + if (n.getId() > maxId) { + maxId = n.getId(); + } + } + return maxId; } public int smallestNodeId() { - return adjEdList.keySet().stream().mapToInt(Node::getId).min().orElse(Integer.MAX_VALUE); - } + if (adjEdList == null || adjEdList.isEmpty()) { + System.err.println("Avertissement: le graphe est vide."); + return Integer.MAX_VALUE; + } + int minId = Integer.MAX_VALUE; + for (Node n : adjEdList.keySet()) { + if (n.getId() < minId) { + minId = n.getId(); + } + } + return minId; + } public List getSuccessors(Node n) { - return n.getSuccessors(); + if (n == null) { + System.err.println("Erreur: nœud nul dans getSuccessors()."); + return List.of(); + } + try { + return n.getSuccessors(); + } catch (Exception e) { + System.err.println("Erreur lors de la récupération des successeurs du nœud " + n.getId() + ": " + e.getMessage()); + return List.of(); + } } public List getSuccessors(int id) { Node u = getNode(id); - return u == null ? List.of() : u.getSuccessors(); + if (u == null) { + System.err.println("Erreur: aucun nœud trouvé avec l'identifiant " + id + " dans getSuccessors()."); + return List.of(); + } + return getSuccessors(u); } public List getSuccessorsMulti(Node n) { - return n.getSuccessorsMulti(); + if (n == null) { + System.err.println("Erreur: nœud nul dans getSuccessorsMulti()."); + return List.of(); + } + try { + return n.getSuccessorsMulti(); + } catch (Exception e) { + System.err.println("Erreur lors de la récupération des successeurs multiples du nœud " + n.getId() + ": " + e.getMessage()); + return List.of(); + } } public List getSuccessorsMulti(int id) { Node u = getNode(id); - return u == null ? List.of() : u.getSuccessorsMulti(); + if (u == null) { + System.err.println("Erreur: aucun nœud trouvé avec l'identifiant " + id + " dans getSuccessorsMulti()."); + return List.of(); + } + return getSuccessorsMulti(u); } public boolean adjacent(Node u, Node v) { - return u.adjacent(v); + if (u == null || v == null) { + System.err.println("Erreur: un des nœuds est nul dans adjacent()."); + return false; + } + try { + return u.adjacent(v); + } catch (Exception e) { + System.err.println("Erreur lors de la vérification de l’adjacence entre " + u.getId() + " et " + v.getId() + ": " + e.getMessage()); + return false; + } } public boolean adjacent(int uId, int vId) { Node u = getNode(uId); Node v = getNode(vId); - return u != null && u.adjacent(v); + if (u == null || v == null) { + System.err.println("Erreur: un des identifiants (" + uId + ", " + vId + ") est invalide dans adjacent()."); + return false; + } + return adjacent(u, v); + } + + public int inDegree(Node n) { + if (n == null) { + System.err.println("Erreur: nœud nul dans inDegree()."); + return 0; + } + try { + return n.inDegree(); + } catch (Exception e) { + System.err.println("Erreur lors du calcul du degré entrant du nœud " + n.getId() + ": " + e.getMessage()); + return 0; + } } - public int inDegree(Node n) { return n.inDegree(); } public int inDegree(int id) { Node n = getNode(id); - return n == null ? 0 : n.inDegree(); + if (n == null) { + System.err.println("Erreur: aucun nœud trouvé avec l'identifiant " + id + " dans inDegree()."); + return 0; + } + return inDegree(n); + } + + public int outDegree(Node n) { + if (n == null) { + System.err.println("Erreur: nœud nul dans outDegree()."); + return 0; + } + try { + return n.outDegree(); + } catch (Exception e) { + System.err.println("Erreur lors du calcul du degré sortant du nœud " + n.getId() + ": " + e.getMessage()); + return 0; + } } - public int outDegree(Node n) { return n.outDegree(); } public int outDegree(int id) { Node n = getNode(id); - return n == null ? 0 : n.outDegree(); + if (n == null) { + System.err.println("Erreur: aucun nœud trouvé avec l'identifiant " + id + " dans outDegree()."); + return 0; + } + return outDegree(n); + } + + public int degree(Node n) { + if (n == null) { + System.err.println("Erreur: nœud nul dans degree()."); + return 0; + } + try { + return n.degree(); + } catch (Exception e) { + System.err.println("Erreur lors du calcul du degré du nœud " + n.getId() + ": " + e.getMessage()); + return 0; + } } - public int degree(Node n) { return n.degree(); } public int degree(int id) { Node n = getNode(id); - return n == null ? 0 : n.degree(); + if (n == null) { + System.err.println("Erreur: aucun nœud trouvé avec l'identifiant " + id + " dans degree()."); + return 0; + } + return degree(n); } - // ====================== // API DES ARÊTES // ====================== @@ -189,135 +373,333 @@ public class Graph { } public boolean existsEdge(Node u, Node v) { - for (Edge e : adjEdList.getOrDefault(u, Collections.emptyList())) { - if (e.getNodeTo().equals(v)) return true; + try { + if (u == null || v == null) { + throw new IllegalArgumentException("Les nœuds ne peuvent pas être null."); + } + for (Edge e : adjEdList.getOrDefault(u, Collections.emptyList())) { + if (e.getNodeTo().equals(v)) return true; + } + return false; + } catch (Exception ex) { + System.err.println("Erreur dans existsEdge(Node, Node) : " + ex.getMessage()); + return false; } - return false; } public boolean existsEdge(int uId, int vId) { - Node u = getNode(uId); - Node v = getNode(vId); - return u != null && v != null && existsEdge(u, v); + try { + if (uId < 0 || vId < 0) { + throw new IllegalArgumentException("Les identifiants de nœuds doivent être positifs."); + } + Node u = getNode(uId); + Node v = getNode(vId); + if (u == null || v == null) { + throw new IllegalArgumentException("Un ou plusieurs nœuds n'existent pas."); + } + return existsEdge(u, v); + } catch (Exception ex) { + System.err.println("Erreur dans existsEdge(int, int) : " + ex.getMessage()); + return false; + } } public boolean existsEdge(Edge e) { - return !adjEdList.getOrDefault(e.getNodeFrom(), Collections.emptyList()).contains(e); + try { + if (e == null) { + throw new IllegalArgumentException("L'arête ne peut pas être null."); + } + return adjEdList.getOrDefault(e.getNodeFrom(), Collections.emptyList()).contains(e); + } catch (Exception ex) { + System.err.println("Erreur dans existsEdge(Edge) : " + ex.getMessage()); + return false; + } } public boolean isMultiEdge(Node u, Node v) { - Edge e = new Edge(u, v); - return e.isMultiEdge(); + try { + if (u == null || v == null) { + throw new IllegalArgumentException("Les nœuds ne peuvent pas être null."); + } + Edge e = new Edge(u, v); + return e.isMultiEdge(); + } catch (Exception ex) { + System.err.println("Erreur dans isMultiEdge(Node, Node) : " + ex.getMessage()); + return false; + } } public boolean isMultiEdge(int uId, int vId) { - Node u = getNode(uId); - Node v = getNode(vId); - return u != null && v != null && isMultiEdge(u, v); + try { + if (uId < 0 || vId < 0) { + throw new IllegalArgumentException("Les identifiants de nœuds doivent être positifs."); + } + Node u = getNode(uId); + Node v = getNode(vId); + if (u == null || v == null) { + throw new IllegalArgumentException("Un ou plusieurs nœuds n'existent pas."); + } + return isMultiEdge(u, v); + } catch (Exception ex) { + System.err.println("Erreur dans isMultiEdge(int, int) : " + ex.getMessage()); + return false; + } } public void addEdge(Node from, Node to) { - if (!usesNode(from)) addNode(from); - if (!usesNode(to)) addNode(to); - adjEdList.get(from).add(new Edge(from, to)); + try { + if (from == null || to == null) { + throw new IllegalArgumentException("Les nœuds source et destination ne peuvent pas être null."); + } + if (!usesNode(from)) addNode(from); + if (!usesNode(to)) addNode(to); + adjEdList.get(from).add(new Edge(from, to)); + } catch (Exception ex) { + System.err.println("Erreur dans addEdge(Node, Node) : " + ex.getMessage()); + } } public void addEdge(int fromId, int toId) { - Node from = getNode(fromId); - Node to = getNode(toId); - if (from == null) from = new Node(fromId, this); - if (to == null) to = new Node(toId, this); - addEdge(from, to); + try { + if (fromId < 0 || toId < 0) { + throw new IllegalArgumentException("Les identifiants de nœuds doivent être positifs."); + } + Node from = getNode(fromId); + Node to = getNode(toId); + if (from == null) from = new Node(fromId, this); + if (to == null) to = new Node(toId, this); + addEdge(from, to); + } catch (Exception ex) { + System.err.println("Erreur dans addEdge(int, int) : " + ex.getMessage()); + } } public void addEdge(Edge e) { - if (existsEdge(e)) { - adjEdList.get(e.getNodeFrom()).add(e); + try { + if (e == null) { + throw new IllegalArgumentException("L'arête ne peut pas être null."); + } + if (!existsEdge(e)) { + adjEdList.get(e.getNodeFrom()).add(e); + } else { + throw new IllegalArgumentException("L'arête existe déjà."); + } + } catch (Exception ex) { + System.err.println("Erreur dans addEdge(Edge) : " + ex.getMessage()); } } public void addEdge(Node from, Node to, int weight) { - if (!usesNode(from)) addNode(from); - if (!usesNode(to)) addNode(to); - adjEdList.get(from).add(new Edge(from, to, weight)); + try { + if (from == null || to == null) { + throw new IllegalArgumentException("Les nœuds source et destination ne peuvent pas être null."); + } + if (weight < 0) { + throw new IllegalArgumentException("Le poids doit être positif ou nul."); + } + if (!usesNode(from)) addNode(from); + if (!usesNode(to)) addNode(to); + adjEdList.get(from).add(new Edge(from, to, weight)); + } catch (Exception ex) { + System.err.println("Erreur dans addEdge(Node, Node, int) : " + ex.getMessage()); + } } public void addEdge(int fromId, int toId, int weight) { - Node from = getNode(fromId); - Node to = getNode(toId); - if (from == null) from = new Node(fromId, this); - if (to == null) to = new Node(toId, this); - addEdge(from, to, weight); + try { + if (fromId < 0 || toId < 0) { + throw new IllegalArgumentException("Les identifiants de nœuds doivent être positifs."); + } + if (weight < 0) { + throw new IllegalArgumentException("Le poids doit être positif ou nul."); + } + Node from = getNode(fromId); + Node to = getNode(toId); + if (from == null) from = new Node(fromId, this); + if (to == null) to = new Node(toId, this); + addEdge(from, to, weight); + } catch (Exception ex) { + System.err.println("Erreur dans addEdge(int, int, int) : " + ex.getMessage()); + } } public void addEdge(int fromId, int toId, Graph g) { - Node from = getNode(fromId); - Node to = getNode(toId); - if (from == null) from = new Node(fromId, g); - if (to == null) to = new Node(toId, g); - addEdge(from, to); + try { + if (g == null) { + throw new IllegalArgumentException("Le graphe ne peut pas être null."); + } + if (fromId < 0 || toId < 0) { + throw new IllegalArgumentException("Les identifiants de nœuds doivent être positifs."); + } + Node from = getNode(fromId); + Node to = getNode(toId); + if (from == null) from = new Node(fromId, g); + if (to == null) to = new Node(toId, g); + addEdge(from, to); + } catch (Exception ex) { + System.err.println("Erreur dans addEdge(int, int, Graph) : " + ex.getMessage()); + } } public boolean removeEdge(Node from, Node to) { - return adjEdList.getOrDefault(from, Collections.emptyList()) - .removeIf(e -> e.getNodeTo().equals(to)); + try { + if (from == null || to == null) { + throw new IllegalArgumentException("Les nœuds source et destination ne peuvent pas être null."); + } + return adjEdList.getOrDefault(from, Collections.emptyList()) + .removeIf(e -> e.getNodeTo().equals(to)); + } catch (Exception ex) { + System.err.println("Erreur dans removeEdge(Node, Node) : " + ex.getMessage()); + return false; + } } public boolean removeEdge(int fromId, int toId) { - Node from = getNode(fromId); - Node to = getNode(toId); - return from != null && to != null && removeEdge(from, to); + try { + if (fromId < 0 || toId < 0) { + throw new IllegalArgumentException("Les identifiants de nœuds doivent être positifs."); + } + Node from = getNode(fromId); + Node to = getNode(toId); + if (from == null || to == null) { + throw new IllegalArgumentException("Un ou plusieurs nœuds n'existent pas."); + } + return removeEdge(from, to); + } catch (Exception ex) { + System.err.println("Erreur dans removeEdge(int, int) : " + ex.getMessage()); + return false; + } } public boolean removeEdge(Edge e) { - return adjEdList.getOrDefault(e.getNodeFrom(), Collections.emptyList()).remove(e); + try { + if (e == null) { + throw new IllegalArgumentException("L'arête ne peut pas être null."); + } + return adjEdList.getOrDefault(e.getNodeFrom(), Collections.emptyList()).remove(e); + } catch (Exception ex) { + System.err.println("Erreur dans removeEdge(Edge) : " + ex.getMessage()); + return false; + } } public List getOutEdges(Node n) { - return new ArrayList<>(adjEdList.getOrDefault(n, Collections.emptyList())); + try { + if (n == null) { + throw new IllegalArgumentException("Le nœud ne peut pas être null."); + } + return new ArrayList<>(adjEdList.getOrDefault(n, Collections.emptyList())); + } catch (Exception ex) { + System.err.println("Erreur dans getOutEdges(Node) : " + ex.getMessage()); + return Collections.emptyList(); + } } public List getOutEdges(int id) { - Node n = getNode(id); - return n == null ? new ArrayList<>() : getOutEdges(n); + try { + if (id < 0) { + throw new IllegalArgumentException("L'identifiant du nœud doit être positif."); + } + Node n = getNode(id); + if (n == null) { + throw new IllegalArgumentException("Le nœud avec l'identifiant " + id + " n'existe pas."); + } + return getOutEdges(n); + } catch (Exception ex) { + System.err.println("Erreur dans getOutEdges(int) : " + ex.getMessage()); + return Collections.emptyList(); + } } public List getInEdges(Node n) { - List result = new ArrayList<>(); - for (List edges : adjEdList.values()) { - for (Edge e : edges) if (e.getNodeTo().equals(n)) result.add(e); + try { + if (n == null) { + throw new IllegalArgumentException("Le nœud ne peut pas être null."); + } + List result = new ArrayList<>(); + for (List edges : adjEdList.values()) { + for (Edge e : edges) { + if (e.getNodeTo().equals(n)) result.add(e); + } + } + return result; + } catch (Exception ex) { + System.err.println("Erreur dans getInEdges(Node) : " + ex.getMessage()); + return Collections.emptyList(); } - return result; } public List getInEdges(int id) { - Node n = getNode(id); - return n == null ? new ArrayList<>() : getInEdges(n); + try { + if (id < 0) { + throw new IllegalArgumentException("L'identifiant du nœud doit être positif."); + } + Node n = getNode(id); + if (n == null) { + throw new IllegalArgumentException("Le nœud avec l'identifiant " + id + " n'existe pas."); + } + return getInEdges(n); + } catch (Exception ex) { + System.err.println("Erreur dans getInEdges(int) : " + ex.getMessage()); + return Collections.emptyList(); + } } public List getIncidentEdges(Node n) { - List inc = getOutEdges(n); - inc.addAll(getInEdges(n)); - return inc; + try { + if (n == null) { + throw new IllegalArgumentException("Le nœud ne peut pas être null."); + } + List inc = getOutEdges(n); + inc.addAll(getInEdges(n)); + return inc; + } catch (Exception ex) { + System.err.println("Erreur dans getIncidentEdges(Node) : " + ex.getMessage()); + return Collections.emptyList(); + } } public List getIncidentEdges(int id) { - Node n = getNode(id); - return n == null ? new ArrayList<>() : getIncidentEdges(n); + try { + if (id < 0) { + throw new IllegalArgumentException("L'identifiant du nœud doit être positif."); + } + Node n = getNode(id); + if (n == null) { + throw new IllegalArgumentException("Le nœud avec l'identifiant " + id + " n'existe pas."); + } + return getIncidentEdges(n); + } catch (Exception ex) { + System.err.println("Erreur dans getIncidentEdges(int) : " + ex.getMessage()); + return Collections.emptyList(); + } } public List getEdges(Node u, Node v) { - List result = new ArrayList<>(); - for (Edge e : adjEdList.getOrDefault(u, Collections.emptyList())) { - if (e.getNodeTo().equals(v)) result.add(e); + try { + if (u == null || v == null) { + throw new IllegalArgumentException("Les nœuds source et destination ne peuvent pas être null."); + } + List result = new ArrayList<>(); + for (Edge e : adjEdList.getOrDefault(u, Collections.emptyList())) { + if (e.getNodeTo().equals(v)) result.add(e); + } + return result; + } catch (Exception ex) { + System.err.println("Erreur dans getEdges(Node, Node) : " + ex.getMessage()); + return Collections.emptyList(); } - return result; } public List getAllEdges() { - List result = new ArrayList<>(); - for (List edges : adjEdList.values()) result.addAll(edges); - return result; + try { + List result = new ArrayList<>(); + for (List edges : adjEdList.values()) result.addAll(edges); + return result; + } catch (Exception ex) { + System.err.println("Erreur dans getAllEdges() : " + ex.getMessage()); + return Collections.emptyList(); + } } // ====================== diff --git a/src/main/java/m1graphs2025/Node.java b/src/main/java/m1graphs2025/Node.java index bbed1a3..ebd69ea 100644 --- a/src/main/java/m1graphs2025/Node.java +++ b/src/main/java/m1graphs2025/Node.java @@ -351,4 +351,13 @@ public class Node implements Comparable { public int compareTo(Node node) { return Integer.compare(this.id, node.getId()); } + + @Override + public String toString() { + if (name != null && !name.isEmpty()) { + return "Node(" + id + ", \"" + name + "\")"; + } else { + return "Node(" + id + ")"; + } + } } -- GitLab