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

org.opentripplanner.routing.services.RealtimeVehiclePositionService Maven / Gradle / Ivy

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

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.opentripplanner.model.vehicle_position.RealtimeVehiclePosition;
import org.opentripplanner.transit.model.network.TripPattern;

public class RealtimeVehiclePositionService {

  private final Map> positions = new ConcurrentHashMap<>();

  /**
   * For the given pattern set all realtime vehicle positions.
   * 

* The list is expected to be exhaustive: all existing positions will be overridden. *

* This means that if there are two updaters providing positions for the same pattern they * overwrite each other. */ public void setVehiclePositions(TripPattern pattern, List updates) { positions.put(pattern, List.copyOf(updates)); } /** * Remove all vehicle positions for a given pattern. *

* This is useful to clear old vehicles for which there are no more updates and we assume that * they have stopped their trip. */ public void clearVehiclePositions(TripPattern pattern) { positions.remove(pattern); } /** * Get the vehicle positions for a certain trip. */ public List getVehiclePositions(TripPattern pattern) { // the list is made immutable during insertion, so we can safely return them return positions.getOrDefault(pattern, List.of()); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy