BlockCalendarServiceImpl implements BlockCalendarService { @Override public List<BlockInstance> getActiveBlocksInTimeRange(long timeFrom, long timeTo) { List<BlockTripIndex> indices = _blockIndexService.getBlockTripIndices(); List<BlockLayoverIndex> layoverIndices = _blockIndexService.getBlockLayoverIndices(); List<FrequencyBlockTripIndex> frequencyIndices = _blockIndexService.getFrequencyBlockTripIndices(); return getActiveBlocksInTimeRange(indices, layoverIndices, frequencyIndices, timeFrom, timeTo); }  @Autowired void setCalendarService(ExtendedCalendarService calendarService); @Autowired void setBlockIndexService(BlockIndexService blockIndexService); @Autowired void setTransitGraphDao(TransitGraphDao transitGraphDao); @Cacheable(isValueSerializable = false) @Override BlockInstance getBlockInstance(AgencyAndId blockId, long serviceDate); @Override List<BlockInstance> getActiveBlocks(AgencyAndId blockId,
      long timeFrom, long timeTo); @Override List<BlockInstance> getClosestActiveBlocks(AgencyAndId blockId,
      long time); @Override List<BlockInstance> getActiveBlocksInTimeRange(long timeFrom,
      long timeTo); @Override List<BlockInstance> getActiveBlocksForAgencyInTimeRange(
      String agencyId, long timeFrom, long timeTo); @Override List<BlockInstance> getActiveBlocksForRouteInTimeRange(
      AgencyAndId routeId, long timeFrom, long timeTo); @Override List<BlockInstance> getActiveBlocksInTimeRange(
      Iterable<BlockTripIndex> indices,
      Iterable<BlockLayoverIndex> layoverIndices,
      Iterable<FrequencyBlockTripIndex> frequencyIndices, long timeFrom,
      long timeTo);  }
