use of org.onebusaway.collections.Counter in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarSimplicationLibrary method getSummaryForServiceDates.
public ServiceCalendarSummary getSummaryForServiceDates(Set<ServiceDate> allServiceDates) {
ServiceCalendarSummary summary = new ServiceCalendarSummary();
summary.allServiceDates = allServiceDates;
summary.serviceDatesInOrder = new ArrayList<ServiceDate>(summary.allServiceDates);
Collections.sort(summary.serviceDatesInOrder);
if (summary.serviceDatesInOrder.isEmpty()) {
return summary;
}
Calendar c = Calendar.getInstance();
Counter<Integer> daysOfTheWeekCounts = new Counter<Integer>();
for (ServiceDate serviceDate : summary.serviceDatesInOrder) {
c.setTime(serviceDate.getAsDate());
// Move the service date to "noon" to avoid problems with DST and the
// day-of-the-week calculation.
c.add(Calendar.HOUR_OF_DAY, 12);
int dayOfTheWeek = c.get(Calendar.DAY_OF_WEEK);
daysOfTheWeekCounts.increment(dayOfTheWeek);
summary.mostRecentServiceDateByDayOfWeek.put(dayOfTheWeek, serviceDate);
}
Integer maxKey = daysOfTheWeekCounts.getMax();
summary.maxDayOfWeekCount = daysOfTheWeekCounts.getCount(maxKey);
for (Integer dayOfTheWeek : daysOfTheWeekCounts.getKeys()) {
int count = daysOfTheWeekCounts.getCount(dayOfTheWeek);
if (count < summary.maxDayOfWeekCount * _dayOfTheWeekInclusionRatio)
continue;
summary.daysOfTheWeekToUse.add(dayOfTheWeek);
}
return summary;
}
Aggregations