From a8f7f4ed5a6a5edf9a89eae1e031395e364ddc08 Mon Sep 17 00:00:00 2001 From: alejeune Date: Sun, 27 Mar 2022 21:37:35 +0200 Subject: [PATCH] ajout des fonctions isValid et tempsMin --- .../main/java/org/insa/graphs/model/Path.java | 43 ++++++++++++++++--- 1 file changed, 36 insertions(+), 7 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 6980fd7..3076e37 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 @@ -198,11 +198,38 @@ public class Path { * * @return true if the path is valid, false otherwise. * - * @deprecated Need to be implemented. */ public boolean isValid() { - // TODO: - return false; + Arc old = null; + // it is empty + if (this.isEmpty()) { + return true; + } + // Origin is ok + if ((this.origin != null) && (this.arcs.size() == 0)) { + return true; + } + if (this.arcs.size() == 0) { + return false; + } + // destination of the first one is the origin of the second node + if (this.arcs.get(0).getOrigin() == this.origin) { + for (Arc a : this.arcs) { + if (this.arcs.get(0) == a) { + old = this.arcs.get(0); + } + else if (old.getDestination() == a.getOrigin()) { + old = a; + } + else { + return false; + } + } + return true; + } + else { + return false; + } } /** @@ -213,7 +240,7 @@ public class Path { */ public float getLength() { float acc = 0; - for (Arc l : arcs) { + for (Arc l : this.arcs) { acc += l.getLength(); } @@ -240,11 +267,13 @@ public class Path { * * @return Minimum travel time to travel this path (in seconds). * - * @deprecated Need to be implemented. */ public double getMinimumTravelTime() { - // TODO: - return 0; + float acc = 0; + for (Arc l : this.arcs) { + acc += l.getMinimumTravelTime(); + } + return acc; } }