From b80a197a5aba55b44e9d69b478f69a774c6232b6 Mon Sep 17 00:00:00 2001 From: marecabo <23156476+marecabo@users.noreply.github.com> Date: Fri, 13 Oct 2023 09:47:58 +0200 Subject: [PATCH] Add getter and setter for disallowedNextLinks --- .../org/matsim/core/network/NetworkUtils.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/matsim/src/main/java/org/matsim/core/network/NetworkUtils.java b/matsim/src/main/java/org/matsim/core/network/NetworkUtils.java index b1b67c5d493..f2dec77cad0 100644 --- a/matsim/src/main/java/org/matsim/core/network/NetworkUtils.java +++ b/matsim/src/main/java/org/matsim/core/network/NetworkUtils.java @@ -22,6 +22,8 @@ import java.util.*; +import javax.annotation.Nullable; + import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -988,4 +990,29 @@ public static List getOriginalGeometry(Link link) { result.add(link.getToNode()); return result; } + + private static final String DISALLOWED_NEXT_LINKS_ATTRIBUTE = "disallowedNextLinks"; + + @Nullable + public static DisallowedNextLinks getDisallowedNextLinks(Link link) { + return (DisallowedNextLinks) link.getAttributes().getAttribute(DISALLOWED_NEXT_LINKS_ATTRIBUTE); + } + + public static DisallowedNextLinks getOrCreateDisallowedNextLinks(Link link) { + DisallowedNextLinks disallowedNextLinks = getDisallowedNextLinks(link); + if (disallowedNextLinks == null) { + disallowedNextLinks = new DisallowedNextLinks(); + setDisallowedNextLinks(link, disallowedNextLinks); + } + return disallowedNextLinks; + } + + public static void setDisallowedNextLinks(Link link, DisallowedNextLinks disallowedNextLinks) { + link.getAttributes().putAttribute(DISALLOWED_NEXT_LINKS_ATTRIBUTE, disallowedNextLinks); + } + + public static boolean addDisallowedNextLinks(Link link, String mode, Collection> linkIds) { + DisallowedNextLinks disallowedNextLinks = getOrCreateDisallowedNextLinks(link); + return disallowedNextLinks.addDisallowedLinkSequence(mode, linkIds); + } }