@Override public TransitRoute createTransitRoute(final Id<TransitRoute> routeId, final NetworkRoute route, final List<TransitRouteStop> stops, final String mode) { return new TransitRouteImpl(routeId, route, stops, mode); }
TransitRouteStop orig = transitRoute.getStop(stopFacilities.get(route.getAccessStopId())); Id dest = route.getEgressStopId(); int i = transitRoute.getStops().indexOf(orig); while (i < transitRoute.getStops().size() - 1) { Id fromId = transitRoute.getStops().get(i).getStopFacility().getId(); TransitRouteStop toStop = transitRoute.getStops().get(i + 1); Id toId = toStop.getStopFacility().getId(); travelTime += stopStopTimes.getStopStopTime(fromId, toId, prevStopTime);
/** * In case we once should have more than one implementation of * {@link TransitRoute}, simply inherit from this test and overwrite * this method to return your own implementation. * * @param id * @param route * @param stops * @param mode * @return a new instance of a TransitRoute with the given attributes */ protected static TransitRoute createTransitRoute(final Id<TransitRoute> id, final NetworkRoute route, final List<TransitRouteStop> stops, final String mode) { return new TransitRouteImpl(id, route, stops, mode); }
public void testGetRoutesImmutable() { TransitLine tLine = createTransitLine(Id.create("1980", TransitLine.class)); TransitRoute route1 = new TransitRouteImpl(Id.create("11", TransitRoute.class), null, new ArrayList<TransitRouteStop>(), "bus"); try { tLine.getRoutes().put(route1.getId(), route1); fail("missing exception"); } catch (UnsupportedOperationException e) { log.info("catched expected exception.", e); } }
public void testAddRoute() { TransitLine tLine = createTransitLine(Id.create("0891", TransitLine.class)); TransitRoute route1 = new TransitRouteImpl(Id.create("1", TransitRoute.class), null, new ArrayList<TransitRouteStop>(), "bus"); TransitRoute route2 = new TransitRouteImpl(Id.create("2", TransitRoute.class), null, new ArrayList<TransitRouteStop>(), "bus"); assertEquals(0, tLine.getRoutes().size()); tLine.addRoute(route1); assertEquals(1, tLine.getRoutes().size()); assertNotNull(tLine.getRoutes().get(route1.getId())); tLine.addRoute(route2); assertEquals(2, tLine.getRoutes().size()); assertNotNull(tLine.getRoutes().get(route1.getId())); assertNotNull(tLine.getRoutes().get(route2.getId())); }
public void testAddRouteException() { TransitLine tLine = createTransitLine(Id.create("0891", TransitLine.class)); TransitRoute route1a = new TransitRouteImpl(Id.create("1", TransitRoute.class), null, new ArrayList<TransitRouteStop>(), "bus"); TransitRoute route1b = new TransitRouteImpl(Id.create("1", TransitRoute.class), null, new ArrayList<TransitRouteStop>(), "bus"); assertEquals(0, tLine.getRoutes().size()); tLine.addRoute(route1a); assertEquals(1, tLine.getRoutes().size()); // try adding a route with same id try { tLine.addRoute(route1b); fail("missing exception."); } catch (IllegalArgumentException e) { log.info("catched expected exception.", e); } // try adding a route a second time try { tLine.addRoute(route1a); fail("missing excetion."); } catch (IllegalArgumentException e) { log.info("catched expected exception. ", e); } }
public void testRemoveRoute() { TransitLine tLine = createTransitLine(Id.create("1980", TransitLine.class)); TransitRoute route1 = new TransitRouteImpl(Id.create("11", TransitRoute.class), null, new ArrayList<TransitRouteStop>(), "bus"); TransitRoute route2 = new TransitRouteImpl(Id.create("5", TransitRoute.class), null, new ArrayList<TransitRouteStop>(), "bus"); assertEquals(0, tLine.getRoutes().size()); tLine.addRoute(route1); tLine.addRoute(route2); assertEquals(2, tLine.getRoutes().size()); assertNotNull(tLine.getRoutes().get(route1.getId())); assertNotNull(tLine.getRoutes().get(route2.getId())); assertTrue(tLine.removeRoute(route1)); assertEquals(1, tLine.getRoutes().size()); assertNull(tLine.getRoutes().get(route1.getId())); assertNotNull(tLine.getRoutes().get(route2.getId())); assertTrue(tLine.removeRoute(route2)); assertEquals(0, tLine.getRoutes().size()); tLine.addRoute(route1); assertEquals(1, tLine.getRoutes().size()); assertFalse(tLine.removeRoute(route2)); assertEquals(1, tLine.getRoutes().size()); assertNotNull(tLine.getRoutes().get(route1.getId())); }