All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.routing.algorithm.raptoradapter.transit.mappers.ServiceCalendarMapper Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
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());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy