StopTimeServiceImpl implements StopTimeService { @Override public List<StopTimeInstance> getStopTimeInstancesInTimeRange( AgencyAndId stopId, Date from, Date to) { StopEntry stopEntry = _graph.getStopEntryForId(stopId, true); return getStopTimeInstancesInTimeRange(stopEntry, from, to, EFrequencyStopTimeBehavior.INCLUDE_UNSPECIFIED); }  @Autowired void setTransitGraphDao(TransitGraphDao graph); @Autowired void setCalendarService(ExtendedCalendarService calendarService); @Autowired void setBlockIndexService(BlockIndexService blockIndexService); @Override List<StopTimeInstance> getStopTimeInstancesInTimeRange(
      AgencyAndId stopId, Date from, Date to); @Override List<StopTimeInstance> getStopTimeInstancesInTimeRange(
      StopEntry stopEntry, Date from, Date to,
      EFrequencyStopTimeBehavior frequencyBehavior); @Override Range getDepartureForStopAndServiceDate(AgencyAndId stopId,
      ServiceDate serviceDate); @Override List<StopTimeInstance> getNextBlockSequenceDeparturesForStop(
      StopEntry stopEntry, long time, boolean includePrivateSerivce);  }
@Test public void test01() { Date from = date("2009-09-01 10:00"); Date to = date("2009-09-01 10:30"); Date day = getTimeAsDay(from); StopTimeEntryImpl stA = stopTime(0, _stop, trip("A", "sA"), time(9, 50), 0); StopTimeEntryImpl stB = stopTime(1, _stop, trip("B", "sA"), time(10, 10), 0); StopTimeEntryImpl stC = stopTime(2, _stop, trip("C", "sA"), time(10, 20), 0); StopTimeEntryImpl stD = stopTime(3, _stop, trip("D", "sA"), time(10, 40), 0); BlockConfigurationEntry bA = linkBlockTrips("bA", stA.getTrip()); BlockConfigurationEntry bB = linkBlockTrips("bB", stB.getTrip()); BlockConfigurationEntry bC = linkBlockTrips("bC", stC.getTrip()); BlockConfigurationEntry bD = linkBlockTrips("bD", stD.getTrip()); addFirstStopToBlockIndex(bA, bB, bC, bD); List<StopTimeInstance> results = _service.getStopTimeInstancesInTimeRange( _stopId, from, to); sort(results); assertEquals(2, results.size()); StopTimeInstance sti = results.get(0); assertEquals(day.getTime(), sti.getServiceDate()); assertEquals(dateAsLong("2009-09-01 10:10"), sti.getArrivalTime()); assertEquals(dateAsLong("2009-09-01 10:10"), sti.getDepartureTime()); sti = results.get(1); assertEquals(day.getTime(), sti.getServiceDate()); assertEquals(date("2009-09-01 10:20").getTime(), sti.getArrivalTime()); assertEquals(date("2009-09-01 10:20").getTime(), sti.getDepartureTime()); from = date("2009-09-01 10:15"); to = date("2009-09-01 10:25"); results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to); sort(results); assertEquals(1, results.size()); sti = results.get(0); assertEquals(day.getTime(), sti.getServiceDate()); assertEquals(date("2009-09-01 10:20").getTime(), sti.getArrivalTime()); assertEquals(date("2009-09-01 10:20").getTime(), sti.getDepartureTime()); from = date("2009-09-01 10:21"); to = date("2009-09-01 10:25"); results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to); assertEquals(0, results.size()); }
@Test public void test02() { Date dayA = getTimeAsDay(date("2009-09-01 00:00")); Date dayB = getTimeAsDay(date("2009-09-02 00:00")); StopTimeEntryImpl stA = stopTime(0, _stop, trip("A", "sA"), time(10, 00), time(10, 30), 0); StopTimeEntryImpl stB = stopTime(1, _stop, trip("B", "sA"), time(25, 00), time(25, 30), 0); BlockConfigurationEntry bA = linkBlockTrips("bA", stA.getTrip()); BlockConfigurationEntry bB = linkBlockTrips("bB", stB.getTrip()); addFirstStopToBlockIndex(bA, bB); Date from = date("2009-09-01 10:10"); Date to = date("2009-09-01 10:40"); List<StopTimeInstance> results = _service.getStopTimeInstancesInTimeRange( _stopId, from, to); sort(results); assertEquals(1, results.size()); StopTimeInstance sti = results.get(0); assertEquals(dayA.getTime(), sti.getServiceDate()); assertEquals(date("2009-09-01 10:00").getTime(), sti.getArrivalTime()); assertEquals(date("2009-09-01 10:30").getTime(), sti.getDepartureTime()); from = date("2009-09-02 10:10"); to = date("2009-09-02 10:40"); results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to); sort(results); assertEquals(1, results.size()); sti = results.get(0); assertEquals(dayB.getTime(), sti.getServiceDate()); assertEquals(date("2009-09-02 10:00").getTime(), sti.getArrivalTime()); assertEquals(date("2009-09-02 10:30").getTime(), sti.getDepartureTime()); from = date("2009-09-01 10:10"); to = date("2009-09-02 10:40"); results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to); sort(results); assertEquals(3, results.size()); sti = results.get(0); assertEquals(dayA.getTime(), sti.getServiceDate()); assertEquals(date("2009-09-01 10:00").getTime(), sti.getArrivalTime()); assertEquals(date("2009-09-01 10:30").getTime(), sti.getDepartureTime()); sti = results.get(1); assertEquals(dayA.getTime(), sti.getServiceDate()); assertEquals(date("2009-09-02 01:00").getTime(), sti.getArrivalTime()); assertEquals(date("2009-09-02 01:30").getTime(), sti.getDepartureTime()); sti = results.get(2); assertEquals(dayB.getTime(), sti.getServiceDate()); assertEquals(date("2009-09-02 10:00").getTime(), sti.getArrivalTime()); assertEquals(date("2009-09-02 10:30").getTime(), sti.getDepartureTime()); from = date("2009-09-01 12:00"); to = date("2009-09-02 12:00"); results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to); sort(results); assertEquals(2, results.size()); sti = results.get(0); assertEquals(dayA.getTime(), sti.getServiceDate()); assertEquals(date("2009-09-02 01:00").getTime(), sti.getArrivalTime()); assertEquals(date("2009-09-02 01:30").getTime(), sti.getDepartureTime()); sti = results.get(1); assertEquals(dayB.getTime(), sti.getServiceDate()); assertEquals(date("2009-09-02 10:00").getTime(), sti.getArrivalTime()); assertEquals(date("2009-09-02 10:30").getTime(), sti.getDepartureTime()); from = date("2009-09-02 12:00"); to = date("2009-09-03 12:00"); results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to); sort(results); assertEquals(1, results.size()); sti = results.get(0); assertEquals(dayB.getTime(), sti.getServiceDate()); assertEquals(date("2009-09-03 01:00").getTime(), sti.getArrivalTime()); assertEquals(date("2009-09-03 01:30").getTime(), sti.getDepartureTime()); }
@Test public void test03() { Date dayA = getTimeAsDay(date("2009-09-02 00:00")); Date dayB = getTimeAsDay(date("2009-09-03 00:00")); StopTimeEntryImpl stA = stopTime(0, _stop, trip("A", "sA"), time(10, 00), time(10, 30), 0); StopTimeEntryImpl stB = stopTime(1, _stop, trip("B", "sA"), time(25, 0), time(25, 30), 0); StopTimeEntryImpl stC = stopTime(2, _stop, trip("C", "sB"), time(10, 00), time(10, 30), 0); StopTimeEntryImpl stD = stopTime(3, _stop, trip("D", "sB"), time(25, 0), time(25, 30), 0); BlockConfigurationEntry bA = linkBlockTrips("bA", stA.getTrip()); BlockConfigurationEntry bB = linkBlockTrips("bB", stB.getTrip()); BlockConfigurationEntry bC = linkBlockTrips("bC", stC.getTrip()); BlockConfigurationEntry bD = linkBlockTrips("bD", stD.getTrip()); addFirstStopToBlockIndex(bA, bB); addFirstStopToBlockIndex(bC, bD); Date from = date("2009-09-02 10:10"); Date to = date("2009-09-02 10:40"); List<StopTimeInstance> results = _service.getStopTimeInstancesInTimeRange( _stopId, from, to); sort(results); assertEquals(1, results.size()); StopTimeInstance sti = results.get(0); assertEquals(dayA.getTime(), sti.getServiceDate()); assertEquals(date("2009-09-02 10:00").getTime(), sti.getArrivalTime()); assertEquals(date("2009-09-02 10:30").getTime(), sti.getDepartureTime()); from = date("2009-09-03 10:10"); to = date("2009-09-03 10:40"); results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to); sort(results); assertEquals(1, results.size()); sti = results.get(0); assertEquals(dayB.getTime(), sti.getServiceDate()); assertEquals(date("2009-09-03 10:00").getTime(), sti.getArrivalTime()); assertEquals(date("2009-09-03 10:30").getTime(), sti.getDepartureTime()); from = date("2009-09-02 10:10"); to = date("2009-09-03 10:40"); results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to); sort(results); assertEquals(3, results.size()); sti = results.get(0); assertEquals(dayA.getTime(), sti.getServiceDate()); assertEquals(date("2009-09-02 10:00").getTime(), sti.getArrivalTime()); assertEquals(date("2009-09-02 10:30").getTime(), sti.getDepartureTime()); sti = results.get(1); assertEquals(dayA.getTime(), sti.getServiceDate()); assertEquals(date("2009-09-03 01:00").getTime(), sti.getArrivalTime()); assertEquals(date("2009-09-03 01:30").getTime(), sti.getDepartureTime()); sti = results.get(2); assertEquals(dayB.getTime(), sti.getServiceDate()); assertEquals(date("2009-09-03 10:00").getTime(), sti.getArrivalTime()); assertEquals(date("2009-09-03 10:30").getTime(), sti.getDepartureTime()); from = date("2009-09-02 12:00"); to = date("2009-09-03 12:00"); results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to); sort(results); assertEquals(2, results.size()); sti = results.get(0); assertEquals(dayA.getTime(), sti.getServiceDate()); assertEquals(date("2009-09-03 01:00").getTime(), sti.getArrivalTime()); assertEquals(date("2009-09-03 01:30").getTime(), sti.getDepartureTime()); sti = results.get(1); assertEquals(dayB.getTime(), sti.getServiceDate()); assertEquals(date("2009-09-03 10:00").getTime(), sti.getArrivalTime()); assertEquals(date("2009-09-03 10:30").getTime(), sti.getDepartureTime()); from = date("2009-09-03 12:00"); to = date("2009-09-04 12:00"); results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to); sort(results); assertEquals(1, results.size()); sti = results.get(0); assertEquals(dayB.getTime(), sti.getServiceDate()); assertEquals(date("2009-09-04 01:00").getTime(), sti.getArrivalTime()); assertEquals(date("2009-09-04 01:30").getTime(), sti.getDepartureTime()); }