Class CalendarServiceImpl

java.lang.Object
org.onebusaway.gtfs.impl.calendar.CalendarServiceImpl
All Implemented Interfaces:
CalendarService

public class CalendarServiceImpl extends Object implements CalendarService
An implementation of CalendarService. Requires a pre-computed CalendarServiceData bundle for efficient operation.
Author:
bdferris
  • Constructor Details

  • Method Details

    • setDataFactory

      public void setDataFactory(CalendarServiceDataFactory factory)
    • setData

      public void setData(CalendarServiceData data)
      Description copied from interface: CalendarService
      Update the underlying data structures.
      Specified by:
      setData in interface CalendarService
      Parameters:
      data -
    • getServiceIds

      public Set<AgencyAndId> getServiceIds()
      CalendarService Interface
      Specified by:
      getServiceIds in interface CalendarService
      Returns:
      the set of all service ids used in the data set
    • getServiceDatesForServiceId

      public Set<ServiceDate> getServiceDatesForServiceId(AgencyAndId serviceId)
      Specified by:
      getServiceDatesForServiceId in interface CalendarService
      Parameters:
      serviceId - the target service id
      Returns:
      the set of all service dates for which the specified service id is active
    • getServiceIdsOnDate

      public Set<AgencyAndId> getServiceIdsOnDate(ServiceDate date)
      Description copied from interface: CalendarService
      Determine the set of service ids that are active on the specified service date.
      Specified by:
      getServiceIdsOnDate in interface CalendarService
      Parameters:
      date - the target service date
      Returns:
      the set of service ids that are active on the specified service date
    • getTimeZoneForAgencyId

      public TimeZone getTimeZoneForAgencyId(String agencyId)
      Description copied from interface: CalendarService
      Returns the instantiated TimeZone for the specified agency id
      Specified by:
      getTimeZoneForAgencyId in interface CalendarService
      Parameters:
      agencyId - Agency.getId()
      Returns:
      the time zone for the specified agency, or null if the agency was not found
    • getLocalizedServiceIdForAgencyAndServiceId

      public LocalizedServiceId getLocalizedServiceIdForAgencyAndServiceId(String agencyId, AgencyAndId serviceId)
      Description copied from interface: CalendarService
      Given an agency id and a service id, we return a LocalizedServiceId which is just a service id with timezone information attached. We use the agencyId argument of the method call to lookup the timezone for requested agency. Note that the service id itself has an agencyId component as well, but we don't use that for the timezone lookup. The service id's agencyId is more of a prefix to guarantee dataset uniqueness. For example, multiple Trip objects, representing different agencies, can all reference the same service id. Its important that we look up agency timezone information using the trip's agencyId and not the serviceId's agencyId.
      Specified by:
      getLocalizedServiceIdForAgencyAndServiceId in interface CalendarService
      Parameters:
      agencyId - the id of the Agency whose timezone info we will use
      serviceId - the service id to use
      Returns:
      a localized service id with timezone info attached, or nul if the specified agency could not be found
    • getDatesForLocalizedServiceId

      public List<Date> getDatesForLocalizedServiceId(LocalizedServiceId localizedServiceId)
      Specified by:
      getDatesForLocalizedServiceId in interface CalendarService
    • isLocalizedServiceIdActiveOnDate

      public boolean isLocalizedServiceIdActiveOnDate(LocalizedServiceId localizedServiceId, Date serviceDate)
      Specified by:
      isLocalizedServiceIdActiveOnDate in interface CalendarService
    • isLocalizedServiceIdActiveInRange

      public boolean isLocalizedServiceIdActiveInRange(LocalizedServiceId localizedServiceId, ServiceInterval activeService, AgencyServiceInterval agencyServiceInterval)
      test if the given calendar servieId is active in the union of the activeService window and the agencyServiceInterval.
      Specified by:
      isLocalizedServiceIdActiveInRange in interface CalendarService
      Parameters:
      localizedServiceId -
      activeService -
      agencyServiceInterval -
      Returns:
    • getServiceDateArrivalsWithinRange

      public List<Date> getServiceDateArrivalsWithinRange(LocalizedServiceId serviceId, ServiceInterval interval, Date from, Date to)
      Description copied from interface: CalendarService
      See the description from CalendarService.getServiceDatesWithinRange(LocalizedServiceId, ServiceInterval, Date, Date) . This method does the same thing, except that it only considers arrival times.
      Specified by:
      getServiceDateArrivalsWithinRange in interface CalendarService
      Parameters:
      serviceId - the localized service id whose service dates we'll consider
      interval - a range of arrival times to consider
      from - - the min portion of the target time interval
      to - - the max portion of the target time interval
      Returns:
      the list of active service dates
    • getServiceDateArrivalsWithinRange

      public Map<LocalizedServiceId,List<Date>> getServiceDateArrivalsWithinRange(ServiceIdIntervals serviceIdIntervals, Date from, Date to)
      Description copied from interface: CalendarService
      See the description from CalendarService.getServiceDateArrivalsWithinRange(LocalizedServiceId, ServiceInterval, Date, Date) . This method does the same thing, except that it works with multiple service ids and intervals at the same time.
      Specified by:
      getServiceDateArrivalsWithinRange in interface CalendarService
      Parameters:
      serviceIdIntervals - - a set of service ids and service intervals
      from - - time interval min
      to - - time interval max
      Returns:
      the list of active service dates, keyed by service id
    • getServiceDateDeparturesWithinRange

      public List<Date> getServiceDateDeparturesWithinRange(LocalizedServiceId serviceId, ServiceInterval interval, Date from, Date to)
      Description copied from interface: CalendarService
      See the description from CalendarService.getServiceDatesWithinRange(LocalizedServiceId, ServiceInterval, Date, Date) . This method does the same thing, except that it only considers departure times.
      Specified by:
      getServiceDateDeparturesWithinRange in interface CalendarService
      Parameters:
      serviceId - the localized service id whose service dates we'll consider
      interval - a range of departure times to consider
      from - - the min portion of the target time interval
      to - - the max portion of the target time interval
      Returns:
      the list of active service dates
    • getServiceDateDeparturesWithinRange

      public Map<LocalizedServiceId,List<Date>> getServiceDateDeparturesWithinRange(ServiceIdIntervals serviceIdIntervals, Date from, Date to)
      Description copied from interface: CalendarService
      See the description from CalendarService.getServiceDateDeparturesWithinRange(LocalizedServiceId, ServiceInterval, Date, Date) . This method does the same thing, except that it works with multiple service ids and intervals at the same time.
      Specified by:
      getServiceDateDeparturesWithinRange in interface CalendarService
      Parameters:
      serviceIdIntervals - - a set of service ids and service intervals
      from - - time interval min
      to - - time interval max
      Returns:
      the list of active service dates, keyed by service id
    • getServiceDatesWithinRange

      public List<Date> getServiceDatesWithinRange(LocalizedServiceId serviceId, ServiceInterval interval, Date from, Date to)
      Description copied from interface: CalendarService
      Given the specified localized service id, which has a corresponding set of localized service dates, determine the sublist of service dates that, when extended with the specified ServiceInterval, overlap with the specified from-to time range. Let's consider a few concrete examples to describe what this method does. Consider a single StopTime with an arrival and departure time. That StopTime is part of a Trip, which means it has a service id attached to it. We wish to answer the question, What service dates would make the specified StopTime active in a particular time range? To answer that question, we'd need to consider each of the localized service dates for which the specified service id is active, add the StopTime arrival and departure offset to each, and see if the resulting time falls within the target range. This method can perform that comparison. By specifying the target service id, a ServiceInterval whose min and max arrival and departure times are set to the arrival and departure time of the StopTime, and the target from-to time interval, the method will return the set of localized service dates that would make the StopTime arrival or departure times active in the specified target time range. As slightly different example, consider answering that same question for multiple StopTime objects, such as all the StopTimes for a particular trip or all the StopTimes for a particular stop. The question is the same, but the difference is now there are multiple arrival and departure times. Here, an appropriate ServiceInterval can be constructed that includes the min and max arrival and departure times for the set of StopTime objects and the calculation will be done looking for service dates that cause any part of the service interval to overlap with the target from-to range. Note that this method considers both the arrival and departure times when looking for overlaps. To consider only arrival times, check out CalendarService.getServiceDateArrivalsWithinRange(LocalizedServiceId, ServiceInterval, Date, Date) and for departures, check out CalendarService.getServiceDateDeparturesWithinRange(LocalizedServiceId, ServiceInterval, Date, Date)
      Specified by:
      getServiceDatesWithinRange in interface CalendarService
      Parameters:
      serviceId - the localized service id whose service dates we'll consider
      interval - a range of arrival and departure times to consider
      from - - the min portion of the target time interval
      to - - the max portion of the target time interval
      Returns:
      the list of localized service dates that would make the specified service interval overlap with the specified from-to time range
    • getServiceDatesWithinRange

      public Map<LocalizedServiceId,List<Date>> getServiceDatesWithinRange(ServiceIdIntervals serviceIdIntervals, Date from, Date to)
      Description copied from interface: CalendarService
      See the description from CalendarService.getServiceDatesWithinRange(LocalizedServiceId, ServiceInterval, Date, Date) . This method does the same thing, except that it works with multiple service ids and intervals at the same time.
      Specified by:
      getServiceDatesWithinRange in interface CalendarService
      Parameters:
      serviceIdIntervals - - a set of service ids and service intervals
      from - - time interval min
      to - - time interval max
      Returns:
      the list of active service dates, keyed by service id
    • getNextDepartureServiceDates

      public List<Date> getNextDepartureServiceDates(LocalizedServiceId serviceId, ServiceInterval interval, long targetTime)
      Description copied from interface: CalendarService
      Computes the list of service dates whose departure service interval (min to max departure time) overlaps the specified target time. If no intervals overlaps, then the next service date whose full service interval comes immediately after (but does overlap) the target time is returned. This method is useful for finding the next scheduled StopTime after the target time at a particular stop . By calling this method with the serviceId and service interval for the specified stop, we return the set of service dates that overlap or the next service date if none do, guaranteeing that at least one service date instantiates a StopTime that occurs after the target time.
      Specified by:
      getNextDepartureServiceDates in interface CalendarService
      Parameters:
      serviceId - the localized service id whose service dates we'll consider
      interval - a range of departure times to consider
      targetTime - - time in UTC
      Returns:
      the set of overlapping and next service dates
    • getNextDepartureServiceDates

      public Map<LocalizedServiceId,List<Date>> getNextDepartureServiceDates(ServiceIdIntervals serviceIdIntervals, long targetTime)
      Description copied from interface: CalendarService
      See the description for CalendarService.getNextDepartureServiceDates(LocalizedServiceId, ServiceInterval, long) . This method does the same thing, except that it works with multiple service ids and intervals at the same time.
      Specified by:
      getNextDepartureServiceDates in interface CalendarService
      Parameters:
      serviceIdIntervals - - set of service ids and service intervals
      targetTime -
      Returns:
      the set of overlapping and next service dates
    • getPreviousArrivalServiceDates

      public List<Date> getPreviousArrivalServiceDates(LocalizedServiceId serviceId, ServiceInterval interval, long targetTime)
      Description copied from interface: CalendarService
      Computes the list of service dates whose arrival service interval (min to max departure time) overlaps the specified target time. If not intervals overlap, then the previous service date whose full service interval comes immediately before (but does overlap) the target time is returned. This method is useful for finding the previous scheduled StopTime before the target time at a particular stop . By calling this method with the serviceId and service interval for the specified stop, we return the set of service dates that potentially overlap or the previous service date if none do, guaranteeing that at least one service date instantiates a StopTime that occurs before the target time.
      Specified by:
      getPreviousArrivalServiceDates in interface CalendarService
      Parameters:
      serviceId - the localized service id whose service dates we'll consider
      interval - a range of arrival times to consider
      targetTime - - time in UTC
      Returns:
      the set of overlapping and previous service dates
    • getPreviousArrivalServiceDates

      public Map<LocalizedServiceId,List<Date>> getPreviousArrivalServiceDates(ServiceIdIntervals serviceIdIntervals, long targetTime)
      Description copied from interface: CalendarService
      See the description for CalendarService.getPreviousArrivalServiceDates(LocalizedServiceId, ServiceInterval, long) . This method does the same thing, except that it works with multiple service ids and intervals at the same time.
      Specified by:
      getPreviousArrivalServiceDates in interface CalendarService
      Parameters:
      serviceIdIntervals - - set of service ids and service intervals
      targetTime -
      Returns:
      the set of overlapping and previous service dates
    • getData

      protected CalendarServiceData getData()
      Private Methods