Class SpeedLimitProspect
- java.lang.Object
-
- org.opentrafficsim.road.network.speed.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-2020 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 Summary
Constructors Constructor Description SpeedLimitProspect(Length odometer)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> void
addSpeedInfo(Length distance, SpeedLimitType<T> speedLimitType, T speedInfo, Object source)
Sets the speed info of a speed limit type.<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.boolean
containsAddSource(Object source)
Returns whether the given source is already added in the prospect.boolean
containsRemoveSource(Object source)
Returns whether the given source is already removed in the prospect.List<Length>
getDistances()
Returns the distances at which a change in the prospect is present in order (upstream first).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).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).Length
getOdometer()
Returns the odometer value at which the last update was performed.<T> T
getSpeedInfoChange(Length distance, SpeedLimitType<T> speedLimitType)
Returns the speed info of given speed limit type where it changed.SpeedLimitInfo
getSpeedLimitInfo(Length distance)
Returns the speed info at a given location.SpeedLimitInfo
getSpeedLimitInfo(Speed speed, Acceleration acceleration, Duration time)
Returns the speed info at a location following an acceleration over some duration.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).void
removeSpeedInfo(Length distance, SpeedLimitType<?> speedLimitType, Object source)
Removes the speed info of a speed limit type.boolean
speedInfoChanged(Length distance, SpeedLimitType<?> speedLimitType)
Returns whether the given speed limit type is changed at the given distance.String
toString()
void
update(Length newOdometer)
Updates the distance values.
-
-
-
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 typespeedLimitType
- SpeedLimitType<T>; speed limit type to set the info forspeedInfo
- T; speed info to setsource
- Object; source object- Throws:
IllegalStateException
- if speed info for a specific speed limit type is set or removed twice at the same distanceIllegalStateException
- if speed info for a specific speed limit type is set twice with negative distanceNullPointerException
- 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 typespeedLimitType
- SpeedLimitType<?>; speed limit type to remove speed info ofsource
- Object; source object- Throws:
IllegalStateException
- if speed info for a specific speed limit type is set or removed twice at the same distanceIllegalArgumentException
- if the speed limit type isMAX_VEHICLE_SPEED
IllegalArgumentException
- if the distance is negativeNullPointerException
- 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 checkspeedLimitType
- 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), thennull
is returned.- Type Parameters:
T
- class of the speed limit type info- Parameters:
distance
- Length; distance where the info changedspeedLimitType
- 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 speedacceleration
- Acceleration; acceleration to applytime
- 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 atspeedLimitType
- 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
-
-