stopTime(4, toStop, trip1A, time(10, 10), time(10, 15), 0.0);
stopTime(5, toStop, trip1B, time(10, 20), time(10, 25), 0.0);
stopTime(6, toStop, trip1C, time(10, 30), time(10, 35), 0.0);
stopTime(7, toStop, trip1D, time(10, 40), time(10, 45), 0.0);
BlockConfigurationEntry b1A = linkBlockTrips("b1A", trip1A);
BlockConfigurationEntry b1B = linkBlockTrips("b1B", trip1B);
BlockConfigurationEntry b1C = linkBlockTrips("b1C", trip1C);
BlockConfigurationEntry b1D = linkBlockTrips("b1D", trip1D);
BlockSequenceIndex index1 = createBlockSequenceIndex(b1A, b1B, b1C, b1D);
BlockStopSequenceIndex fromIndex1 = new BlockStopSequenceIndex(index1, 0);
BlockStopSequenceIndex toIndex1 = new BlockStopSequenceIndex(index1, 1);
Pair<BlockStopSequenceIndex> indexPair1 = Tuples.pair(fromIndex1, toIndex1);
TripEntryImpl trip2A = trip("2A", "sA");
TripEntryImpl trip2B = trip("2B", "sA");
TripEntryImpl trip2C = trip("2C", "sA");
TripEntryImpl trip2D = trip("2D", "sA");
stopTime(0, fromStop, trip2A, time(10, 07), time(10, 07), 0.0);
stopTime(1, fromStop, trip2B, time(10, 17), time(10, 17), 0.0);
stopTime(2, fromStop, trip2C, time(10, 27), time(10, 27), 0.0);
stopTime(3, fromStop, trip2D, time(10, 37), time(10, 37), 0.0);
stopTime(4, toStop, trip2A, time(10, 17), time(10, 17), 0.0);
stopTime(5, toStop, trip2B, time(10, 27), time(10, 27), 0.0);
stopTime(6, toStop, trip2C, time(10, 37), time(10, 37), 0.0);
stopTime(7, toStop, trip2D, time(10, 47), time(10, 47), 0.0);
BlockConfigurationEntry b2A = linkBlockTrips("bA", trip2A);
BlockConfigurationEntry b2B = linkBlockTrips("bB", trip2B);
BlockConfigurationEntry b2C = linkBlockTrips("bC", trip2C);
BlockConfigurationEntry b2D = linkBlockTrips("bD", trip2D);
BlockSequenceIndex index2 = createBlockSequenceIndex(b2A, b2B, b2C, b2D);
BlockStopSequenceIndex fromIndex2 = new BlockStopSequenceIndex(index2, 0);
BlockStopSequenceIndex toIndex2 = new BlockStopSequenceIndex(index2, 1);
Pair<BlockStopSequenceIndex> indexPair2 = Tuples.pair(fromIndex2, toIndex2);
List<Pair<BlockStopSequenceIndex>> indices = new ArrayList<Pair<BlockStopSequenceIndex>>();
indices.add(indexPair1);
indices.add(indexPair2);
Mockito.when(
_blockIndexService.getBlockSequenceIndicesBetweenStops(fromStop, toStop)).thenReturn(
indices);
TripEntryImpl tripF = trip("freq", "sA");
stopTime(0, fromStop, tripF, time(10, 00), time(10, 00), 0.0);
stopTime(4, toStop, tripF, time(10, 05), time(10, 05), 0.0);
FrequencyEntry frequency = new FrequencyEntryImpl(time(10, 30),
time(11, 30), 10 * 60);
List<FrequencyEntry> frequencies = Arrays.asList(frequency);
BlockConfigurationEntry bcFreq = linkBlockTrips(block("bFreq"),
frequencies, tripF);
FrequencyBlockTripIndex freqIndex = _factory.createFrequencyIndexForTrips(
bcFreq.getTrips(), frequencies);
FrequencyStopTripIndex freqFromIndex = new FrequencyStopTripIndex(
freqIndex, 0);
FrequencyStopTripIndex freqToIndex = new FrequencyStopTripIndex(freqIndex,
1);
Pair<FrequencyStopTripIndex> freqIndexPair = Tuples.pair(freqFromIndex,
freqToIndex);
List<Pair<FrequencyStopTripIndex>> frequencyIndices = new ArrayList<Pair<FrequencyStopTripIndex>>();
frequencyIndices.add(freqIndexPair);
Mockito.when(
_blockIndexService.getFrequencyIndicesBetweenStops(fromStop, toStop)).thenReturn(
frequencyIndices);
/****
*
****/
Date time = date("2009-09-01 08:00");
List<Pair<StopTimeInstance>> instances = _service.getNextDeparturesBetweenStopPair(
fromStop, toStop, time, 0, 0, 3, includePrivateService);
assertEquals(3, instances.size());
Pair<StopTimeInstance> pair = instances.get(0);
assertSame(fromStop, pair.getFirst().getStop());
assertSame(toStop, pair.getSecond().getStop());
assertEquals(dateAsLong("2009-09-01 00:00"),
pair.getFirst().getServiceDate());
assertEquals(b1A.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b1A.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(1);
assertEquals(b2A.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b2A.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(2);
assertEquals(b1B.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b1B.getStopTimes().get(1), pair.getSecond().getStopTime());
/****
*
****/
time = date("2009-09-01 08:00");
instances = _service.getNextDeparturesBetweenStopPair(fromStop, toStop,
time, 10 * 60, 0, 3, includePrivateService);
assertEquals(5, instances.size());
pair = instances.get(0);
assertEquals(b1A.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b1A.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(1);
assertEquals(b2A.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b2A.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(2);
assertEquals(b1B.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b1B.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(3);
assertEquals(b2B.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b2B.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(4);
assertEquals(b1C.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b1C.getStopTimes().get(1), pair.getSecond().getStopTime());
/****
*
****/
time = date("2009-09-01 10:06");
instances = _service.getNextDeparturesBetweenStopPair(fromStop, toStop,
time, 0, 0, 3, includePrivateService);
assertEquals(3, instances.size());
pair = instances.get(0);
assertEquals(b2A.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b2A.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(1);
assertEquals(b1B.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b1B.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(2);
assertEquals(b2B.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b2B.getStopTimes().get(1), pair.getSecond().getStopTime());
/****
*
****/
time = date("2009-09-01 10:06");
instances = _service.getNextDeparturesBetweenStopPair(fromStop, toStop,
time, 10 * 60, 5 * 60, 3, includePrivateService);
assertEquals(8, instances.size());
pair = instances.get(0);
assertEquals(b1A.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b1A.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(1);
assertEquals(b2A.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b2A.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(2);
assertEquals(b1B.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b1B.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(3);
assertEquals(b2B.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b2B.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(4);
assertEquals(b1C.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b1C.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(5);
assertEquals(b2C.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b2C.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(6);
assertEquals(bcFreq.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(bcFreq.getStopTimes().get(1), pair.getSecond().getStopTime());
assertEquals(dateAsLong("2009-09-01 10:30"),
pair.getFirst().getDepartureTime());
assertEquals(dateAsLong("2009-09-01 10:35"),
pair.getSecond().getDepartureTime());
pair = instances.get(7);
assertEquals(b1D.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b1D.getStopTimes().get(1), pair.getSecond().getStopTime());
/****
*
****/
time = date("2009-09-02 10:06");
instances = _service.getNextDeparturesBetweenStopPair(fromStop, toStop,
time, 0, 0, 3, includePrivateService);
assertEquals(3, instances.size());
pair = instances.get(0);
assertEquals(dateAsLong("2009-09-02 00:00"),
pair.getFirst().getServiceDate());
assertEquals(b2A.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b2A.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(1);
assertEquals(b1B.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b1B.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(2);
assertEquals(b2B.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b2B.getStopTimes().get(1), pair.getSecond().getStopTime());
/****
*
****/
time = date("2009-09-02 10:29");
instances = _service.getNextDeparturesBetweenStopPair(fromStop, toStop,
time, 0, 0, 3, includePrivateService);
assertEquals(3, instances.size());
pair = instances.get(0);
assertEquals(bcFreq.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(bcFreq.getStopTimes().get(1), pair.getSecond().getStopTime());
assertEquals(dateAsLong("2009-09-02 10:30"),
pair.getFirst().getDepartureTime());
assertEquals(dateAsLong("2009-09-02 10:35"),
pair.getSecond().getDepartureTime());
pair = instances.get(1);
assertEquals(b1D.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b1D.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(2);
assertEquals(b2D.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b2D.getStopTimes().get(1), pair.getSecond().getStopTime());
/****
*
****/
time = date("2009-09-02 10:40");
instances = _service.getNextDeparturesBetweenStopPair(fromStop, toStop,
time, 0, 0, 3, includePrivateService);
assertEquals(1, instances.size());
pair = instances.get(0);
assertEquals(bcFreq.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(bcFreq.getStopTimes().get(1), pair.getSecond().getStopTime());
assertEquals(dateAsLong("2009-09-02 10:40"),
pair.getFirst().getDepartureTime());
assertEquals(dateAsLong("2009-09-02 10:45"),
pair.getSecond().getDepartureTime());
/****
*
****/
time = date("2009-09-02 11:40");
instances = _service.getNextDeparturesBetweenStopPair(fromStop, toStop,
time, 0, 0, 3, includePrivateService);
assertEquals(0, instances.size());
/****
*
****/
time = date("2009-09-02 10:50");
instances = _service.getPreviousArrivalsBetweenStopPair(fromStop, toStop,
time, 0, 0, 3, includePrivateService);
assertEquals(3, instances.size());
pair = instances.get(0);
assertEquals(b2D.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b2D.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(1);
assertEquals(bcFreq.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(bcFreq.getStopTimes().get(1), pair.getSecond().getStopTime());
assertEquals(dateAsLong("2009-09-02 10:40"),
pair.getFirst().getDepartureTime());
assertEquals(dateAsLong("2009-09-02 10:45"),
pair.getSecond().getDepartureTime());
pair = instances.get(2);
assertEquals(b1D.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b1D.getStopTimes().get(1), pair.getSecond().getStopTime());
/****
*
****/
time = date("2009-09-02 10:46");
instances = _service.getPreviousArrivalsBetweenStopPair(fromStop, toStop,
time, 0, 0, 3, includePrivateService);
assertEquals(3, instances.size());
pair = instances.get(0);
assertEquals(bcFreq.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(bcFreq.getStopTimes().get(1), pair.getSecond().getStopTime());
assertEquals(dateAsLong("2009-09-02 10:40"),
pair.getFirst().getDepartureTime());
assertEquals(dateAsLong("2009-09-02 10:45"),
pair.getSecond().getDepartureTime());
pair = instances.get(1);
assertEquals(b1D.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b1D.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(2);
assertEquals(b2C.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b2C.getStopTimes().get(1), pair.getSecond().getStopTime());
/****
*
****/
time = date("2009-09-02 10:40");
instances = _service.getPreviousArrivalsBetweenStopPair(fromStop, toStop,
time, 0, 0, 3, includePrivateService);
assertEquals(3, instances.size());
pair = instances.get(0);
assertEquals(b2C.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(b2C.getStopTimes().get(1), pair.getSecond().getStopTime());
pair = instances.get(1);
assertEquals(bcFreq.getStopTimes().get(0), pair.getFirst().getStopTime());
assertEquals(bcFreq.getStopTimes().get(1), pair.getSecond().getStopTime());
assertEquals(dateAsLong("2009-09-02 10:30"),
pair.getFirst().getDepartureTime());
assertEquals(dateAsLong("2009-09-02 10:35"),
pair.getSecond().getDepartureTime());