1 package org.opentrafficsim.road.network.lane.object;
2
3 import org.djunits.value.vdouble.scalar.Length;
4 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
5 import org.opentrafficsim.core.geometry.OTSLine3D;
6 import org.opentrafficsim.core.network.Network;
7 import org.opentrafficsim.core.network.NetworkException;
8 import org.opentrafficsim.core.object.StaticObject;
9 import org.opentrafficsim.road.network.lane.CrossSectionElement;
10 import org.opentrafficsim.road.network.lane.Lane;
11
12 import nl.tudelft.simulation.language.Throw;
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 public abstract class AbstractLaneBasedObject extends StaticObject implements LaneBasedObject
28 {
29
30 private static final long serialVersionUID = 20160909L;
31
32
33 private final Lane lane;
34
35
36 private final Length longitudinalPosition;
37
38
39
40
41
42
43
44
45
46
47 public AbstractLaneBasedObject(final Lane lane, final Length longitudinalPosition, final OTSLine3D geometry,
48 final Length height) throws NetworkException
49 {
50 super(geometry, height);
51
52 Throw.whenNull(lane, "lane is null");
53 Throw.whenNull(longitudinalPosition, "longitudinal position is null");
54 Throw.whenNull(geometry, "geometry is null");
55 Throw.when(longitudinalPosition.si < 0.0 || longitudinalPosition.si > lane.getCenterLine().getLengthSI(),
56 NetworkException.class, "Position of the object on the lane is out of bounds");
57
58 this.lane = lane;
59 this.longitudinalPosition = longitudinalPosition;
60 }
61
62
63
64
65
66
67
68
69
70 public AbstractLaneBasedObject(final Lane lane, final Length longitudinalPosition, final OTSLine3D geometry)
71 throws NetworkException
72 {
73 this(lane, longitudinalPosition, geometry, Length.ZERO);
74 }
75
76
77 @Override
78 public final Lane getLane()
79 {
80 return this.lane;
81 }
82
83
84 @Override
85 public final Length getLongitudinalPosition()
86 {
87 return this.longitudinalPosition;
88 }
89
90
91 @Override
92 public final StaticObject clone(final Network newNetwork, final OTSSimulatorInterface newSimulator, final boolean animation)
93 throws NetworkException
94 {
95 throw new NetworkException("LaneBasedObjects should be cloned with the clone(lane, simulator, animation) method");
96 }
97
98
99
100
101
102
103
104
105
106 @SuppressWarnings("checkstyle:designforextension")
107 public abstract AbstractLaneBasedObject clone(final CrossSectionElement newCSE, final OTSSimulatorInterface newSimulator,
108 final boolean animation) throws NetworkException;
109
110 }