int stopTimeOffset = sourceEntry.getStopTimeOffset();
int frequencyOffset = computeFrequencyOffset(relativeTime, sourceBst,
frequency, stopTimeOffset, findDepartures);
StopTimeInstance stiSource = new StopTimeInstance(sourceBst, state,
frequencyOffset);
FrequencyBlockStopTimeEntry toEntry = destStopTimes.get(sourceIndex);
BlockStopTimeEntry stopTimeTo = toEntry.getStopTime();
StopTimeInstance stiDest = new StopTimeInstance(stopTimeTo, state,
frequencyOffset);
/**
* There's a chance the frequency-based departure+arrival pair could
* extend out the front of the frequency range, at which point we
* discard it.
*/
if (!findDepartures
&& stiDest.getDepartureTime() < serviceDate.getTime()
+ frequency.getStartTime() * 1000) {
break;
}
if (stopTimeIsBeyondRangeOfQueue(nBestQueue, stiDest, resultCount,
findDepartures, slack))
break;
Pair<StopTimeInstance> stiPair = findDepartures ? Tuples.pair(
stiSource, stiDest) : Tuples.pair(stiDest, stiSource);
/**
* We only add to the n-best queue if the arrival-departure is beyond
* the target time, as opposed to time adjusted by slack
*/
if (isStopTimeInstanceBeyondTargetTime(stiSource, targetTime,
findDepartures)) {
nBestQueue.add(stiPair);
}
while (nBestQueue.size() > resultCount)
nBestQueue.poll();
/**
* We always add to the result queue
*/
resultQueue.add(stiPair);
while (!resultQueue.isEmpty()) {
Pair<StopTimeInstance> r = resultQueue.peek();
StopTimeInstance sti = findDepartures ? r.getSecond()
: r.getFirst();
if (stopTimeIsBeyondRangeOfQueue(nBestQueue, sti, resultCount,
findDepartures, slack))
resultQueue.poll();
else