use of org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl in project onebusaway-application-modules by camsys.
the class StopEntriesFactory method processStops.
/**
* Iterate over each stop, generating a StopEntry for the graph.
*
* @param graph
*/
public void processStops(TransitGraphImpl graph) {
int stopIndex = 0;
Collection<Stop> stops = _gtfsDao.getAllStops();
int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(stops.size());
Map<String, ArrayList<StopEntry>> stopEntriesByAgencyId = new FactoryMap<String, ArrayList<StopEntry>>(new ArrayList<StopEntry>());
for (Stop stop : stops) {
if (stopIndex % logInterval == 0)
_log.info("stops: " + stopIndex + "/" + stops.size());
stopIndex++;
StopEntryImpl stopEntry = new StopEntryImpl(stop.getId(), stop.getLat(), stop.getLon());
stopEntry.setWheelchairBoarding(getWheelchairBoardingAccessibilityForStop(stop));
graph.putStopEntry(stopEntry);
stopEntriesByAgencyId.get(stop.getId().getAgencyId()).add(stopEntry);
}
for (Map.Entry<String, ArrayList<StopEntry>> entry : stopEntriesByAgencyId.entrySet()) {
String agencyId = entry.getKey();
ArrayList<StopEntry> stopEntries = entry.getValue();
stopEntries.trimToSize();
AgencyEntryImpl agency = graph.getAgencyForId(agencyId);
if (agency == null) {
String msg = null;
if (stopEntries.size() > 0) {
msg = "no agency found for agencyId=" + agencyId + " of stop entry " + stopEntries.get(0).getId();
} else {
msg = "no agency found for agencyId=" + agencyId + " of empty stop entry list.";
}
_log.error(msg);
throw new IllegalStateException(msg);
}
agency.setStops(stopEntries);
}
graph.refreshStopMapping();
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl in project onebusaway-application-modules by camsys.
the class RouteCollectionEntriesFactoryTest method testProcessRouteCollections.
@Test
public void testProcessRouteCollections() {
TransitGraphImpl graph = new TransitGraphImpl();
AgencyEntryImpl agency = new AgencyEntryImpl();
agency.setId("A");
graph.putAgencyEntry(agency);
graph.refreshAgencyMapping();
RouteEntryImpl routeA = new RouteEntryImpl();
routeA.setId(new AgencyAndId("A", "routeA"));
graph.putRouteEntry(routeA);
RouteEntryImpl routeB = new RouteEntryImpl();
routeB.setId(new AgencyAndId("A", "routeB"));
graph.putRouteEntry(routeB);
RouteCollectionEntriesFactory factory = new RouteCollectionEntriesFactory();
GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
factory.setGtfsDao(gtfsDao);
factory.setUniqueService(new UniqueServiceImpl());
factory.processRouteCollections(graph);
RouteCollectionEntry routeEntryA = graph.getRouteCollectionForId(routeA.getId());
assertEquals(routeA.getId(), routeEntryA.getId());
List<RouteEntry> routes = routeEntryA.getChildren();
assertEquals(1, routes.size());
assertTrue(routes.contains(routeA));
RouteCollectionEntry routeEntryB = graph.getRouteCollectionForId(routeB.getId());
assertEquals(routeB.getId(), routeEntryB.getId());
routes = routeEntryB.getChildren();
assertEquals(1, routes.size());
assertTrue(routes.contains(routeB));
List<RouteCollectionEntry> routeCollections = graph.getAllRouteCollections();
assertEquals(2, routeCollections.size());
assertTrue(routeCollections.contains(routeEntryA));
assertTrue(routeCollections.contains(routeEntryB));
routeCollections = agency.getRouteCollections();
assertEquals(2, routeCollections.size());
assertTrue(routeCollections.contains(routeEntryA));
assertTrue(routeCollections.contains(routeEntryB));
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl in project onebusaway-application-modules by camsys.
the class RouteCollectionEntriesFactoryTest method testGroupRoutesByShortName.
@Test
public void testGroupRoutesByShortName() {
TransitGraphImpl graph = new TransitGraphImpl();
AgencyEntryImpl agency = new AgencyEntryImpl();
agency.setId("A");
graph.putAgencyEntry(agency);
graph.refreshAgencyMapping();
RouteEntryImpl routeA = new RouteEntryImpl();
routeA.setId(new AgencyAndId("A", "routeA"));
graph.putRouteEntry(routeA);
RouteEntryImpl routeB = new RouteEntryImpl();
routeB.setId(new AgencyAndId("A", "routeB"));
graph.putRouteEntry(routeB);
GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
Route rA = new Route();
rA.setId(routeA.getId());
rA.setShortName("10");
Mockito.when(gtfsDao.getRouteForId(routeA.getId())).thenReturn(rA);
Route rB = new Route();
rB.setId(routeB.getId());
rB.setShortName("10");
Mockito.when(gtfsDao.getRouteForId(routeB.getId())).thenReturn(rB);
RouteCollectionEntriesFactory factory = new RouteCollectionEntriesFactory();
factory.setGroupRoutesByShortName(true);
factory.setGtfsDao(gtfsDao);
factory.setUniqueService(new UniqueServiceImpl());
factory.processRouteCollections(graph);
AgencyAndId id = new AgencyAndId("A", "10");
RouteCollectionEntry routeCollectionEntry = graph.getRouteCollectionForId(id);
assertEquals(id, routeCollectionEntry.getId());
List<RouteEntry> routes = routeCollectionEntry.getChildren();
assertEquals(2, routes.size());
assertTrue(routes.contains(routeA));
assertTrue(routes.contains(routeB));
List<RouteCollectionEntry> routeCollections = graph.getAllRouteCollections();
assertEquals(1, routeCollections.size());
assertTrue(routeCollections.contains(routeCollectionEntry));
routeCollections = agency.getRouteCollections();
assertEquals(1, routeCollections.size());
assertTrue(routeCollections.contains(routeCollectionEntry));
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl in project onebusaway-application-modules by camsys.
the class AgencyEntriesFactory method processAgencies.
public void processAgencies(TransitGraphImpl graph) {
Collection<Agency> agencies = _gtfsDao.getAllAgencies();
for (Agency agency : agencies) {
AgencyEntryImpl agencyEntry = new AgencyEntryImpl();
agencyEntry.setId(_uniqueService.unique(agency.getId()));
graph.putAgencyEntry(agencyEntry);
}
graph.refreshAgencyMapping();
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl in project onebusaway-application-modules by camsys.
the class UnitTestingSupport method agency.
/**
**
* Entity Factory Methods
***
*/
public static AgencyEntryImpl agency(String id) {
AgencyEntryImpl agency = new AgencyEntryImpl();
agency.setId(id);
return agency;
}
Aggregations