diff --git a/matsim/src/main/java/org/matsim/core/network/DisallowedNextLinks.java b/matsim/src/main/java/org/matsim/core/network/DisallowedNextLinks.java index 2b816d1cbbb..25c0bbd7303 100644 --- a/matsim/src/main/java/org/matsim/core/network/DisallowedNextLinks.java +++ b/matsim/src/main/java/org/matsim/core/network/DisallowedNextLinks.java @@ -37,10 +37,34 @@ public class DisallowedNextLinks { // list in favor of a smaller memory footprint. private final Map>>> linkIdSequencesMap = new HashMap<>(); + /** + * A builder to allow building a populated instance in one statement. + * Be aware that several calls to the build() method of a particular Builder instance will + * return the same DisallowedNextLinks instance! + */ + public static class Builder { + private final DisallowedNextLinks instance = new DisallowedNextLinks(); + + public Builder withDisallowedLinkSequence(String mode, List> linkSequence) { + instance.addDisallowedLinkSequence(mode, linkSequence); + return this; + } + + /** + * Be aware that several calls to the build() method of a particular Builder + * instance will return the same DisallowedNextLinks instance! + * + * @return an instance with the required disallowedNextLinks set + */ + public DisallowedNextLinks build() { + return instance; + } + } + public DisallowedNextLinks() { // ! remove constructor, if routing considers this if (!warnedAboutNotConsideredInRouting) { warnedAboutNotConsideredInRouting = true; - LOG.warn("Considering DisallowedNextLinks in routing is not yet implemented!"); + LOG.warn("Considering DisallowedNextLinks in routing is only implemented by SpeedyDijkstra and SpeedyALT!"); } } @@ -154,4 +178,9 @@ public int hashCode() { return this.linkIdSequencesMap.hashCode(); } + @Override + public String toString() { + return "DisallowedNextLinks [linkIdSequencesMap=" + linkIdSequencesMap + "]"; + } + }