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