use of org.onebusaway.transit_data.model.StopCalendarDaysBean in project onebusaway-application-modules by camsys.
the class ScheduleAction method execute.
@Override
@Actions({ @Action(value = "/where/schedule") })
public String execute() throws Exception {
if (_date == null)
_date = new Date();
if (_id == null)
return INPUT;
_result = _service.getScheduleForStop(_id, _date);
if (_result == null)
throw new NoSuchStopServiceException(_id);
StopCalendarDaysBean days = _result.getCalendarDays();
String tzName = days.getTimeZone();
_timeZone = TimeZone.getTimeZone(tzName);
if (_timeZone == null)
_timeZone = TimeZone.getDefault();
filterResults();
return SUCCESS;
}
use of org.onebusaway.transit_data.model.StopCalendarDaysBean in project onebusaway-application-modules by camsys.
the class StopScheduleBeanServiceImpl method getCalendarForStop.
@Cacheable
public StopCalendarDaysBean getCalendarForStop(AgencyAndId stopId) {
TimeZone timeZone = _agencyService.getTimeZoneForAgencyId(stopId.getAgencyId());
StopEntry stopEntry = _graph.getStopEntryForId(stopId);
Set<ServiceIdActivation> serviceIds = new HashSet<ServiceIdActivation>();
for (BlockStopTimeIndex index : _blockIndexService.getStopTimeIndicesForStop(stopEntry)) serviceIds.add(index.getServiceIds());
for (FrequencyBlockStopTimeIndex index : _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry)) serviceIds.add(index.getServiceIds());
SortedMap<ServiceDate, Set<ServiceIdActivation>> serviceIdsByDate = getServiceIdsByDate(serviceIds);
Counter<Set<ServiceIdActivation>> counts = new Counter<Set<ServiceIdActivation>>();
for (Set<ServiceIdActivation> ids : serviceIdsByDate.values()) counts.increment(ids);
int total = counts.size();
Map<Set<ServiceIdActivation>, Integer> idsToGroup = new HashMap<Set<ServiceIdActivation>, Integer>();
for (Set<ServiceIdActivation> ids : counts.getSortedKeys()) idsToGroup.put(ids, total--);
List<StopCalendarDayBean> beans = new ArrayList<StopCalendarDayBean>(serviceIdsByDate.size());
for (Map.Entry<ServiceDate, Set<ServiceIdActivation>> entry : serviceIdsByDate.entrySet()) {
StopCalendarDayBean bean = new StopCalendarDayBean();
ServiceDate serviceDate = entry.getKey();
Date date = serviceDate.getAsDate(timeZone);
bean.setDate(date);
Integer indexId = idsToGroup.get(entry.getValue());
bean.setGroup(indexId);
beans.add(bean);
}
return new StopCalendarDaysBean(timeZone.getID(), beans);
}
Aggregations