use of org.onebusaway.gtfs_merge.strategies.EntityMergeStrategy in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsMerger method run.
public void run(List<File> inputPaths, File outputPath) throws IOException {
GtfsRelationalDaoImpl mergedDao = new GtfsRelationalDaoImpl();
mergedDao.setPackShapePoints(true);
mergedDao.setPackStopTimes(true);
List<EntityMergeStrategy> strategies = new ArrayList<EntityMergeStrategy>();
buildStrategies(strategies);
/**
* For each entity merge strategy, we keep track of a mapping from raw GTFS
* ids to entities, if the particular entity type has an identifier. This
* will be used to detect id conflicts between subsequent runs of each merge
* strategy on different feeds. We can't use the AgencyAndId ids in the DAO
* because it might be possible for two entities with the same id but
* different agency prefixes to sneak in. Since we ultimately serialize the
* data to a GTFS feed with no agency prefixes, we need to track the raw id.
*/
Map<EntityMergeStrategy, Map<String, Object>> rawEntityIdMapsByMergeStrategy = new HashMap<EntityMergeStrategy, Map<String, Object>>();
for (EntityMergeStrategy strategy : strategies) {
rawEntityIdMapsByMergeStrategy.put(strategy, new HashMap<String, Object>());
}
/**
* We iterate over the input feeds in reverse order, such that entities from
* the newest feeds are added first and older entities are potentially
* dropped.
*/
for (int index = inputPaths.size() - 1; index >= 0; --index) {
File inputPath = inputPaths.get(index);
String prefix = getIndexAsPrefix(index, inputPaths.size());
_log.info("reading input: " + inputPath);
GtfsReader reader = new GtfsReader();
reader.setInputLocation(inputPath);
GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
dao.setPackShapePoints(true);
dao.setPackStopTimes(true);
reader.setEntityStore(dao);
reader.run();
for (EntityMergeStrategy strategy : strategies) {
_log.info("strategy=" + strategy.getClass());
GtfsMergeContext context = new GtfsMergeContext(dao, mergedDao, prefix, rawEntityIdMapsByMergeStrategy.get(strategy));
strategy.merge(context);
}
}
_log.info("writing merged output: " + outputPath);
GtfsWriter writer = new GtfsWriter();
writer.setOutputLocation(outputPath);
writer.run(mergedDao);
}
use of org.onebusaway.gtfs_merge.strategies.EntityMergeStrategy in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsMerger method getEntityMergeStrategyForEntityType.
public EntityMergeStrategy getEntityMergeStrategyForEntityType(Class<?> entityType) {
List<EntityMergeStrategy> strategies = new ArrayList<EntityMergeStrategy>();
buildStrategies(strategies);
for (EntityMergeStrategy strategy : strategies) {
Set<Class<?>> entityTypes = new HashSet<Class<?>>();
strategy.getEntityTypes(entityTypes);
if (entityTypes.contains(entityType)) {
return strategy;
}
}
return null;
}
Aggregations