Search in sources :

Example 1 with RouteCollectionEntryImpl

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

the class RouteBeanServiceImplTest method testGetStopsForRoute.

@Test
public void testGetStopsForRoute() {
    AgencyAndId routeId = new AgencyAndId("1", "route");
    RouteEntryImpl route = new RouteEntryImpl();
    route.setId(new AgencyAndId("1", "raw_route"));
    List<RouteEntry> routes = Arrays.asList((RouteEntry) route);
    RouteCollectionEntryImpl routeCollection = new RouteCollectionEntryImpl();
    routeCollection.setId(routeId);
    routeCollection.setChildren(routes);
    route.setParent(routeCollection);
    Mockito.when(_transitGraphDao.getRouteCollectionForId(routeId)).thenReturn(routeCollection);
    RouteCollectionNarrative.Builder rcNarrative = RouteCollectionNarrative.builder();
    Mockito.when(_narrativeService.getRouteCollectionForId(routeId)).thenReturn(rcNarrative.create());
    StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
    StopEntryImpl stopB = stop("stopB", 47.1, -122.1);
    StopEntryImpl stopC = stop("stopC", 47.2, -122.2);
    BlockEntryImpl blockA = block("blockA");
    TripEntryImpl tripA = trip("tripA", "sidA");
    TripEntryImpl tripB = trip("tripB", "sidA");
    tripA.setRoute(route);
    tripA.setDirectionId("0");
    tripB.setRoute(route);
    tripB.setDirectionId("1");
    route.setTrips(Arrays.asList((TripEntry) tripA, tripB));
    TripNarrative.Builder tnA = TripNarrative.builder();
    tnA.setTripHeadsign("Destination A");
    Mockito.when(_narrativeService.getTripForId(tripA.getId())).thenReturn(tnA.create());
    TripNarrative.Builder tnB = TripNarrative.builder();
    tnB.setTripHeadsign("Destination B");
    Mockito.when(_narrativeService.getTripForId(tripB.getId())).thenReturn(tnB.create());
    stopTime(0, stopA, tripA, time(9, 00), time(9, 00), 0);
    stopTime(1, stopB, tripA, time(9, 30), time(9, 30), 100);
    stopTime(2, stopC, tripA, time(10, 00), time(10, 00), 200);
    stopTime(3, stopC, tripB, time(11, 30), time(11, 30), 0);
    stopTime(4, stopA, tripB, time(12, 30), time(12, 30), 200);
    linkBlockTrips(blockA, tripA, tripB);
    List<BlockTripIndex> blockIndices = blockTripIndices(blockA);
    Mockito.when(_blockIndexService.getBlockTripIndicesForRouteCollectionId(routeId)).thenReturn(blockIndices);
    StopBean stopBeanA = getStopBean(stopA);
    StopBean stopBeanB = getStopBean(stopB);
    StopBean stopBeanC = getStopBean(stopC);
    List<AgencyAndId> stopIds = Arrays.asList(stopA.getId(), stopB.getId(), stopC.getId());
    Mockito.when(_routeService.getStopsForRouteCollection(routeId)).thenReturn(stopIds);
    Mockito.when(_stopBeanService.getStopForId(stopA.getId())).thenReturn(stopBeanA);
    Mockito.when(_stopBeanService.getStopForId(stopB.getId())).thenReturn(stopBeanB);
    Mockito.when(_stopBeanService.getStopForId(stopC.getId())).thenReturn(stopBeanC);
    AgencyAndId shapeId = new AgencyAndId("1", "shapeId");
    Set<AgencyAndId> shapeIds = new HashSet<AgencyAndId>();
    shapeIds.add(shapeId);
    tripA.setShapeId(shapeId);
    EncodedPolylineBean polyline = new EncodedPolylineBean();
    Mockito.when(_shapeBeanService.getMergedPolylinesForShapeIds(shapeIds)).thenReturn(Arrays.asList(polyline));
    // Setup complete
    StopsForRouteBean stopsForRoute = _service.getStopsForRoute(routeId);
    List<StopBean> stops = stopsForRoute.getStops();
    assertEquals(3, stops.size());
    assertSame(stopBeanA, stops.get(0));
    assertSame(stopBeanB, stops.get(1));
    assertSame(stopBeanC, stops.get(2));
    List<EncodedPolylineBean> polylines = stopsForRoute.getPolylines();
    assertEquals(1, polylines.size());
    assertSame(polyline, polylines.get(0));
    List<StopGroupingBean> groupings = stopsForRoute.getStopGroupings();
    assertEquals(1, groupings.size());
    StopGroupingBean grouping = groupings.get(0);
    assertEquals("direction", grouping.getType());
    List<StopGroupBean> groups = grouping.getStopGroups();
    assertEquals(2, groups.size());
    StopGroupBean groupA = groups.get(0);
    StopGroupBean groupB = groups.get(1);
    NameBean nameA = groupA.getName();
    assertEquals("destination", nameA.getType());
    assertEquals("Destination A", nameA.getName());
    List<String> stopIdsA = groupA.getStopIds();
    assertEquals(3, stopIdsA.size());
    assertEquals(ids(stopA.getId(), stopB.getId(), stopC.getId()), stopIdsA);
    NameBean nameB = groupB.getName();
    assertEquals("destination", nameB.getType());
    assertEquals("Destination B", nameB.getName());
    List<String> stopIdsB = groupB.getStopIds();
    assertEquals(2, stopIdsB.size());
    assertEquals(ids(stopC.getId(), stopA.getId()), stopIdsB);
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) BlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex) HashSet(java.util.HashSet) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) RouteCollectionNarrative(org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopBean(org.onebusaway.transit_data.model.StopBean) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) NameBean(org.onebusaway.transit_data.model.NameBean) TripNarrative(org.onebusaway.transit_data_federation.model.narrative.TripNarrative) Test(org.junit.Test)

