Skip to content

Commit

Permalink
get rid of strange GtfsBundles class
Browse files Browse the repository at this point in the history
  • Loading branch information
abyrd committed Feb 3, 2015
1 parent 8f5fca5 commit 7ecf07b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 76 deletions.

This file was deleted.

Expand Up @@ -25,6 +25,7 @@ the License, or (at your option) any later version.
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;


import com.beust.jcommander.internal.Lists;
import org.onebusaway.csv_entities.EntityHandler; import org.onebusaway.csv_entities.EntityHandler;
import org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl; import org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl;
import org.onebusaway.gtfs.impl.calendar.CalendarServiceDataFactoryImpl; import org.onebusaway.gtfs.impl.calendar.CalendarServiceDataFactoryImpl;
Expand All @@ -44,7 +45,6 @@ the License, or (at your option) any later version.
import org.onebusaway.gtfs.services.GtfsMutableRelationalDao; import org.onebusaway.gtfs.services.GtfsMutableRelationalDao;
import org.opentripplanner.calendar.impl.MultiCalendarServiceImpl; import org.opentripplanner.calendar.impl.MultiCalendarServiceImpl;
import org.opentripplanner.graph_builder.model.GtfsBundle; import org.opentripplanner.graph_builder.model.GtfsBundle;
import org.opentripplanner.graph_builder.model.GtfsBundles;
import org.opentripplanner.graph_builder.services.GraphBuilderModule; import org.opentripplanner.graph_builder.services.GraphBuilderModule;
import org.opentripplanner.gtfs.BikeAccess; import org.opentripplanner.gtfs.BikeAccess;
import org.opentripplanner.gtfs.GtfsContext; import org.opentripplanner.gtfs.GtfsContext;
Expand All @@ -62,8 +62,6 @@ public class GtfsModule implements GraphBuilderModule {


private static final Logger LOG = LoggerFactory.getLogger(GtfsModule.class); private static final Logger LOG = LoggerFactory.getLogger(GtfsModule.class);


private GtfsBundles _gtfsBundles;

EntityHandler counter = new EntityCounter(); EntityHandler counter = new EntityCounter();


private FareServiceFactory _fareServiceFactory; private FareServiceFactory _fareServiceFactory;
Expand All @@ -78,18 +76,9 @@ public class GtfsModule implements GraphBuilderModule {


int nextAgencyId = 1; // used for generating agency IDs to resolve ID conflicts int nextAgencyId = 1; // used for generating agency IDs to resolve ID conflicts


/** public List<GtfsBundle> gtfsBundles;
* Construct and set bundles all at once.
* TODO why is there a wrapper class around a list of GTFS files? public GtfsModule(List<GtfsBundle> bundles) { this.gtfsBundles = bundles; };
* TODO why is there a wrapper around GTFS files at all?
*/
public GtfsModule(List<GtfsBundle> gtfsBundles) {
GtfsBundles gtfsb = new GtfsBundles();
gtfsb.setBundles(gtfsBundles);
this.setGtfsBundles(gtfsb);
}

public GtfsModule() { };


public List<String> provides() { public List<String> provides() {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<String>();
Expand All @@ -101,19 +90,6 @@ public List<String> getPrerequisites() {
return Collections.emptyList(); return Collections.emptyList();
} }


public void setGtfsBundles(GtfsBundles gtfsBundles) {
_gtfsBundles = gtfsBundles;
/* check for dups */
HashSet<String> bundles = new HashSet<String>();
for (GtfsBundle bundle : gtfsBundles.getBundles()) {
String key = bundle.getDataKey();
if (bundles.contains(key)) {
throw new RuntimeException("duplicate GTFS bundle " + key);
}
bundles.add(key);
}
}

public void setFareServiceFactory(FareServiceFactory factory) { public void setFareServiceFactory(FareServiceFactory factory) {
_fareServiceFactory = factory; _fareServiceFactory = factory;
} }
Expand All @@ -131,7 +107,7 @@ public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
GtfsStopContext stopContext = new GtfsStopContext(); GtfsStopContext stopContext = new GtfsStopContext();


try { try {
for (GtfsBundle gtfsBundle : _gtfsBundles.getBundles()) { for (GtfsBundle gtfsBundle : gtfsBundles) {
// apply global defaults to individual GTFSBundles (if globals have been set) // apply global defaults to individual GTFSBundles (if globals have been set)
if (cacheDirectory != null && gtfsBundle.cacheDirectory == null) if (cacheDirectory != null && gtfsBundle.cacheDirectory == null)
gtfsBundle.cacheDirectory = cacheDirectory; gtfsBundle.cacheDirectory = cacheDirectory;
Expand Down Expand Up @@ -371,7 +347,7 @@ public void handleEntity(Object bean) {


@Override @Override
public void checkInputs() { public void checkInputs() {
for (GtfsBundle bundle : _gtfsBundles.getBundles()) { for (GtfsBundle bundle : gtfsBundles) {
bundle.checkInputs(); bundle.checkInputs();
} }
} }
Expand Down
Expand Up @@ -53,7 +53,6 @@ the License, or (at your option) any later version.
import org.opentripplanner.graph_builder.module.shapefile.ShapefileStreetModule; import org.opentripplanner.graph_builder.module.shapefile.ShapefileStreetModule;
import org.opentripplanner.graph_builder.module.shapefile.ShapefileStreetSchema; import org.opentripplanner.graph_builder.module.shapefile.ShapefileStreetSchema;
import org.opentripplanner.graph_builder.model.GtfsBundle; import org.opentripplanner.graph_builder.model.GtfsBundle;
import org.opentripplanner.graph_builder.model.GtfsBundles;
import org.opentripplanner.graph_builder.services.shapefile.FeatureSourceFactory; import org.opentripplanner.graph_builder.services.shapefile.FeatureSourceFactory;
import org.opentripplanner.routing.alertpatch.AlertPatch; import org.opentripplanner.routing.alertpatch.AlertPatch;
import org.opentripplanner.routing.bike_rental.BikeRentalStation; import org.opentripplanner.routing.bike_rental.BikeRentalStation;
Expand Down Expand Up @@ -170,15 +169,12 @@ public Context() {
} }


private void initTransit() { private void initTransit() {
GtfsModule gtfsBuilder = new GtfsModule();
GtfsBundle bundle = new GtfsBundle(); GtfsBundle bundle = new GtfsBundle();
bundle.setPath(new File("src/test/resources/google_transit.zip")); bundle.setPath(new File("src/test/resources/google_transit.zip"));


ArrayList<GtfsBundle> bundleList = new ArrayList<GtfsBundle>(); ArrayList<GtfsBundle> bundleList = new ArrayList<GtfsBundle>();
bundleList.add(bundle); bundleList.add(bundle);
GtfsBundles bundles = new GtfsBundles(); GtfsModule gtfsBuilder = new GtfsModule(bundleList);
bundles.setBundles(bundleList);
gtfsBuilder.setGtfsBundles(bundles);


HashMap<Class<?>, Object> extra = new HashMap<Class<?>, Object>(); HashMap<Class<?>, Object> extra = new HashMap<Class<?>, Object>();
gtfsBuilder.buildGraph(graph, extra); gtfsBuilder.buildGraph(graph, extra);
Expand Down
Expand Up @@ -20,13 +20,13 @@ the License, or (at your option) any later version.
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;


import com.beust.jcommander.internal.Lists;
import org.junit.Test; import org.junit.Test;
import org.onebusaway.gtfs.model.AgencyAndId; import org.onebusaway.gtfs.model.AgencyAndId;
import org.onebusaway.gtfs.model.IdentityBean; import org.onebusaway.gtfs.model.IdentityBean;
import org.onebusaway.gtfs.model.Trip; import org.onebusaway.gtfs.model.Trip;
import org.onebusaway.gtfs.services.MockGtfs; import org.onebusaway.gtfs.services.MockGtfs;
import org.opentripplanner.graph_builder.model.GtfsBundle; import org.opentripplanner.graph_builder.model.GtfsBundle;
import org.opentripplanner.graph_builder.model.GtfsBundles;
import org.opentripplanner.gtfs.BikeAccess; import org.opentripplanner.gtfs.BikeAccess;
import org.opentripplanner.routing.edgetype.TripPattern; import org.opentripplanner.routing.edgetype.TripPattern;
import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.routing.graph.Graph;
Expand All @@ -36,7 +36,7 @@ public class GtfsGraphBuilderModuleTest {


private static final HashMap<Class<?>, Object> _extra = new HashMap<Class<?>, Object>(); private static final HashMap<Class<?>, Object> _extra = new HashMap<Class<?>, Object>();


private GtfsModule _builder = new GtfsModule(); private GtfsModule _builder;


@Test @Test
public void testNoBikesByDefault() throws IOException { public void testNoBikesByDefault() throws IOException {
Expand All @@ -46,9 +46,9 @@ public void testNoBikesByDefault() throws IOException {
gtfs.putTrips(2, "r0", "sid0", "bikes_allowed=0,1"); gtfs.putTrips(2, "r0", "sid0", "bikes_allowed=0,1");
gtfs.putStopTimes("t0,t1", "s0,s1"); gtfs.putStopTimes("t0,t1", "s0,s1");


GtfsBundles bundles = getGtfsAsBundles(gtfs); List<GtfsBundle> bundleList = getGtfsAsBundleList(gtfs);
bundles.getBundles().get(0).setDefaultBikesAllowed(false); bundleList.get(0).setDefaultBikesAllowed(false);
_builder.setGtfsBundles(bundles); _builder = new GtfsModule(bundleList);


Graph graph = new Graph(); Graph graph = new Graph();
_builder.buildGraph(graph, _extra); _builder.buildGraph(graph, _extra);
Expand All @@ -71,9 +71,9 @@ public void testBikesByDefault() throws IOException {
gtfs.putTrips(2, "r0", "sid0", "bikes_allowed=0,2"); gtfs.putTrips(2, "r0", "sid0", "bikes_allowed=0,2");
gtfs.putStopTimes("t0,t1", "s0,s1"); gtfs.putStopTimes("t0,t1", "s0,s1");


GtfsBundles bundles = getGtfsAsBundles(gtfs); List<GtfsBundle> bundleList = getGtfsAsBundleList(gtfs);
bundles.getBundles().get(0).setDefaultBikesAllowed(true); bundleList.get(0).setDefaultBikesAllowed(true);
_builder.setGtfsBundles(bundles); _builder = new GtfsModule(bundleList);


Graph graph = new Graph(); Graph graph = new Graph();
_builder.buildGraph(graph, _extra); _builder.buildGraph(graph, _extra);
Expand All @@ -99,12 +99,12 @@ private MockGtfs getSimpleGtfs() throws IOException {
return gtfs; return gtfs;
} }


private static GtfsBundles getGtfsAsBundles(MockGtfs gtfs) { private static List<GtfsBundle> getGtfsAsBundleList (MockGtfs gtfs) {
GtfsBundle bundle = new GtfsBundle(); GtfsBundle bundle = new GtfsBundle();
bundle.setPath(gtfs.getPath()); bundle.setPath(gtfs.getPath());
GtfsBundles bundles = new GtfsBundles(); List<GtfsBundle> list = Lists.newArrayList();
bundles.getBundles().add(bundle); list.add(bundle);
return bundles; return list;
} }


private static <S extends Serializable, T extends IdentityBean<S>> T withId(Iterable<T> beans, private static <S extends Serializable, T extends IdentityBean<S>> T withId(Iterable<T> beans,
Expand Down

0 comments on commit 7ecf07b

Please sign in to comment.