Search in sources :

Example 36 with FeedScopedId

use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.

the class NoticeAssignmentMapperTest method mapNoticeAssignment.

@Test
public void mapNoticeAssignment() {
    NoticeAssignment noticeAssignment = new NoticeAssignment();
    noticeAssignment.setNoticedObjectRef(new VersionOfObjectRefStructure().withRef(ROUTE_ID));
    noticeAssignment.setNotice(NOTICE);
    Route route = new Route();
    route.setId(MappingSupport.ID_FACTORY.createId(ROUTE_ID));
    EntityById<FeedScopedId, Route> routesById = new EntityById<>();
    routesById.add(route);
    NoticeAssignmentMapper noticeAssignmentMapper = new NoticeAssignmentMapper(MappingSupport.ID_FACTORY, new HierarchicalMultimap<>(), new HierarchicalMapById<>(), routesById, new EntityById<>(), new HashMap<>());
    Multimap<TransitEntity<?>, org.opentripplanner.model.Notice> noticesByElement = noticeAssignmentMapper.map(noticeAssignment);
    org.opentripplanner.model.Notice notice2 = noticesByElement.get(route).iterator().next();
    assertEquals(NOTICE_ID, notice2.getId().getId());
}
Also used : VersionOfObjectRefStructure(org.rutebanken.netex.model.VersionOfObjectRefStructure) TransitEntity(org.opentripplanner.model.TransitEntity) EntityById(org.opentripplanner.model.impl.EntityById) Notice(org.rutebanken.netex.model.Notice) NoticeAssignment(org.rutebanken.netex.model.NoticeAssignment) FeedScopedId(org.opentripplanner.model.FeedScopedId) Route(org.opentripplanner.model.Route) Test(org.junit.Test)

Example 37 with FeedScopedId

use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.

the class NoticeAssignmentMapperTest method mapNoticeAssignmentOnStopPoint.

@Test
public void mapNoticeAssignmentOnStopPoint() {
    HierarchicalMultimap<String, TimetabledPassingTime> passingTimeByStopPointId = new HierarchicalMultimap<>();
    HierarchicalMapById<Notice> noticesById = new HierarchicalMapById<>();
    passingTimeByStopPointId.add(STOP_POINT_ID, new TimetabledPassingTime().withId(TIMETABLED_PASSING_TIME1));
    passingTimeByStopPointId.add(STOP_POINT_ID, new TimetabledPassingTime().withId(TIMETABLED_PASSING_TIME2));
    Trip trip = new Trip();
    trip.setId(new FeedScopedId("T", "1"));
    StopTime stopTime1 = createStopTime(1, trip);
    StopTime stopTime2 = createStopTime(2, trip);
    Map<String, StopTime> stopTimesById = new HashMap<>();
    stopTimesById.put(TIMETABLED_PASSING_TIME1, stopTime1);
    stopTimesById.put(TIMETABLED_PASSING_TIME2, stopTime2);
    noticesById.add(NOTICE);
    NoticeAssignment noticeAssignment = new NoticeAssignment().withNoticedObjectRef(new VersionOfObjectRefStructure().withRef(STOP_POINT_ID)).withNoticeRef(new NoticeRefStructure().withRef(NOTICE_ID));
    NoticeAssignmentMapper noticeAssignmentMapper = new NoticeAssignmentMapper(MappingSupport.ID_FACTORY, passingTimeByStopPointId, noticesById, new EntityById<>(), new EntityById<>(), stopTimesById);
    Multimap<TransitEntity<?>, org.opentripplanner.model.Notice> noticesByElement = noticeAssignmentMapper.map(noticeAssignment);
    org.opentripplanner.model.Notice notice2a = noticesByElement.get(stopTime1.getId()).stream().findFirst().orElseThrow(IllegalStateException::new);
    org.opentripplanner.model.Notice notice2b = noticesByElement.get(stopTime2.getId()).stream().findFirst().orElseThrow(IllegalStateException::new);
    assertEquals(NOTICE_ID, notice2a.getId().getId());
    assertEquals(NOTICE_ID, notice2b.getId().getId());
}
Also used : Trip(org.opentripplanner.model.Trip) NoticeRefStructure(org.rutebanken.netex.model.NoticeRefStructure) VersionOfObjectRefStructure(org.rutebanken.netex.model.VersionOfObjectRefStructure) HashMap(java.util.HashMap) TransitEntity(org.opentripplanner.model.TransitEntity) MultilingualString(org.rutebanken.netex.model.MultilingualString) HierarchicalMultimap(org.opentripplanner.netex.loader.util.HierarchicalMultimap) HierarchicalMapById(org.opentripplanner.netex.loader.util.HierarchicalMapById) TimetabledPassingTime(org.rutebanken.netex.model.TimetabledPassingTime) Notice(org.rutebanken.netex.model.Notice) FeedScopedId(org.opentripplanner.model.FeedScopedId) NoticeAssignment(org.rutebanken.netex.model.NoticeAssignment) StopTime(org.opentripplanner.model.StopTime) Test(org.junit.Test)

Example 38 with FeedScopedId

use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.

the class OtpTransitServiceBuilderLimitPeriodTest method createTrip.

private Trip createTrip(String id, FeedScopedId serviceId) {
    Trip trip = new Trip();
    trip.setId(new FeedScopedId(FEED_ID, id));
    trip.setServiceId(serviceId);
    trip.setDirectionId("1");
    trip.setRoute(route);
    return trip;
}
Also used : Trip(org.opentripplanner.model.Trip) FeedScopedId(org.opentripplanner.model.FeedScopedId)

Example 39 with FeedScopedId

use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.

the class OtpTransitServiceBuilderLimitPeriodTest method createTripPattern.

