public class CalendarServiceImpl extends Object implements CalendarService
CalendarService. Requires a pre-computed
CalendarServiceData bundle for efficient operation.| Constructor and Description |
|---|
CalendarServiceImpl() |
CalendarServiceImpl(CalendarServiceData data) |
CalendarServiceImpl(CalendarServiceDataFactory factory) |
public CalendarServiceImpl()
public CalendarServiceImpl(CalendarServiceDataFactory factory)
public CalendarServiceImpl(CalendarServiceData data)
public void setDataFactory(CalendarServiceDataFactory factory)
public void setData(CalendarServiceData data)
public Set<AgencyAndId> getServiceIds()
CalendarService InterfacegetServiceIds in interface CalendarServicepublic Set<ServiceDate> getServiceDatesForServiceId(AgencyAndId serviceId)
getServiceDatesForServiceId in interface CalendarServiceserviceId - the target service idpublic Set<AgencyAndId> getServiceIdsOnDate(ServiceDate date)
CalendarServicegetServiceIdsOnDate in interface CalendarServicedate - the target service datepublic TimeZone getTimeZoneForAgencyId(String agencyId)
CalendarServiceTimeZone for the specified agency idgetTimeZoneForAgencyId in interface CalendarServiceagencyId - Agency.getId()public LocalizedServiceId getLocalizedServiceIdForAgencyAndServiceId(String agencyId, AgencyAndId serviceId)
CalendarServiceLocalizedServiceId
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.getLocalizedServiceIdForAgencyAndServiceId in interface CalendarServiceagencyId - the id of the Agency whose timezone info we will useserviceId - the service id to usepublic List<Date> getDatesForLocalizedServiceId(LocalizedServiceId localizedServiceId)
getDatesForLocalizedServiceId in interface CalendarServicepublic boolean isLocalizedServiceIdActiveOnDate(LocalizedServiceId localizedServiceId, Date serviceDate)
isLocalizedServiceIdActiveOnDate in interface CalendarServicepublic List<Date> getServiceDateArrivalsWithinRange(LocalizedServiceId serviceId, ServiceInterval interval, Date from, Date to)
CalendarServiceCalendarService.getServiceDatesWithinRange(LocalizedServiceId, ServiceInterval, Date, Date)
. This method does the same thing, except that it only considers arrival
times.getServiceDateArrivalsWithinRange in interface CalendarServiceserviceId - the localized service id whose service dates we'll
considerinterval - a range of arrival times to considerfrom - - the min portion of the target time intervalto - - the max portion of the target time intervalpublic Map<LocalizedServiceId,List<Date>> getServiceDateArrivalsWithinRange(ServiceIdIntervals serviceIdIntervals, Date from, Date to)
CalendarServiceCalendarService.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.getServiceDateArrivalsWithinRange in interface CalendarServiceserviceIdIntervals - - a set of service ids and service intervalsfrom - - time interval minto - - time interval maxpublic List<Date> getServiceDateDeparturesWithinRange(LocalizedServiceId serviceId, ServiceInterval interval, Date from, Date to)
CalendarServiceCalendarService.getServiceDatesWithinRange(LocalizedServiceId, ServiceInterval, Date, Date)
. This method does the same thing, except that it only considers departure
times.getServiceDateDeparturesWithinRange in interface CalendarServiceserviceId - the localized service id whose service dates we'll
considerinterval - a range of departure times to considerfrom - - the min portion of the target time intervalto - - the max portion of the target time intervalpublic Map<LocalizedServiceId,List<Date>> getServiceDateDeparturesWithinRange(ServiceIdIntervals serviceIdIntervals, Date from, Date to)
CalendarServiceCalendarService.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.getServiceDateDeparturesWithinRange in interface CalendarServiceserviceIdIntervals - - a set of service ids and service intervalsfrom - - time interval minto - - time interval maxpublic List<Date> getServiceDatesWithinRange(LocalizedServiceId serviceId, ServiceInterval interval, Date from, Date to)
CalendarServiceServiceInterval, 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)getServiceDatesWithinRange in interface CalendarServiceserviceId - the localized service id whose service dates we'll
considerinterval - a range of arrival and departure times to considerfrom - - the min portion of the target time intervalto - - the max portion of the target time intervalpublic Map<LocalizedServiceId,List<Date>> getServiceDatesWithinRange(ServiceIdIntervals serviceIdIntervals, Date from, Date to)
CalendarServiceCalendarService.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.getServiceDatesWithinRange in interface CalendarServiceserviceIdIntervals - - a set of service ids and service intervalsfrom - - time interval minto - - time interval maxpublic List<Date> getNextDepartureServiceDates(LocalizedServiceId serviceId, ServiceInterval interval, long targetTime)
CalendarServiceStopTime 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.getNextDepartureServiceDates in interface CalendarServiceserviceId - the localized service id whose service dates we'll
considerinterval - a range of departure times to considertargetTime - - time in UTCpublic Map<LocalizedServiceId,List<Date>> getNextDepartureServiceDates(ServiceIdIntervals serviceIdIntervals, long targetTime)
CalendarServiceCalendarService.getNextDepartureServiceDates(LocalizedServiceId, ServiceInterval, long)
. This method does the same thing, except that it works with multiple
service ids and intervals at the same time.getNextDepartureServiceDates in interface CalendarServiceserviceIdIntervals - - set of service ids and service intervalspublic List<Date> getPreviousArrivalServiceDates(LocalizedServiceId serviceId, ServiceInterval interval, long targetTime)
CalendarServiceStopTime
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.getPreviousArrivalServiceDates in interface CalendarServiceserviceId - the localized service id whose service dates we'll
considerinterval - a range of arrival times to considertargetTime - - time in UTCpublic Map<LocalizedServiceId,List<Date>> getPreviousArrivalServiceDates(ServiceIdIntervals serviceIdIntervals, long targetTime)
CalendarServiceCalendarService.getPreviousArrivalServiceDates(LocalizedServiceId, ServiceInterval, long)
. This method does the same thing, except that it works with multiple
service ids and intervals at the same time.getPreviousArrivalServiceDates in interface CalendarServiceserviceIdIntervals - - set of service ids and service intervalsprotected CalendarServiceData getData()
Copyright © 2013 OneBusAway. All Rights Reserved.