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.6.0
Show newest version
package org.opentripplanner.gtfs.mapping;

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

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.opentripplanner.model.calendar.ServiceCalendar;
import org.opentripplanner.util.MapUtils;

/** Responsible for mapping GTFS ServiceCalendar into the OTP model. */
class ServiceCalendarMapper {

  private final 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 - 2025 Weber Informatics LLC | Privacy Policy