ArrivalAndDepartureServiceImpl implements ArrivalAndDepartureService { @Override public List<ArrivalAndDepartureInstance> getArrivalsAndDeparturesForStopInTimeRange( StopEntry stop, TargetTime targetTime, long fromTime, long toTime) { Date fromTimeBuffered = new Date( fromTime - _blockStatusService.getRunningLateWindow() * 1000); Date toTimeBuffered = new Date( toTime + _blockStatusService.getRunningEarlyWindow() * 1000); List<StopTimeInstance> stis = _stopTimeService.getStopTimeInstancesInTimeRange( stop, fromTimeBuffered, toTimeBuffered, EFrequencyStopTimeBehavior.INCLUDE_UNSPECIFIED); long frequencyOffsetTime = Math.max(targetTime.getTargetTime(), fromTime); Map<BlockInstance, List<StopTimeInstance>> stisByBlockId = getStopTimeInstancesByBlockInstance( stis); List<ArrivalAndDepartureInstance> instances = new ArrayList<ArrivalAndDepartureInstance>(); for (Map.Entry<BlockInstance, List<StopTimeInstance>> entry : stisByBlockId.entrySet()) { BlockInstance blockInstance = entry.getKey(); List<BlockLocation> locations = _blockLocationService.getLocationsForBlockInstance( blockInstance, targetTime); List<StopTimeInstance> stisForBlock = entry.getValue(); for (StopTimeInstance sti : stisForBlock) { applyRealTimeToStopTimeInstance(sti, targetTime, fromTime, toTime, frequencyOffsetTime, blockInstance, locations, instances); if (sti.getFrequency() != null && sti.getFrequency().getExactTimes() == 0) { applyPostInterpolateForFrequencyNoSchedule(sti, fromTime, toTime, frequencyOffsetTime, blockInstance, instances); } } } if (removeFuturePredictionsWithoutRealtime) { List<ArrivalAndDepartureInstance> filteredInstances = new ArrayList<ArrivalAndDepartureInstance>(); for (ArrivalAndDepartureInstance instance : instances) { FrequencyEntry entry = instance.getFrequency(); boolean toAdd = (entry == null) || (instance.getServiceDate() + (entry.getStartTime() * 1000) < targetTime.getTargetTime()) || (instance.getBlockLocation() != null && instance.getBlockLocation().isPredicted()); if (toAdd) filteredInstances.add(instance); } return filteredInstances; } return instances; }  @Autowired void setStopTimeService(StopTimeService stopTimeService); @Autowired void setBlockLocationService(
      BlockLocationService blockLocationService); @Autowired void setBlockStatusService(BlockStatusService blockStatusService); void setRemoveFuturePredictionsWithoutRealtime(boolean remove); @Override List<ArrivalAndDepartureInstance> getArrivalsAndDeparturesForStopInTimeRange(
      StopEntry stop, TargetTime targetTime, long fromTime, long toTime); @Override List<ArrivalAndDepartureInstance> getScheduledArrivalsAndDeparturesForStopInTimeRange(
      StopEntry stop, long currentTime, long fromTime, long toTime); @Override List<ArrivalAndDepartureInstance> getNextScheduledBlockTripDeparturesForStop(
      StopEntry stop, long time, boolean includePrivateService); @Override ArrivalAndDepartureInstance getArrivalAndDepartureForStop(
      ArrivalAndDepartureQuery query); @Override ArrivalAndDepartureInstance getPreviousStopArrivalAndDeparture(
      ArrivalAndDepartureInstance instance); @Override ArrivalAndDepartureInstance getNextStopArrivalAndDeparture(
      ArrivalAndDepartureInstance instance);  }
@Test public void testGetArrivalsAndDeparturesForStopInTimeRange(){ List<TimepointPredictionRecord> tprs = getTimepointPredictionsWithSkippedStop(); List<ArrivalAndDepartureInstance> arrivalsAndDepartures = getArrivalsAndDeparturesForStopInTimeRangeByTimepointPredictionRecord(tprs); assertEquals(2, arrivalsAndDepartures.size()); assertEquals(2, arrivalsAndDepartures.get(0).getBlockLocation().getTimepointPredictions().size()); assertNotNull(arrivalsAndDepartures.get(0).getBlockLocation().getTimepointPredictions().get(0).getScheduleRelationship()); assertEquals(1, arrivalsAndDepartures.get(0).getBlockLocation().getTimepointPredictions().get(0).getScheduleRelationship().getValue()); assertEquals(arrivalsAndDepartures.get(0).getBlockLocation().getTimepointPredictions().get(1).getTimepointPredictedArrivalTime(), arrivalsAndDepartures.get(0).getPredictedArrivalTime()); }