All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.graph_builder.module.vehicle.VehicleParkingModule Maven / Gradle / Ivy

package org.opentripplanner.graph_builder.module.vehicle;

import org.opentripplanner.graph_builder.DataImportIssueStore;
import org.opentripplanner.graph_builder.services.GraphBuilderModule;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.vehicle_parking.VehicleParking;
import org.opentripplanner.routing.vehicle_parking.VehicleParkingHelper;
import org.opentripplanner.routing.vehicle_parking.VehicleParkingService;
import org.opentripplanner.updater.DataSource;
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 or car park using the same source as the dynamic
 * vehicle parking updater.
 */
public class VehicleParkingModule implements GraphBuilderModule {

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

    private DataSource dataSource;

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    @Override
    public void buildGraph(
            Graph graph,
            HashMap, Object> extra,
            DataImportIssueStore issueStore
    ) {

        LOG.info("Building vehicle parking from static source...");
        VehicleParkingService service = graph.getService(VehicleParkingService.class, true);
        if (!dataSource.update()) {
            LOG.warn("No vehicle parks found from the data source.");
            return;
        }
        Collection vehicleParks = dataSource.getUpdates();

        for (VehicleParking vehicleParking : vehicleParks) {
            service.addVehicleParking(vehicleParking);
            VehicleParkingHelper.linkVehicleParkingToGraph(graph, vehicleParking);
        }
        LOG.info("Created " + vehicleParks.size() + " vehicle parks.");
    }

    @Override
    public void checkInputs() {
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy