Search in sources :

Example 6 with AgencyEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl in project onebusaway-application-modules by camsys.

the class RouteCollectionEntriesFactory method groupRouteCollectionsByAgencyId.

private void groupRouteCollectionsByAgencyId(TransitGraphImpl graph) {
    Map<String, ArrayList<RouteCollectionEntry>> entriesByAgencyId = new FactoryMap<String, ArrayList<RouteCollectionEntry>>(new ArrayList<RouteCollectionEntry>());
    for (RouteCollectionEntry entry : graph.getAllRouteCollections()) {
        String agencyId = entry.getId().getAgencyId();
        entriesByAgencyId.get(agencyId).add(entry);
    }
    for (Map.Entry<String, ArrayList<RouteCollectionEntry>> entry : entriesByAgencyId.entrySet()) {
        String agencyId = entry.getKey();
        ArrayList<RouteCollectionEntry> routeCollections = entry.getValue();
        routeCollections.trimToSize();
        AgencyEntryImpl agencyEntry = graph.getAgencyForId(agencyId);
        agencyEntry.setRouteCollections(routeCollections);
    }
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) AgencyEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl) ArrayList(java.util.ArrayList) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) HashMap(java.util.HashMap) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap)

Example 7 with AgencyEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl in project onebusaway-application-modules by camsys.

the class StopEntriesFactoryTest method test.

@Test
public void test() {
    Stop stopA = new Stop();
    stopA.setId(new AgencyAndId("1", "stopA"));
    stopA.setCode("A");
    stopA.setDesc("Stop A Description");
    stopA.setLat(47.0);
    stopA.setLon(-122.0);
    stopA.setLocationType(0);
    stopA.setName("Stop A");
    Stop stopB = new Stop();
    stopB.setId(new AgencyAndId("1", "stopB"));
    stopB.setCode("B");
    stopB.setDesc("Stop B Description");
    stopB.setLat(47.1);
    stopB.setLon(-122.1);
    stopB.setLocationType(0);
    stopB.setName("Stop B");
    GtfsRelationalDao dao = Mockito.mock(GtfsRelationalDao.class);
    Mockito.when(dao.getAllStops()).thenReturn(Arrays.asList(stopA, stopB));
    StopEntriesFactory factory = new StopEntriesFactory();
    factory.setGtfsDao(dao);
    TransitGraphImpl graph = new TransitGraphImpl();
    AgencyEntryImpl agency = new AgencyEntryImpl();
    agency.setId("1");
    graph.putAgencyEntry(agency);
    graph.refreshAgencyMapping();
    factory.processStops(graph);
    StopEntryImpl stopEntryA = graph.getStopEntryForId(stopA.getId());
    assertEquals(stopA.getId(), stopEntryA.getId());
    assertEquals(stopA.getLat(), stopEntryA.getStopLat(), 0);
    assertEquals(stopA.getLon(), stopEntryA.getStopLon(), 0);
    StopEntryImpl stopEntryB = graph.getStopEntryForId(stopB.getId());
    assertEquals(stopB.getId(), stopEntryB.getId());
    assertEquals(stopB.getLat(), stopEntryB.getStopLat(), 0);
    assertEquals(stopB.getLon(), stopEntryB.getStopLon(), 0);
    List<StopEntry> stops = graph.getAllStops();
    assertEquals(2, stops.size());
    assertTrue(stops.contains(stopEntryA));
    assertTrue(stops.contains(stopEntryB));
    stops = agency.getStops();
    assertTrue(stops.contains(stopEntryA));
    assertTrue(stops.contains(stopEntryB));
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) AgencyEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopEntriesFactory(org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.StopEntriesFactory) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Aggregations

AgencyEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl)7 Test (org.junit.Test)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)3 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)3 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)3 RouteCollectionEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 FactoryMap (org.onebusaway.collections.FactoryMap)2 Stop (org.onebusaway.gtfs.model.Stop)2 UniqueServiceImpl (org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl)2 RouteEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)2 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)2 RouteEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry)2 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)2 HashMap (java.util.HashMap)1 Agency (org.onebusaway.gtfs.model.Agency)1 Route (org.onebusaway.gtfs.model.Route)1 StopEntriesFactory (org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.StopEntriesFactory)1