1 package org.opentrafficsim.road.network.sampling;
2
3 import org.djunits.unit.SpeedUnit;
4 import org.djunits.value.vdouble.scalar.Speed;
5 import org.opentrafficsim.core.gtu.GTUException;
6 import org.opentrafficsim.core.network.NetworkException;
7 import org.opentrafficsim.kpi.interfaces.GtuDataInterface;
8 import org.opentrafficsim.kpi.sampling.data.ExtendedDataType;
9 import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
10
11 import nl.tudelft.simulation.language.Throw;
12
13
14
15
16
17
18
19
20
21
22
23 public class SpeedLimit extends ExtendedDataType<Speed>
24 {
25
26
27
28
29 public SpeedLimit()
30 {
31 super("SpeedLimit");
32 }
33
34
35 @Override
36 public final Speed getValue(final GtuDataInterface gtu)
37 {
38 Throw.whenNull(gtu, "GTU may not be null.");
39 Throw.when(!(gtu instanceof GtuData), IllegalArgumentException.class,
40 "Extended data type speed limit is only for use with GtuData. The provided data %s is of the wrong type.", gtu);
41 LaneBasedGTU laneGtu = ((GtuData) gtu).getGtu();
42 try
43 {
44 return laneGtu.getReferencePosition().getLane().getSpeedLimit(laneGtu.getGTUType());
45 }
46 catch (NetworkException | GTUException exception)
47 {
48 throw new RuntimeException("Could not obtain speed limit.", exception);
49 }
50 }
51
52
53 public final String toString()
54 {
55 return "SpeedLimit";
56 }
57
58 }