Search in sources :

Example 6 with FactoryMap

use of org.onebusaway.collections.FactoryMap in project onebusaway-gtfs-modules by OneBusAway.

the class RemoveDuplicateTripsStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    Map<Pattern, List<Trip>> tripsByPattern = new FactoryMap<Pattern, List<Trip>>(new ArrayList<Trip>());
    for (Trip trip : dao.getAllTrips()) {
        Pattern pattern = getPatternForTrip(dao, trip);
        tripsByPattern.get(pattern).add(trip);
    }
    int duplicateTrips = 0;
    for (List<Trip> trips : tripsByPattern.values()) {
        if (trips.size() == 1)
            continue;
        for (int i = 1; i < trips.size(); i++) {
            Trip trip = trips.get(i);
            List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
            for (StopTime stopTime : stopTimes) dao.removeEntity(stopTime);
            dao.removeEntity(trip);
            duplicateTrips++;
        }
    }
    UpdateLibrary.clearDaoCache(dao);
    _log.info("removed " + duplicateTrips + " duplicate trips");
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) Trip(org.onebusaway.gtfs.model.Trip) ArrayList(java.util.ArrayList) List(java.util.List) StopTime(org.onebusaway.gtfs.model.StopTime)

Aggregations

ArrayList (java.util.ArrayList)6 List (java.util.List)6 FactoryMap (org.onebusaway.collections.FactoryMap)6 Trip (org.onebusaway.gtfs.model.Trip)6 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)4 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 StopTime (org.onebusaway.gtfs.model.StopTime)2 Map (java.util.Map)1 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)1 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)1 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)1 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)1