@Test public void testGetActiveBlocksInTimeRange() { Date serviceDateA = UnitTestingSupport.date("2010-09-07 00:00"); Date serviceDateB = UnitTestingSupport.date("2010-09-08 00:00"); Date serviceDateC = UnitTestingSupport.date("2010-09-09 00:00"); UnitTestingSupport.addDates(_calendarData, "sidA", serviceDateA, serviceDateB); UnitTestingSupport.addDates(_calendarData, "sidB", serviceDateB, serviceDateC); ServiceIdActivation ids_A_not_B = serviceIds(lsids("sidA"), lsids("sidB")); ServiceIdActivation ids_B_not_A = serviceIds(lsids("sidB"), lsids("sidA")); ServiceIdActivation ids_A_and_B = serviceIds(lsids("sidA", "sidB"), lsids()); StopEntryImpl stopA = stop("stopA", 0.0, 0.0); StopEntryImpl stopB = stop("stopB", 0.0, 0.0); BlockEntryImpl blockA = block("blockA"); TripEntryImpl tripA = trip("tripA", "sidA"); TripEntryImpl tripB = trip("tripB", "sidB"); stopTime(0, stopA, tripA, time(9, 00), time(9, 00), 0); stopTime(1, stopB, tripA, time(9, 30), time(9, 30), 100); stopTime(2, stopB, tripB, time(10, 00), time(10, 00), 200); stopTime(3, stopA, tripB, time(10, 30), time(10, 30), 300); linkBlockTrips(ids_A_not_B, blockA, tripA); linkBlockTrips(ids_A_and_B, blockA, tripA, tripB); linkBlockTrips(ids_B_not_A, blockA, tripB); BlockConfigurationEntry bcA_A_B = findBlockConfig(blockA, ids_A_not_B); BlockConfigurationEntry bcA_B_A = findBlockConfig(blockA, ids_B_not_A); BlockConfigurationEntry bcA_AB = findBlockConfig(blockA, ids_A_and_B); BlockEntryImpl blockB = block("blockB"); TripEntryImpl tripC = trip("tripC", "sidA"); TripEntryImpl tripD = trip("tripD", "sidB"); TripEntryImpl tripE = trip("tripE", "sidA"); stopTime(4, stopA, tripC, time(10, 00), time(10, 00), 0); stopTime(5, stopB, tripC, time(10, 30), time(10, 30), 0); stopTime(6, stopB, tripD, time(11, 00), time(11, 00), 0); stopTime(7, stopA, tripD, time(11, 30), time(11, 30), 0); stopTime(8, stopA, tripE, time(12, 00), time(12, 00), 0); stopTime(9, stopB, tripE, time(12, 30), time(12, 30), 0); linkBlockTrips(ids_A_not_B, blockB, tripC, tripE); linkBlockTrips(ids_A_and_B, blockB, tripC, tripD, tripE); linkBlockTrips(ids_B_not_A, blockB, tripD); BlockConfigurationEntry bcB_A_B = findBlockConfig(blockB, ids_A_not_B); BlockConfigurationEntry bcB_B_A = findBlockConfig(blockB, ids_B_not_A); BlockConfigurationEntry bcB_AB = findBlockConfig(blockB, ids_A_and_B); List<BlockTripIndex> blocks = blockTripIndices(blockA, blockB); List<BlockLayoverIndex> layoverIndices = Collections.emptyList(); List<FrequencyBlockTripIndex> frequencyIndices = Collections.emptyList(); long time = timeFromString("2010-09-07 09:15"); List<BlockInstance> instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time); assertEquals(1, instances.size()); BlockInstance instance = instances.get(0); assertEquals(bcA_A_B, instance.getBlock()); assertEquals(serviceDateA.getTime(), instance.getServiceDate()); time = timeFromString("2010-09-07 010:15"); instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time); assertEquals(1, instances.size()); instance = instances.get(0); assertEquals(bcB_A_B, instance.getBlock()); assertEquals(serviceDateA.getTime(), instance.getServiceDate()); time = timeFromString("2010-09-07 012:15"); instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time); assertEquals(1, instances.size()); instance = instances.get(0); assertEquals(bcB_A_B, instance.getBlock()); assertEquals(serviceDateA.getTime(), instance.getServiceDate()); time = timeFromString("2010-09-08 09:15"); instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time); assertEquals(1, instances.size()); instance = instances.get(0); assertEquals(bcA_AB, instance.getBlock()); assertEquals(serviceDateB.getTime(), instance.getServiceDate()); time = timeFromString("2010-09-08 10:15"); instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time); Collections.sort(instances, new BlockInstanceComparator()); assertEquals(2, instances.size()); instance = instances.get(0); assertEquals(bcA_AB, instance.getBlock()); assertEquals(serviceDateB.getTime(), instance.getServiceDate()); instance = instances.get(1); assertEquals(bcB_AB, instance.getBlock()); assertEquals(serviceDateB.getTime(), instance.getServiceDate()); time = timeFromString("2010-09-08 11:15"); instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time); assertEquals(1, instances.size()); instance = instances.get(0); assertEquals(bcB_AB, instance.getBlock()); assertEquals(serviceDateB.getTime(), instance.getServiceDate()); time = timeFromString("2010-09-08 12:15"); instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time); assertEquals(1, instances.size()); instance = instances.get(0); assertEquals(bcB_AB, instance.getBlock()); assertEquals(serviceDateB.getTime(), instance.getServiceDate()); time = timeFromString("2010-09-09 09:15"); instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time); assertEquals(0, instances.size()); time = timeFromString("2010-09-09 10:15"); instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time); assertEquals(1, instances.size()); instance = instances.get(0); assertEquals(bcA_B_A, instance.getBlock()); assertEquals(serviceDateC.getTime(), instance.getServiceDate()); time = timeFromString("2010-09-09 11:15"); instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time); assertEquals(1, instances.size()); instance = instances.get(0); assertEquals(bcB_B_A, instance.getBlock()); assertEquals(serviceDateC.getTime(), instance.getServiceDate()); }