private TripPattern createTripPattern(Collection<Trip> trips) {
    TripPattern p = new TripPattern(route, STOP_PATTERN);
    p.setId(new FeedScopedId(FEED_ID, trips.stream().map(t -> t.getId().getId()).collect(Collectors.joining(":"))));
    p.name = "Pattern";
    for (Trip trip : trips) {
        p.add(new TripTimes(trip, STOP_TIMES, DEDUPLICATOR));
    }
    return p;
}
Also used : FeedScopedId(org.opentripplanner.model.FeedScopedId) Trip(org.opentripplanner.model.Trip) TripPattern(org.opentripplanner.model.TripPattern) Stop(org.opentripplanner.model.Stop) Collection(java.util.Collection) ServiceCalendar(org.opentripplanner.model.calendar.ServiceCalendar) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) StopTime(org.opentripplanner.model.StopTime) Collectors(java.util.stream.Collectors) ServiceDate(org.opentripplanner.model.calendar.ServiceDate) List(java.util.List) Route(org.opentripplanner.model.Route) StopPattern(org.opentripplanner.model.StopPattern) ServiceCalendarDate(org.opentripplanner.model.calendar.ServiceCalendarDate) Deduplicator(org.opentripplanner.routing.trippattern.Deduplicator) TraverseMode(org.opentripplanner.routing.core.TraverseMode) TransitMode(org.opentripplanner.model.TransitMode) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) ServiceDateInterval(org.opentripplanner.model.calendar.ServiceDateInterval) Trip(org.opentripplanner.model.Trip) FeedScopedId(org.opentripplanner.model.FeedScopedId) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) TripPattern(org.opentripplanner.model.TripPattern)

Example 40 with FeedScopedId

use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.

the class OtpTransitServiceBuilderLimitPeriodTest method testLimitPeriod.

@Test
public void testLimitPeriod() {
    // Assert the test is set up as expected
    assertEquals(2, subject.getCalendars().size());
    assertEquals(2, subject.getCalendarDates().size());
    assertEquals(4, subject.getTripsById().size());
    assertEquals(3, subject.getTripPatterns().get(STOP_PATTERN).size());
    assertEquals(2, patternInT1.getTrips().size());
    assertEquals(2, patternInT1.scheduledTimetable.tripTimes.size());
    assertEquals(1, patternInT2.getTrips().size());
    assertEquals(1, patternInT2.scheduledTimetable.tripTimes.size());
    // Limit service to last half of month
    subject.limitServiceDays(new ServiceDateInterval(D2, D3));
    // Verify calendar
    List<ServiceCalendar> calendars = subject.getCalendars();
    assertEquals(calendars.toString(), 1, calendars.size());
    assertEquals(calendars.toString(), SERVICE_C_IN, calendars.get(0).getServiceId());
    // Verify calendar dates
    List<ServiceCalendarDate> dates = subject.getCalendarDates();
    assertEquals(dates.toString(), 1, dates.size());
    assertEquals(dates.toString(), SERVICE_D_IN, dates.get(0).getServiceId());
    // Verify trips
    EntityById<FeedScopedId, Trip> trips = subject.getTripsById();
    assertEquals(trips.toString(), 2, trips.size());
    assertTrue(trips.toString(), trips.containsKey(tripCSIn.getId()));
    assertTrue(trips.toString(), trips.containsKey(tripCSDIn.getId()));
    // Verify patterns
    Collection<TripPattern> patterns = subject.getTripPatterns().get(STOP_PATTERN);
    assertEquals(2, patterns.size());
    assertTrue(patterns.toString(), patterns.contains(patternInT1));
    assertTrue(patterns.toString(), patterns.contains(patternInT2));
    // Verify trips in pattern (one trip is removed from patternInT1)
    assertEquals(1, patternInT1.getTrips().size());
    assertEquals(tripCSIn, patternInT1.getTrips().get(0));
    // Verify trips in pattern is unchanged (one trip)
    assertEquals(1, patternInT2.getTrips().size());
    // Verify scheduledTimetable trips (one trip is removed from patternInT1)
    assertEquals(1, patternInT1.scheduledTimetable.tripTimes.size());
    assertEquals(tripCSIn, patternInT1.scheduledTimetable.tripTimes.get(0).trip);
    // Verify scheduledTimetable trips in pattern is unchanged (one trip)
    assertEquals(1, patternInT2.scheduledTimetable.tripTimes.size());
}
Also used : ServiceCalendarDate(org.opentripplanner.model.calendar.ServiceCalendarDate) Trip(org.opentripplanner.model.Trip) ServiceDateInterval(org.opentripplanner.model.calendar.ServiceDateInterval) FeedScopedId(org.opentripplanner.model.FeedScopedId) TripPattern(org.opentripplanner.model.TripPattern) ServiceCalendar(org.opentripplanner.model.calendar.ServiceCalendar) Test(org.junit.Test)

Aggregations

FeedScopedId (org.opentripplanner.model.FeedScopedId)117 Trip (org.opentripplanner.model.Trip)32 Test (org.junit.Test)29 Stop (org.opentripplanner.model.Stop)25 TripPattern (org.opentripplanner.model.TripPattern)25 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)21 ArrayList (java.util.ArrayList)20 Route (org.opentripplanner.model.Route)15 HashSet (java.util.HashSet)11 List (java.util.List)11 Agency (org.opentripplanner.model.Agency)11 Collection (java.util.Collection)9 Map (java.util.Map)9 Collectors (java.util.stream.Collectors)9 ZonedDateTime (java.time.ZonedDateTime)8 TransitEntity (org.opentripplanner.model.TransitEntity)8 RoutingService (org.opentripplanner.routing.RoutingService)8 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)8 Notice (org.opentripplanner.model.Notice)7 Station (org.opentripplanner.model.Station)7