Class SpeedLimitProspect

  • All Implemented Interfaces:
    Serializable

    public class SpeedLimitProspect
    extends Object
    implements Serializable
    Prospect of speed limits ahead, both legal and otherwise (e.g. curve, speed bump).

    Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
    BSD-style license. See OpenTrafficSim License.

    Version:
    $Revision$, $LastChangedDate$, by $Author$, initial version May 1, 2016
    Author:
    Alexander Verbraeck, Wouter Schakel
    See Also:
    Serialized Form
    • Constructor Detail

      • SpeedLimitProspect

        public SpeedLimitProspect​(Length odometer)
        Constructor.
        Parameters:
        odometer - Length; odometer value
    • Method Detail

      • update

        public void update​(Length newOdometer)
        Updates the distance values.
        Parameters:
        newOdometer - Length; odometer value
      • containsAddSource

        public final boolean containsAddSource​(Object source)
        Returns whether the given source is already added in the prospect.
        Parameters:
        source - Object; source
        Returns:
        whether the given source is already added in the prospect
      • containsRemoveSource

        public final boolean containsRemoveSource​(Object source)
        Returns whether the given source is already removed in the prospect.
        Parameters:
        source - Object; source
        Returns:
        whether the given source is already removed in the prospect
      • getOdometer

        public final Length getOdometer()
        Returns the odometer value at which the last update was performed.
        Returns:
        Length; odometer value at which the last update was performed
      • addSpeedInfo

        public final <T> void addSpeedInfo​(Length distance,
                                           SpeedLimitType<T> speedLimitType,
                                           T speedInfo,
                                           Object source)
        Sets the speed info of a speed limit type.
        Type Parameters:
        T - class of speed info
        Parameters:
        distance - Length; location to set info for a speed limit type
        speedLimitType - SpeedLimitType<T>; speed limit type to set the info for
        speedInfo - T; speed info to set
        source - Object; source object
        Throws:
        IllegalStateException - if speed info for a specific speed limit type is set or removed twice at the same distance
        IllegalStateException - if speed info for a specific speed limit type is set twice with negative distance
        NullPointerException - if any input is null
      • removeSpeedInfo

        public final void removeSpeedInfo​(Length distance,
                                          SpeedLimitType<?> speedLimitType,
                                          Object source)
        Removes the speed info of a speed limit type.
        Parameters:
        distance - Length; distance to remove speed info of a speed limit type
        speedLimitType - SpeedLimitType<?>; speed limit type to remove speed info of
        source - Object; source object
        Throws:
        IllegalStateException - if speed info for a specific speed limit type is set or removed twice at the same distance
        IllegalArgumentException - if the speed limit type is MAX_VEHICLE_SPEED
        IllegalArgumentException - if the distance is negative
        NullPointerException - if any input is null
      • getDistances

        public final List<Length> getDistances()
        Returns the distances at which a change in the prospect is present in order (upstream first). If multiple changes are present at the same distance, only one distance is returned in the list.
        Returns:
        distances at which a change in the prospect is present in order (upstream first)
      • getDistances

        public final List<Length> getDistances​(SpeedLimitType<?> speedLimitType)
        Returns the distances at which a change of the given speed limit type in the prospect is present in order (most upstream first). If multiple changes are present at the same distance, only one distance is returned in the list.
        Parameters:
        speedLimitType - SpeedLimitType<?>; speed limit type to get the distances of
        Returns:
        distances at which a change of the given speed limit type in the prospect is present in order
      • getUpstreamDistances

        public final List<Length> getUpstreamDistances​(SpeedLimitType<?> speedLimitType)
        Returns the upstream distances at which a change of the given speed limit type in the prospect is present in order (most upstream first). If multiple changes are present at the same distance, only one distance is returned in the list.
        Parameters:
        speedLimitType - SpeedLimitType<?>; speed limit type to get the distances of
        Returns:
        distances at which a change of the given speed limit type in the prospect is present in order
      • getDownstreamDistances

        public final List<Length> getDownstreamDistances​(SpeedLimitType<?> speedLimitType)
        Returns the downstream distances at which a change of the given speed limit type in the prospect is present in order (most upstream first). If multiple changes are present at the same distance, only one distance is returned in the list.
        Parameters:
        speedLimitType - SpeedLimitType<?>; speed limit type to get the distances of
        Returns:
        distances at which a change of the given speed limit type in the prospect is present in order
      • speedInfoChanged

        public final boolean speedInfoChanged​(Length distance,
                                              SpeedLimitType<?> speedLimitType)
        Returns whether the given speed limit type is changed at the given distance.
        Parameters:
        distance - Length; distance to check
        speedLimitType - SpeedLimitType<?>; speed limit type to check
        Returns:
        whether the given speed limit type is changed at the given distance
        Throws:
        NullPointerException - if distance is null
      • getSpeedInfoChange

        public final <T> T getSpeedInfoChange​(Length distance,
                                              SpeedLimitType<T> speedLimitType)
        Returns the speed info of given speed limit type where it changed. If the change was removing the speed limit type (e.g. end of corner), then null is returned.
        Type Parameters:
        T - class of the speed limit type info
        Parameters:
        distance - Length; distance where the info changed
        speedLimitType - SpeedLimitType<T>; speed limit type
        Returns:
        speed info of given speed limit type where it changed, null if speed limit type is removed
        Throws:
        IllegalArgumentException - if the speed info did not change at the given distance for the speed limit type
      • getSpeedLimitInfo

        public final SpeedLimitInfo getSpeedLimitInfo​(Length distance)
        Returns the speed info at a given location.
        Parameters:
        distance - Length; where to get the speed info
        Returns:
        speed info at a given distance
        Throws:
        NullPointerException - if distance is null
      • getSpeedLimitInfo

        public final SpeedLimitInfo getSpeedLimitInfo​(Speed speed,
                                                      Acceleration acceleration,
                                                      Duration time)
        Returns the speed info at a location following an acceleration over some duration.
        Parameters:
        speed - Speed; current speed
        acceleration - Acceleration; acceleration to apply
        time - Duration; duration of acceleration
        Returns:
        speed info at a given distance
        Throws:
        NullPointerException - if any input is null
      • buildSpeedLimitInfo

        public final <T> SpeedLimitInfo buildSpeedLimitInfo​(Length distance,
                                                            SpeedLimitType<T> speedLimitType)
        Builds speed limit info with only MAX_VEHICLE_SPEED and the given speed limit type, where the speed info is obtained at the given distance.
        Type Parameters:
        T - class of speed info of given speed limit type
        Parameters:
        distance - Length; distance to get the speed info at
        speedLimitType - SpeedLimitType<T>; speed limit type of which to include the info
        Returns:
        speed limit info with only MAX_VEHICLE_SPEED and the given speed limit type