org.opentripplanner.routing.algorithm.raptoradapter.transit.mappers.ServiceCalendarMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
package org.opentripplanner.routing.algorithm.raptoradapter.transit.mappers;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import org.opentripplanner.model.calendar.CalendarService;
import org.opentripplanner.model.FeedScopedId;
import org.opentripplanner.model.calendar.ServiceDate;
import java.time.LocalDate;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* This uses the integer service codes that are already present in the pre-Raptor OTP graph.
*/
class ServiceCalendarMapper {
static Multimap mapServiceCodesByLocalDates(
CalendarService calendarService,
Map serviceCodes
) {
Multimap serviceCodesByLocalDates = HashMultimap.create();
if (calendarService != null) {
for (FeedScopedId serviceId : calendarService.getServiceIds()) {
Set localDates = calendarService.getServiceDatesForServiceId(serviceId)
.stream()
.map(ServiceCalendarMapper::localDateFromServiceDate)
.collect(Collectors.toSet());
int serviceIndex = serviceCodes.get(serviceId);
for (LocalDate date : localDates) {
serviceCodesByLocalDates.put(date, serviceIndex);
}
}
}
return serviceCodesByLocalDates;
}
static LocalDate localDateFromServiceDate(ServiceDate serviceDate) {
return LocalDate.of(serviceDate.getYear(), serviceDate.getMonth(), serviceDate.getDay());
}
}