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

org.opentripplanner.gtfs.mapping.ServiceCalendarMapper Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package org.opentripplanner.gtfs.mapping;

import org.opentripplanner.model.calendar.ServiceCalendar;
import org.opentripplanner.util.MapUtils;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import static org.opentripplanner.gtfs.mapping.AgencyAndIdMapper.mapAgencyAndId;

/** Responsible for mapping GTFS ServiceCalendar into the OTP model. */
class ServiceCalendarMapper {
    private Map mappedCalendars = new HashMap<>();

    Collection map(
            Collection allServiceCalendars) {
        return MapUtils.mapToList(allServiceCalendars, this::map);
    }

    /** Map from GTFS to OTP model, {@code null} safe.  */
    ServiceCalendar map(org.onebusaway.gtfs.model.ServiceCalendar orginal) {
        return orginal == null ? null : mappedCalendars.computeIfAbsent(orginal, this::doMap);
    }

    private ServiceCalendar doMap(org.onebusaway.gtfs.model.ServiceCalendar rhs) {
        ServiceCalendar lhs = new ServiceCalendar();

        lhs.setServiceId(mapAgencyAndId(rhs.getServiceId()));
        lhs.setMonday(rhs.getMonday());
        lhs.setTuesday(rhs.getTuesday());
        lhs.setWednesday(rhs.getWednesday());
        lhs.setThursday(rhs.getThursday());
        lhs.setFriday(rhs.getFriday());
        lhs.setSaturday(rhs.getSaturday());
        lhs.setSunday(rhs.getSunday());
        lhs.setPeriod(
                ServiceDateMapper.mapServiceDateInterval(
                        rhs.getStartDate(),
                        rhs.getEndDate()
                )
        );
        return lhs;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy