Search in sources :

Example 1 with ServiceDateSummary

use of org.onebusaway.transit_data_federation.model.ServiceDateSummary in project onebusaway-application-modules by camsys.

the class StopScheduleServiceImpl method getServiceDateSummariesForStop.

@Override
public List<ServiceDateSummary> getServiceDateSummariesForStop(AgencyAndId stopId, boolean includePrivateService) {
    StopEntry stop = _transitGraphDao.getStopEntryForId(stopId, true);
    Set<ServiceIdActivation> allServiceIds = getAllServiceIdsForStop(stop, includePrivateService);
    Map<ServiceDate, Set<ServiceIdActivation>> serviceIdsByDate = new FactoryMap<ServiceDate, Set<ServiceIdActivation>>(new HashSet<ServiceIdActivation>());
    for (ServiceIdActivation serviceIds : allServiceIds) {
        Set<ServiceDate> serviceDates = _calendarService.getServiceDatesForServiceIds(serviceIds);
        for (ServiceDate serviceDate : serviceDates) serviceIdsByDate.get(serviceDate).add(serviceIds);
    }
    Map<Set<ServiceIdActivation>, List<ServiceDate>> datesByServiceIds = new FactoryMap<Set<ServiceIdActivation>, List<ServiceDate>>(new ArrayList<ServiceDate>());
    for (Map.Entry<ServiceDate, Set<ServiceIdActivation>> entry : serviceIdsByDate.entrySet()) {
        ServiceDate serviceDate = entry.getKey();
        Set<ServiceIdActivation> serviceIds = entry.getValue();
        datesByServiceIds.get(serviceIds).add(serviceDate);
    }
    List<ServiceDateSummary> summaries = new ArrayList<ServiceDateSummary>();
    for (Map.Entry<Set<ServiceIdActivation>, List<ServiceDate>> entry : datesByServiceIds.entrySet()) {
        Set<ServiceIdActivation> serviceIds = entry.getKey();
        List<ServiceDate> serviceDates = entry.getValue();
        Collections.sort(serviceDates);
        summaries.add(new ServiceDateSummary(serviceIds, serviceDates));
    }
    Collections.sort(summaries);
    return summaries;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) ServiceDateSummary(org.onebusaway.transit_data_federation.model.ServiceDateSummary) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 FactoryMap (org.onebusaway.collections.FactoryMap)1 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)1 ServiceDateSummary (org.onebusaway.transit_data_federation.model.ServiceDateSummary)1 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)1 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)1