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

org.opentripplanner.routing.vehicle_rental.VehicleRentalStationService Maven / Gradle / Ivy

There is a newer version: 2.6.0
Show newest version
package org.opentripplanner.routing.vehicle_rental;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Envelope;
import org.opentripplanner.transit.model.framework.FeedScopedId;

public class VehicleRentalStationService implements Serializable {

  private final Map vehicleRentalStations = new HashMap<>();

  public Collection getVehicleRentalPlaces() {
    return vehicleRentalStations.values();
  }

  public VehicleRentalPlace getVehicleRentalPlace(FeedScopedId id) {
    return vehicleRentalStations.get(id);
  }

  public List getVehicleRentalVehicles() {
    return vehicleRentalStations
      .values()
      .stream()
      .filter(vehicleRentalPlace -> vehicleRentalPlace instanceof VehicleRentalVehicle)
      .map(VehicleRentalVehicle.class::cast)
      .collect(Collectors.toList());
  }

  public VehicleRentalVehicle getVehicleRentalVehicle(FeedScopedId id) {
    VehicleRentalPlace vehicleRentalPlace = vehicleRentalStations.get(id);
    return vehicleRentalPlace instanceof VehicleRentalVehicle
      ? (VehicleRentalVehicle) vehicleRentalPlace
      : null;
  }

  public List getVehicleRentalStations() {
    return vehicleRentalStations
      .values()
      .stream()
      .filter(vehicleRentalPlace -> vehicleRentalPlace instanceof VehicleRentalStation)
      .map(VehicleRentalStation.class::cast)
      .collect(Collectors.toList());
  }

  public VehicleRentalStation getVehicleRentalStation(FeedScopedId id) {
    VehicleRentalPlace vehicleRentalPlace = vehicleRentalStations.get(id);
    return vehicleRentalPlace instanceof VehicleRentalStation
      ? (VehicleRentalStation) vehicleRentalPlace
      : null;
  }

  public void addVehicleRentalStation(VehicleRentalPlace vehicleRentalStation) {
    // Remove old reference first, as adding will be a no-op if already present
    vehicleRentalStations.remove(vehicleRentalStation.getId());
    vehicleRentalStations.put(vehicleRentalStation.getId(), vehicleRentalStation);
  }

  public void removeVehicleRentalStation(FeedScopedId vehicleRentalStationId) {
    vehicleRentalStations.remove(vehicleRentalStationId);
  }

  /**
   * Gets all the vehicle rental stations inside the envelope. This is currently done by iterating
   * over a set, but we could use a spatial index if the number of vehicle rental stations is high
   * enough for performance to be a concern.
   */
  public List getVehicleRentalStationForEnvelope(
    double minLon,
    double minLat,
    double maxLon,
    double maxLat
  ) {
    Envelope envelope = new Envelope(
      new Coordinate(minLon, minLat),
      new Coordinate(maxLon, maxLat)
    );

    return vehicleRentalStations
      .values()
      .stream()
      .filter(b -> envelope.contains(new Coordinate(b.getLongitude(), b.getLatitude())))
      .collect(Collectors.toList());
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy