20 package org.matsim.pt.transitSchedule;
22 import java.util.Iterator;
24 import java.util.NoSuchElementException;
25 import java.util.concurrent.ConcurrentHashMap;
36 class MinimalTransferTimesImpl
implements MinimalTransferTimes {
38 private final Map<Id<TransitStopFacility>, Map<Id<TransitStopFacility>, Double>> minimalTransferTimes =
new ConcurrentHashMap<>();
41 public double set(Id<TransitStopFacility> fromStop, Id<TransitStopFacility> toStop,
double seconds) {
42 if (Double.isNaN(seconds)) {
43 return remove(fromStop, toStop);
45 Map<Id<TransitStopFacility>, Double> innerMap = this.minimalTransferTimes.computeIfAbsent(fromStop, key ->
new ConcurrentHashMap<>());
46 Double value = innerMap.put(toStop, seconds);
54 public double get(Id<TransitStopFacility> fromStop, Id<TransitStopFacility> toStop) {
55 return get(fromStop, toStop, Double.NaN);
59 public double get(Id<TransitStopFacility> fromStop, Id<TransitStopFacility> toStop,
double defaultSeconds) {
60 Map<Id<TransitStopFacility>, Double> innerMap = this.minimalTransferTimes.get(fromStop);
61 if (innerMap == null) {
62 return getInnerStopTransferTime(toStop,defaultSeconds);
64 Double value = innerMap.get(toStop);
66 return Math.max(getInnerStopTransferTime(toStop,defaultSeconds),getInnerStopTransferTime(fromStop,defaultSeconds));
71 private double getInnerStopTransferTime(Id<TransitStopFacility> stopId,
double defaultSeconds){
72 Map<Id<TransitStopFacility>, Double> innerMap = this.minimalTransferTimes.get(stopId);
73 return innerMap!=null?innerMap.getOrDefault(stopId,defaultSeconds):defaultSeconds;
78 public double remove(Id<TransitStopFacility> fromStop, Id<TransitStopFacility> toStop) {
79 Map<Id<TransitStopFacility>, Double> innerMap = this.minimalTransferTimes.get(fromStop);
80 if (innerMap == null) {
83 Double value = innerMap.remove(toStop);
92 return new MinimalTransferTimesIteratorImpl(this.minimalTransferTimes);
107 this.outerIterator = values.entrySet().iterator();
112 if (this.innerIterator != null && this.innerIterator.hasNext()) {
115 while (this.outerIterator.hasNext()) {
116 Map.Entry<
Id<TransitStopFacility>, Map<Id<TransitStopFacility>, Double>> outerEntry = this.outerIterator.next();
117 Map<Id<TransitStopFacility>, Double> innerMap = outerEntry.getValue();
118 this.innerIterator = innerMap.entrySet().iterator();
119 if (this.innerIterator.hasNext()) {
120 this.nextFromStopId = outerEntry.getKey();
125 this.nextFromStopId = null;
131 if (this.innerIterator != null && this.innerIterator.hasNext()) {
134 this.toStopId = e.getKey();
135 this.seconds = e.getValue();
136 this.hasElement =
true;
138 this.hasElement =
false;
139 throw new NoSuchElementException();
145 if (this.hasElement) {
148 throw new NoSuchElementException();
153 if (this.hasElement) {
156 throw new NoSuchElementException();
161 if (this.hasElement) {
164 throw new NoSuchElementException();
Id< TransitStopFacility > getFromStopId()
Iterator< Map.Entry< Id< TransitStopFacility >, Double > > innerIterator
Id< TransitStopFacility > nextFromStopId
final Iterator< Map.Entry< Id< TransitStopFacility >, Map< Id< TransitStopFacility >, Double > > > outerIterator
Id< TransitStopFacility > getToStopId()
Id< TransitStopFacility > fromStopId
Id< TransitStopFacility > toStopId