use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.
the class HibernateGtfsRelationalImplBartTest method testCalendarForServiceId.
@Test
public void testCalendarForServiceId() {
ServiceCalendar calendar = _dao.getCalendarForServiceId(new AgencyAndId("BART", "WKDY"));
assertEquals(new ServiceDate(2007, 1, 1), calendar.getStartDate());
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsHibernateReaderExampleMain method main.
public static void main(String[] args) throws IOException {
if (!(args.length == 1 || args.length == 2)) {
System.err.println("usage: gtfsPath [hibernate-config.xml]");
System.exit(-1);
}
String resource = "classpath:org/onebusaway/gtfs/examples/hibernate-configuration-examples.xml";
if (args.length == 2)
resource = args[1];
HibernateGtfsFactory factory = createHibernateGtfsFactory(resource);
GtfsReader reader = new GtfsReader();
reader.setInputLocation(new File(args[0]));
GtfsMutableRelationalDao dao = factory.getDao();
reader.setEntityStore(dao);
reader.run();
Collection<Stop> stops = dao.getAllStops();
for (Stop stop : stops) System.out.println(stop.getName());
CalendarService calendarService = factory.getCalendarService();
Set<AgencyAndId> serviceIds = calendarService.getServiceIds();
for (AgencyAndId serviceId : serviceIds) {
Set<ServiceDate> dates = calendarService.getServiceDatesForServiceId(serviceId);
ServiceDate from = null;
ServiceDate to = null;
for (ServiceDate date : dates) {
from = min(from, date);
to = max(to, date);
}
System.out.println("serviceId=" + serviceId + " from=" + from + " to=" + to);
}
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarServiceDataFactoryImpl method getServiceDatesForServiceId.
public Set<ServiceDate> getServiceDatesForServiceId(AgencyAndId serviceId, TimeZone serviceIdTimeZone) {
Set<ServiceDate> activeDates = new HashSet<ServiceDate>();
ServiceCalendar c = _dao.getCalendarForServiceId(serviceId);
if (c != null) {
addDatesFromCalendar(c, serviceIdTimeZone, activeDates);
}
for (ServiceCalendarDate cd : _dao.getCalendarDatesForServiceId(serviceId)) {
addAndRemoveDatesFromCalendarDate(cd, serviceIdTimeZone, activeDates);
}
return activeDates;
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarServiceDataFactoryImpl method addDatesFromCalendar.
private void addDatesFromCalendar(ServiceCalendar calendar, TimeZone timeZone, Set<ServiceDate> activeDates) {
/**
* We calculate service dates relative to noon so as to avoid any weirdness
* relative to DST.
*/
Date startDate = getServiceDateAsNoon(calendar.getStartDate(), timeZone);
Date endDate = getServiceDateAsNoon(calendar.getEndDate(), timeZone);
java.util.Calendar c = java.util.Calendar.getInstance(timeZone);
c.setTime(startDate);
while (true) {
Date date = c.getTime();
if (date.after(endDate))
break;
int day = c.get(java.util.Calendar.DAY_OF_WEEK);
boolean active = false;
switch(day) {
case java.util.Calendar.MONDAY:
active = calendar.getMonday() == 1;
break;
case java.util.Calendar.TUESDAY:
active = calendar.getTuesday() == 1;
break;
case java.util.Calendar.WEDNESDAY:
active = calendar.getWednesday() == 1;
break;
case java.util.Calendar.THURSDAY:
active = calendar.getThursday() == 1;
break;
case java.util.Calendar.FRIDAY:
active = calendar.getFriday() == 1;
break;
case java.util.Calendar.SATURDAY:
active = calendar.getSaturday() == 1;
break;
case java.util.Calendar.SUNDAY:
active = calendar.getSunday() == 1;
break;
}
if (active) {
addServiceDate(activeDates, new ServiceDate(c), timeZone);
}
c.add(java.util.Calendar.DAY_OF_YEAR, 1);
}
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarServiceDataFactoryImpl method addAndRemoveDatesFromCalendarDate.
private void addAndRemoveDatesFromCalendarDate(ServiceCalendarDate calendarDate, TimeZone serviceIdTimeZone, Set<ServiceDate> activeDates) {
ServiceDate serviceDate = calendarDate.getDate();
Date targetDate = calendarDate.getDate().getAsDate();
Calendar c = Calendar.getInstance();
c.setTime(targetDate);
switch(calendarDate.getExceptionType()) {
case ServiceCalendarDate.EXCEPTION_TYPE_ADD:
addServiceDate(activeDates, serviceDate, serviceIdTimeZone);
break;
case ServiceCalendarDate.EXCEPTION_TYPE_REMOVE:
activeDates.remove(serviceDate);
break;
default:
_log.warn("unknown CalendarDate exception type: " + calendarDate.getExceptionType());
break;
}
}
Aggregations