Package org.onebusaway.transit_data_federation.impl.transit_graph

Examples of org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl


  }

  @Test
  public void testGenerateStopNarrativesWithConflictingDirections() {

    StopEntryImpl stopEntry = stop("stopA", 47.663146, -122.300928);

    Mockito.when(_transitGraphDao.getAllStops()).thenReturn(
        Arrays.asList((StopEntry) stopEntry));

    Stop stop = new Stop();
    stop.setId(stopEntry.getId());
    Mockito.when(_gtfsDao.getAllStops()).thenReturn(Arrays.asList(stop));

    /**
     * Two shapes heading in opposite directions
     */
    AgencyAndId shapeIdA = aid("shapeA");
    ShapePointsFactory factoryA = new ShapePointsFactory();
    factoryA.addPoint(47.661225, -122.3009201);
    factoryA.addPoint(47.664375, -122.3008986);
    ShapePoints shapePointsA = factoryA.create();
    _provider.setShapePointsForId(shapeIdA, shapePointsA);

    AgencyAndId shapeIdB = aid("shapeB");
    ShapePointsFactory factoryB = new ShapePointsFactory();
    factoryB.addPoint(47.664375, -122.3008986);
    factoryB.addPoint(47.661225, -122.3009201);
    ShapePoints shapePointsB = factoryB.create();
    _provider.setShapePointsForId(shapeIdB, shapePointsB);

    TripEntryImpl tripA = trip("tripA");
    tripA.setShapeId(shapeIdA);

    TripEntryImpl tripB = trip("tripB");
    tripB.setShapeId(shapeIdB);

    StopTimeEntryImpl stopTimeA = stopTime(0, stopEntry, tripA, 0, 0.0);
    stopTimeA.setShapePointIndex(0);

    StopTimeEntryImpl stopTimeB = stopTime(0, stopEntry, tripB, 0, 0.0);
    stopTimeB.setShapePointIndex(0);

    BlockStopTimeEntry blockStopTimeA = Mockito.mock(BlockStopTimeEntry.class);
    Mockito.when(blockStopTimeA.getStopTime()).thenReturn(stopTimeA);

    BlockStopTimeEntry blockStopTimeB = Mockito.mock(BlockStopTimeEntry.class);
    Mockito.when(blockStopTimeB.getStopTime()).thenReturn(stopTimeB);

    BlockStopTimeIndex index = Mockito.mock(BlockStopTimeIndex.class);
    Mockito.when(index.getStopTimes()).thenReturn(
        Arrays.asList(blockStopTimeA, blockStopTimeB));

    List<BlockStopTimeIndex> indices = Arrays.asList(index);
    Mockito.when(_blockIndexService.getStopTimeIndicesForStop(stopEntry)).thenReturn(
        indices);

    _task.generateStopNarratives(_provider);

    StopNarrative narrative = _provider.getNarrativeForStopId(stopEntry.getId());
    assertNull(narrative.getDirection());
  }
View Full Code Here


    TripNarrative narrative = _provider.getNarrativeForTripId(trip.getId());
    assertEquals(trip.getRouteShortName(), narrative.getRouteShortName());
    assertEquals(trip.getTripHeadsign(), narrative.getTripHeadsign());
    assertEquals(trip.getTripShortName(), narrative.getTripShortName());

    StopEntryImpl stopEntry = stop("stop", 47.0, -122.0);
    TripEntryImpl tripEntry = trip("trip");
    StopTimeEntryImpl stopTimeEntry = stopTime(0, stopEntry, tripEntry, 0, 0.0);

    StopTimeNarrative stopTimeNarrative = _provider.getNarrativeForStopTimeEntry(stopTimeEntry);
    assertEquals(stopTime.getRouteShortName(),
View Full Code Here

    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));
View Full Code Here

    TripEntryImpl tripA = trip("tripA");
    TripEntryImpl tripB = trip("tripB");
    TripEntryImpl tripC = trip("tripC");
    TripEntryImpl tripD = trip("tripD");

    StopEntryImpl stopA = stop("stopA", 0, 0);
    StopEntryImpl stopB = stop("stopB", 0, 0);

    stopTime(0, stopA, tripA, time(7, 30), 0.0);
    stopTime(1, stopB, tripB, time(8, 30), 0.0);
    stopTime(2, stopA, tripC, time(8, 30), 0.0);
    stopTime(3, stopB, tripD, time(9, 30), 0.0);
