BlockStopTimeIndicesFactory { public List<BlockStopTimeIndex> createIndices(Iterable<BlockEntry> blocks) { Map<BlockStopTimeKey, List<BlockStopTimeEntry>> stopTimesByKey = groupBlockStopTimes( blocks, false); return createIndicesFromGroups(stopTimesByKey); }  void setVerbose(boolean verbose); List<BlockStopTimeIndex> createIndices(Iterable<BlockEntry> blocks); List<FrequencyBlockStopTimeIndex> createFrequencyIndices(
      Iterable<BlockEntry> blocks);  }
@Test public void test() { StopEntryImpl stopA = stop("a", 47.0, -122.0); StopEntryImpl stopB = stop("b", 47.1, -122.1); StopEntryImpl stopC = stop("c", 47.2, -122.2); BlockEntryImpl blockA = block("a"); TripEntryImpl tripA1 = trip("a1", "s1"); TripEntryImpl tripA2 = trip("a2", "s1"); TripEntryImpl tripA3 = trip("a3", "s1"); stopTime(0, stopA, tripA1, 0, 10, 0); stopTime(0, stopB, tripA1, 20, 20, 0); stopTime(0, stopC, tripA2, 30, 30, 0); stopTime(0, stopA, tripA2, 40, 40, 0); stopTime(0, stopA, tripA3, 50, 50, 0); stopTime(0, stopB, tripA3, 60, 70, 0); BlockConfigurationEntry bcA = linkBlockTrips(blockA, tripA1, tripA2, tripA3); BlockEntryImpl blockB = block("b"); TripEntryImpl tripB1 = trip("b1", "s1"); TripEntryImpl tripB2 = trip("b2", "s1"); TripEntryImpl tripB3 = trip("b3", "s1"); stopTime(0, stopA, tripB1, 20, 30, 0); stopTime(0, stopB, tripB1, 50, 50, 0); stopTime(0, stopC, tripB2, 60, 60, 0); stopTime(0, stopA, tripB2, 70, 70, 0); stopTime(0, stopA, tripB3, 80, 80, 0); stopTime(0, stopB, tripB3, 90, 100, 0); BlockConfigurationEntry bcB = linkBlockTrips(blockB, tripB1, tripB2, tripB3); BlockEntryImpl blockC = block("c"); TripEntryImpl tripC1 = trip("c1", "s1"); TripEntryImpl tripC2 = trip("c2", "s1"); TripEntryImpl tripC3 = trip("c3", "s1"); stopTime(0, stopA, tripC1, 40, 50, 0); stopTime(0, stopB, tripC1, 60, 60, 0); stopTime(0, stopC, tripC2, 70, 70, 0); stopTime(0, stopA, tripC2, 80, 80, 0); stopTime(0, stopA, tripC3, 85, 85, 0); stopTime(0, stopB, tripC3, 90, 95, 0); BlockConfigurationEntry bcC = linkBlockTrips(blockC, tripC1, tripC2, tripC3); BlockEntryImpl blockD = block("d"); TripEntryImpl tripD1 = trip("d1", "s1"); TripEntryImpl tripD2 = trip("d2", "s1"); TripEntryImpl tripD3 = trip("d3", "s2"); stopTime(0, stopA, tripD1, 40, 50, 0); stopTime(0, stopB, tripD1, 70, 70, 0); stopTime(0, stopC, tripD2, 80, 80, 0); stopTime(0, stopA, tripD2, 90, 90, 0); stopTime(0, stopA, tripD3, 100, 100, 0); stopTime(0, stopB, tripD3, 110, 120, 0); BlockConfigurationEntry bcD = linkBlockTrips(blockD, tripD1, tripD2, tripD3); BlockEntryImpl blockE = block("e"); TripEntryImpl tripE1 = trip("e1", "s1"); TripEntryImpl tripE2 = trip("e2", "s1"); TripEntryImpl tripE3 = trip("e3", "s1"); stopTime(0, stopA, tripE1, 50, 60, 0); stopTime(0, stopB, tripE1, 80, 80, 0); stopTime(0, stopC, tripE2, 90, 90, 0); stopTime(0, stopA, tripE2, 100, 100, 0); stopTime(0, stopA, tripE3, 110, 110, 0); BlockConfigurationEntry bcE = linkBlockTrips(blockE, tripE1, tripE2, tripE3); BlockEntryImpl blockF = block("f"); TripEntryImpl tripF1 = trip("f1", "s1"); TripEntryImpl tripF2 = trip("f2", "s1"); TripEntryImpl tripF3 = trip("f3", "s1"); stopTime(0, stopA, tripF1, 40, 50, 0); stopTime(0, stopB, tripF1, 70, 70, 0); stopTime(0, stopC, tripF2, 80, 80, 0); stopTime(0, stopA, tripF2, 90, 90, 0); stopTime(0, stopA, tripF3, 100, 100, 0); BlockConfigurationEntry bcF = linkBlockTrips(blockF, tripF1, tripF2, tripF3); BlockEntryImpl blockG = block("g"); TripEntryImpl tripG1 = trip("g1", "s1"); TripEntryImpl tripG2 = trip("g2", "s1"); TripEntryImpl tripG3 = trip("g3", "s1"); stopTime(0, stopA, tripG1, 0, 10, 0, 0.0); stopTime(0, stopB, tripG1, 20, 20, 0, 25.0); stopTime(0, stopC, tripG2, 30, 30, 0, 50.0); stopTime(0, stopA, tripG2, 40, 40, 0, 75.0); stopTime(0, stopA, tripG3, 50, 50, 0, 90.0); stopTime(0, stopA, tripG3, 50, 50, 0, 99.0); stopTime(0, stopB, tripG3, 60, 70, 0, 100.0); BlockConfigurationEntry bcG = linkBlockTrips(blockG, tripG1, tripG2, tripG3); BlockStopTimeIndicesFactory factory = new BlockStopTimeIndicesFactory(); List<BlockStopTimeIndex> allIndices = factory.createIndices(Arrays.asList( (BlockEntry) blockF, blockE, blockD, blockC, blockB, blockA)); assertEquals(6, allIndices.size()); List<BlockStopTimeIndex> indices = grep(allIndices, aid("a"), serviceIds(lsids("s1"), lsids())); assertEquals(1, indices.size()); BlockStopTimeIndex index = indices.get(0); assertEquals(15, index.getStopTimes().size()); assertEquals(bcA.getStopTimes().get(0), index.getStopTimes().get(0)); assertEquals(bcB.getStopTimes().get(0), index.getStopTimes().get(1)); assertEquals(bcA.getStopTimes().get(3), index.getStopTimes().get(2)); assertEquals(bcF.getStopTimes().get(0), index.getStopTimes().get(3)); assertEquals(bcC.getStopTimes().get(0), index.getStopTimes().get(4)); assertEquals(bcA.getStopTimes().get(4), index.getStopTimes().get(5)); assertEquals(bcE.getStopTimes().get(0), index.getStopTimes().get(6)); assertEquals(bcB.getStopTimes().get(3), index.getStopTimes().get(7)); assertEquals(bcC.getStopTimes().get(3), index.getStopTimes().get(8)); assertEquals(bcB.getStopTimes().get(4), index.getStopTimes().get(9)); assertEquals(bcC.getStopTimes().get(4), index.getStopTimes().get(10)); assertEquals(bcF.getStopTimes().get(3), index.getStopTimes().get(11)); assertEquals(bcF.getStopTimes().get(4), index.getStopTimes().get(12)); assertEquals(bcE.getStopTimes().get(3), index.getStopTimes().get(13)); assertEquals(bcE.getStopTimes().get(4), index.getStopTimes().get(14)); indices = grep(allIndices, aid("a"), serviceIds(lsids("s1", "s2"), lsids())); assertEquals(1, indices.size()); index = indices.get(0); assertEquals(3, index.getStopTimes().size()); assertEquals(bcD.getStopTimes().get(0), index.getStopTimes().get(0)); assertEquals(bcD.getStopTimes().get(3), index.getStopTimes().get(1)); assertEquals(bcD.getStopTimes().get(4), index.getStopTimes().get(2)); indices = grep(allIndices, aid("b"), serviceIds(lsids("s1"), lsids())); assertEquals(1, indices.size()); index = indices.get(0); assertEquals(8, index.getStopTimes().size()); assertEquals(bcA.getStopTimes().get(1), index.getStopTimes().get(0)); assertEquals(bcB.getStopTimes().get(1), index.getStopTimes().get(1)); assertEquals(bcC.getStopTimes().get(1), index.getStopTimes().get(2)); assertEquals(bcA.getStopTimes().get(5), index.getStopTimes().get(3)); assertEquals(bcF.getStopTimes().get(1), index.getStopTimes().get(4)); assertEquals(bcE.getStopTimes().get(1), index.getStopTimes().get(5)); assertEquals(bcC.getStopTimes().get(5), index.getStopTimes().get(6)); assertEquals(bcB.getStopTimes().get(5), index.getStopTimes().get(7)); indices = grep(allIndices, aid("b"), serviceIds(lsids("s1", "s2"), lsids())); assertEquals(1, indices.size()); index = indices.get(0); assertEquals(2, index.getStopTimes().size()); assertEquals(bcD.getStopTimes().get(1), index.getStopTimes().get(0)); assertEquals(bcD.getStopTimes().get(5), index.getStopTimes().get(1)); indices = grep(allIndices, aid("c"), serviceIds(lsids("s1"), lsids())); assertEquals(1, indices.size()); index = indices.get(0); assertEquals(5, index.getStopTimes().size()); assertEquals(bcA.getStopTimes().get(2), index.getStopTimes().get(0)); assertEquals(bcB.getStopTimes().get(2), index.getStopTimes().get(1)); assertEquals(bcC.getStopTimes().get(2), index.getStopTimes().get(2)); assertEquals(bcF.getStopTimes().get(2), index.getStopTimes().get(3)); assertEquals(bcE.getStopTimes().get(2), index.getStopTimes().get(4)); indices = grep(allIndices, aid("c"), serviceIds(lsids("s1", "s2"), lsids())); assertEquals(1, indices.size()); index = indices.get(0); assertEquals(1, index.getStopTimes().size()); assertEquals(bcD.getStopTimes().get(2), index.getStopTimes().get(0)); assertNotNull(bcG.getStopTimes()); assertEquals(OccupancyStatus.EMPTY, bcG.getStopTimes().get(0).getStopTime().getHistoricalOccupancy()); assertEquals(OccupancyStatus.MANY_SEATS_AVAILABLE, bcG.getStopTimes().get(1).getStopTime().getHistoricalOccupancy()); assertEquals(OccupancyStatus.FEW_SEATS_AVAILABLE, bcG.getStopTimes().get(2).getStopTime().getHistoricalOccupancy()); assertEquals(OccupancyStatus.STANDING_ROOM_ONLY, bcG.getStopTimes().get(3).getStopTime().getHistoricalOccupancy()); assertEquals(OccupancyStatus.CRUSHED_STANDING_ROOM_ONLY, bcG.getStopTimes().get(4).getStopTime().getHistoricalOccupancy()); assertEquals(OccupancyStatus.FULL, bcG.getStopTimes().get(5).getStopTime().getHistoricalOccupancy()); assertEquals(OccupancyStatus.FULL, bcG.getStopTimes().get(6).getStopTime().getHistoricalOccupancy()); }