From ae6bf5d339f356f31411be8797f42a3456cf7d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yanis=20Mah=C3=A9?= Date: Wed, 15 Apr 2026 18:08:25 +0200 Subject: [PATCH] Path.createShortestPathFromNodes --- .../src/main/java/org/insa/graphs/model/Path.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/Path.java b/be-graphes-model/src/main/java/org/insa/graphs/model/Path.java index 63a20f6..d6a570e 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/Path.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/Path.java @@ -2,6 +2,7 @@ package org.insa.graphs.model; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.List; /** @@ -43,12 +44,20 @@ public class Path { * @return A path that goes through the given list of nodes. * @throws IllegalArgumentException If the list of nodes is not valid, i.e. two * consecutive nodes in the list are not connected in the graph. - * @deprecated Need to be implemented. */ public static Path createShortestPathFromNodes(Graph graph, List nodes) throws IllegalArgumentException { + if (nodes.size() == 0) { + return new Path(graph); + } + if (nodes.size() == 1) { + return new Path(graph, nodes.getFirst()); + } List arcs = new ArrayList(); - // TODO: + for (int i=0; i a.getDestination().equals(nodes.get(j+1))).min(Comparator.comparing(Arc::getLength)).orElseThrow(() -> new IllegalArgumentException("Invalid list of nodes"))); + } return new Path(graph, arcs); }