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;
}
Aggregations