View Full Code Here

    long t = dateAsLong("2010-10-05 16:30");
    long serviceDate = dateAsLong("2010-10-05 00:00");
    int minutesBefore = 5;
    int minutesAfter = 30;

    StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
    StopEntryImpl stopB = stop("stopB", 47.0, -122.0);

    Mockito.when(_transitGraphDao.getStopEntryForId(stopA.getId(), true)).thenReturn(
        stopA);
    Mockito.when(_transitGraphDao.getStopEntryForId(stopB.getId(), true)).thenReturn(
        stopB);

    /****
     * Block A
     ****/

    BlockEntryImpl blockA = block("blockA");
    TripEntryImpl tripA = trip("tripA", "sA", 3000);

    stopTime(0, stopA, tripA, time(16, 30), time(16, 35), 1000);
    StopTimeEntryImpl stopTimeAB = stopTime(1, stopB, tripA, time(16, 40),
        time(16, 45), 2000);

    BlockConfigurationEntry blockConfigA = blockConfiguration(blockA,
        serviceIds(lsids("sA"), lsids()), tripA);
    BlockStopTimeEntry bstAA = blockConfigA.getStopTimes().get(0);
    BlockStopTimeEntry bstAB = blockConfigA.getStopTimes().get(1);

    /****
     * Block B
     ****/

    BlockEntryImpl blockB = block("blockB");
    TripEntryImpl tripB = trip("tripB", "sA", 3000);

    stopTime(2, stopA, tripB, time(16, 40), time(16, 45), 1000);
    StopTimeEntryImpl stopTimeBB = stopTime(3, stopB, tripB, time(16, 50),
        time(16, 55), 2000);

    BlockConfigurationEntry blockConfigB = blockConfiguration(blockB,
        serviceIds(lsids("sA"), lsids()), tripB);
    BlockStopTimeEntry bstBA = blockConfigB.getStopTimes().get(0);
    BlockStopTimeEntry bstBB = blockConfigB.getStopTimes().get(1);

    /****
     *
     ****/

    BlockInstance blockInstanceA = new BlockInstance(blockConfigA, serviceDate);
    long lastUpdateTime = dateAsLong("2010-10-05 16:15");

    BlockLocation blockLocationA = new BlockLocation();
    blockLocationA.setActiveTrip(bstAA.getTrip());
    blockLocationA.setBlockInstance(blockInstanceA);
    blockLocationA.setClosestStop(bstAA);
    blockLocationA.setDistanceAlongBlock(500);
    blockLocationA.setInService(true);
    blockLocationA.setLastUpdateTime(lastUpdateTime);
    blockLocationA.setNextStop(bstAA);
    blockLocationA.setPredicted(true);
    blockLocationA.setScheduledDistanceAlongBlock(600);
    blockLocationA.setScheduleDeviation(10 * 60);
    blockLocationA.setVehicleId(aid("vehicle"));

    /****
     *
     ****/

    BlockInstance blockInstanceB = new BlockInstance(blockConfigB, serviceDate);

    BlockLocation blockLocationB = new BlockLocation();
    blockLocationB.setActiveTrip(bstBA.getTrip());
    blockLocationB.setBlockInstance(blockInstanceA);
    blockLocationB.setClosestStop(bstBA);
    blockLocationB.setDistanceAlongBlock(400);
    blockLocationB.setInService(true);
    blockLocationB.setNextStop(bstAA);
    blockLocationB.setPredicted(false);
    blockLocationB.setScheduledDistanceAlongBlock(400);

    /****
     *
     ****/

    long stopTimeFrom = t - minutesBefore * 60 * 1000;
    long stopTimeTo = t + minutesAfter * 60 * 1000;

    StopTimeInstance sti1 = new StopTimeInstance(bstAB,blockInstanceA.getState());
    ArrivalAndDepartureInstance in1 = new ArrivalAndDepartureInstance(sti1);
    in1.setBlockLocation(blockLocationA);
    in1.setPredictedArrivalTime((long) (in1.getScheduledArrivalTime() + 5 * 60 * 1000));
    in1.setPredictedDepartureTime((long) (in1.getScheduledDepartureTime()));

    StopTimeInstance sti2 = new StopTimeInstance(bstBB, blockInstanceB.getState());
    ArrivalAndDepartureInstance in2 = new ArrivalAndDepartureInstance(sti2);
    in2.setBlockLocation(blockLocationB);

    TargetTime target = new TargetTime(t, t);

    Mockito.when(
        _arrivalAndDepartureService.getArrivalsAndDeparturesForStopInTimeRange(
            stopB, target, stopTimeFrom, stopTimeTo)).thenReturn(
        Arrays.asList(in1, in2));

    /****
     *
     ****/

    Builder stopTimeNarrative = StopTimeNarrative.builder();
    stopTimeNarrative.setStopHeadsign("Downtown");
    Mockito.when(_narrativeService.getStopTimeForEntry(stopTimeAB)).thenReturn(
        stopTimeNarrative.create());

    stopTimeNarrative = StopTimeNarrative.builder();
    stopTimeNarrative.setRouteShortName("XX");
    Mockito.when(_narrativeService.getStopTimeForEntry(stopTimeBB)).thenReturn(
        stopTimeNarrative.create());

    /****
     *
     ****/

    StopBean stopABean = new StopBean();
    stopABean.setId("1_stopA");
    Mockito.when(_stopBeanService.getStopForId(stopA.getId())).thenReturn(
        stopABean);

    StopBean stopBBean = new StopBean();
    stopBBean.setId("1_stopB");
    Mockito.when(_stopBeanService.getStopForId(stopB.getId())).thenReturn(
        stopBBean);

    /****
     *
     ****/

    TripBean tripABean = new TripBean();
    Mockito.when(_tripBeanService.getTripForId(aid("tripA"))).thenReturn(
        tripABean);

    TripBean tripBBean = new TripBean();
    Mockito.when(_tripBeanService.getTripForId(aid("tripB"))).thenReturn(
        tripBBean);

    /****
     *
     ****/

    TripStatusBean tripStatusBeanA = new TripStatusBean();
    TripStatusBean tripStatusBeanB = new TripStatusBean();

    Mockito.when(
        _tripDetailsBeanService.getBlockLocationAsStatusBean(blockLocationA, t)).thenReturn(
        tripStatusBeanA);

    Mockito.when(
        _tripDetailsBeanService.getBlockLocationAsStatusBean(blockLocationB, t)).thenReturn(
        tripStatusBeanB);

    /****
     *
     ****/

    ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
    query.setTime(t);
    query.setMinutesBefore(minutesBefore);
    query.setMinutesAfter(minutesAfter);
    query.setFrequencyMinutesBefore(minutesBefore);
    query.setFrequencyMinutesAfter(minutesAfter);

    List<ArrivalAndDepartureBean> arrivalsAndDepartures = _service.getArrivalsAndDeparturesByStopId(
        stopB.getId(), query);

    assertEquals(2, arrivalsAndDepartures.size());

    ArrivalAndDepartureBean bean = arrivalsAndDepartures.get(0);
    assertEquals(1500, bean.getDistanceFromStop(), 0.0);
View Full Code Here

public class BlockStopTimeIndicesFactoryTest {

  @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);

    /****
     * Block A
     ****/

 
View Full Code Here

  }

  @Test
  public void testFrequencies() {

    StopEntryImpl stopA = stop("a", 47.0, -122.0);
    StopEntryImpl stopB = stop("b", 47.1, -122.1);

    /****
     * Block A
     ****/

 
View Full Code Here

  }

  @Test
  public void testGetStopId() {

    StopEntryImpl stop = new StopEntryImpl(new AgencyAndId("2", "S10"), 0, 0);
    Mockito.when(_dao.getStopEntryForId(stop.getId())).thenReturn(stop);

    Id stopId = _source.getStopId("S10");
    assertEquals("2", stopId.getAgencyId());
    assertEquals("S10", stopId.getId());
View Full Code Here

    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);

  }
View Full Code Here

  public static StopEntryImpl stop(String id) {
    return stop(id, 0.0, 0.0);
  }

  public static StopEntryImpl stop(String id, double lat, double lon) {
    return new StopEntryImpl(aid(id), lat, lon);
  }
View Full Code Here

TOP

Related Classes of org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.