org.opentripplanner.graph_builder.module.bike.BikeRentalModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
package org.opentripplanner.graph_builder.module.bike;
import org.opentripplanner.graph_builder.DataImportIssueStore;
import org.opentripplanner.graph_builder.services.GraphBuilderModule;
import org.opentripplanner.routing.bike_rental.BikeRentalStation;
import org.opentripplanner.routing.bike_rental.BikeRentalStationService;
import org.opentripplanner.routing.edgetype.RentABikeOffEdge;
import org.opentripplanner.routing.edgetype.RentABikeOnEdge;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.vertextype.BikeRentalStationVertex;
import org.opentripplanner.updater.bike_rental.BikeRentalDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.HashMap;
/**
* This graph builder allow one to statically build bike rental stations using the same source as
* the dynamic bike rental updater. This may help when the source does not contain real-time info
* (or one is not interested in), location of stations do not change that often, or development.
*/
public class BikeRentalModule implements GraphBuilderModule {
private static Logger LOG = LoggerFactory.getLogger(BikeRentalModule.class);
private BikeRentalDataSource dataSource;
public void setDataSource(BikeRentalDataSource dataSource) {
this.dataSource = dataSource;
}
@Override
public void buildGraph(
Graph graph,
HashMap, Object> extra,
DataImportIssueStore issueStore
) {
LOG.info("Building bike rental stations from static source...");
BikeRentalStationService service = graph.getService(BikeRentalStationService.class, true);
if (!dataSource.update()) {
LOG.warn("No bike rental found from the data source.");
return;
}
Collection stations = dataSource.getStations();
for (BikeRentalStation station : stations) {
service.addBikeRentalStation(station);
BikeRentalStationVertex vertex = new BikeRentalStationVertex(graph, station);
new RentABikeOnEdge(vertex, vertex, station.networks);
if (station.allowDropoff)
new RentABikeOffEdge(vertex, vertex, station.networks);
}
LOG.info("Created " + stations.size() + " bike rental stations.");
}
@Override
public void checkInputs() {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy