ArrivalAndDepartureServiceImpl implements ArrivalAndDepartureService { private BlockStopTimeEntry getBlockStopTime( BlockTripInstance blockTripInstance, AgencyAndId stopId, int stopSequence, int timeOfServiceDate) { BlockTripEntry blockTrip = blockTripInstance.getBlockTrip(); TripEntry trip = blockTrip.getTrip(); List<StopTimeEntry> stopTimes = trip.getStopTimes(); if (stopSequence > -1) { int offset = 0; while (true) { int before = stopSequence - offset; if (isMatch(stopTimes, stopId, before)) { return blockTrip.getStopTimes().get(before); } int after = stopSequence + offset; if (isMatch(stopTimes, stopId, after)) { return blockTrip.getStopTimes().get(after); } if (before < 0 && after >= stopTimes.size()) return null; offset++; } } else { Min<BlockStopTimeEntry> m = new Min<BlockStopTimeEntry>(); int index = 0; for (StopTimeEntry stopTime : stopTimes) { if (stopTime.getStop().getId().equals(stopId)) { int a = Math.abs(timeOfServiceDate - stopTime.getArrivalTime()); int b = Math.abs(timeOfServiceDate - stopTime.getDepartureTime()); int delta = Math.min(a, b); m.add(delta, blockTrip.getStopTimes().get(index)); } index++; } if (m.isEmpty()) return null; return m.getMinElement(); } }  @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 testGetArrivalsAndDeparturesForStopInTimeRange19() { TimepointPredictionRecord tprA = new TimepointPredictionRecord(); tprA.setTimepointId(mStopA.getId()); long tprATime = createPredictedTime(time(13, 30)); tprA.setTimepointPredictedDepartureTime(tprATime); tprA.setTripId(mTrip1.getId()); List<ArrivalAndDepartureInstance> arrivalsAndDepartures = getArrivalsAndDeparturesForStopInTimeRangeByTimepointPredictionRecord(Arrays.asList(tprA)); assertNotNull(arrivalsAndDepartures.get(0).getHistoricalOccupancy()); assertNotNull(arrivalsAndDepartures.get(0).getBlockStopTime().getStopTime().getHistoricalOccupancy()); assertNotNull(arrivalsAndDepartures.get(0).getStopTimeInstance().getStopTime().getStopTime().getHistoricalOccupancy()); }