Example 2 with RouteCollectionEntryImpl

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

the class UnitTestingSupport method routeCollection.

public static RouteCollectionEntryImpl routeCollection(String id, RouteEntry... routes) {
    RouteCollectionEntryImpl route = new RouteCollectionEntryImpl();
    route.setId(aid(id));
    route.setChildren(Arrays.asList(routes));
    for (RouteEntry routeEntry : routes) {
        ((RouteEntryImpl) routeEntry).setParent(route);
    }
    return route;
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)

Example 3 with RouteCollectionEntryImpl

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

the class GtfsRealtimeEntitySourceTest method testGetRouteId.

@Test
public void testGetRouteId() {
    RouteCollectionEntryImpl routeCollection = new RouteCollectionEntryImpl();
    routeCollection.setId(new AgencyAndId("2", "R10C"));
    RouteEntryImpl route = new RouteEntryImpl();
    route.setId(new AgencyAndId("2", "R10"));
    route.setParent(routeCollection);
    Mockito.when(_dao.getRouteForId(route.getId())).thenReturn(route);
    Id routeId = _source.getRouteId("R10");
    assertEquals("2", routeId.getAgencyId());
    assertEquals("R10C", routeId.getId());
    routeId = _source.getRouteId("R11");
    assertEquals("1", routeId.getAgencyId());
    assertEquals("R11", routeId.getId());
}
Also used : RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) Id(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Id) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Test(org.junit.Test)

Example 4 with RouteCollectionEntryImpl

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

the class RouteCollectionEntriesFactory method createRouteShortNameRouteCollectionMapping.

private void createRouteShortNameRouteCollectionMapping(TransitGraphImpl graph) {
    Map<AgencyAndId, List<RouteEntryImpl>> routesByKey = new HashMap<AgencyAndId, List<RouteEntryImpl>>();
    for (RouteEntryImpl routeEntry : graph.getRoutes()) {
        Route route = _gtfsDao.getRouteForId(routeEntry.getId());
        AgencyAndId key = getRouteCollectionIdForRoute(route);
        List<RouteEntryImpl> forKey = routesByKey.get(key);
        if (forKey == null) {
            forKey = new ArrayList<RouteEntryImpl>();
            routesByKey.put(key, forKey);
        }
        forKey.add(routeEntry);
    }
    for (Map.Entry<AgencyAndId, List<RouteEntryImpl>> entry : routesByKey.entrySet()) {
        AgencyAndId key = entry.getKey();
        List<RouteEntryImpl> routesForKey = entry.getValue();
        ArrayList<RouteEntry> children = new ArrayList<RouteEntry>();
        children.addAll(routesForKey);
        children.trimToSize();
        key = _uniqueService.unique(key);
        RouteCollectionEntryImpl routeCollectionEntry = new RouteCollectionEntryImpl();
        routeCollectionEntry.setId(key);
        routeCollectionEntry.setChildren(children);
        graph.putRouteCollectionEntry(routeCollectionEntry);
        for (RouteEntryImpl route : routesForKey) route.setParent(routeCollectionEntry);
    }
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap) Route(org.onebusaway.gtfs.model.Route)

Example 5 with RouteCollectionEntryImpl

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

the class RouteCollectionEntriesFactory method createOneToOneRouteCollectionMapping.

private void createOneToOneRouteCollectionMapping(TransitGraphImpl graph) {
    for (RouteEntryImpl routeEntry : graph.getRoutes()) {
        RouteCollectionEntryImpl routeCollectionEntry = new RouteCollectionEntryImpl();
        routeCollectionEntry.setId(routeEntry.getId());
        ArrayList<RouteEntry> routes = new ArrayList<RouteEntry>();
        routes.add(routeEntry);
        routes.trimToSize();
        routeCollectionEntry.setChildren(routes);
        graph.putRouteCollectionEntry(routeCollectionEntry);
        routeEntry.setParent(routeCollectionEntry);
    }
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) ArrayList(java.util.ArrayList) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)

Aggregations

RouteCollectionEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl)7 RouteEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)6 Test (org.junit.Test)4 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)4 RouteEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry)4 RouteCollectionNarrative (org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative)3 ArrayList (java.util.ArrayList)2 Route (org.onebusaway.gtfs.model.Route)2 RouteCollectionEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry)2 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 FactoryMap (org.onebusaway.collections.FactoryMap)1 EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)1 NameBean (org.onebusaway.transit_data.model.NameBean)1 StopBean (org.onebusaway.transit_data.model.StopBean)1 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)1 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)1