1 package org.opentrafficsim.road.gtu.lane.perception;
2
3 import java.io.Serializable;
4
5 import org.djunits.value.vdouble.scalar.Length;
6 import org.opentrafficsim.core.gtu.RelativePosition;
7 import org.opentrafficsim.core.network.LateralDirectionality;
8
9 import nl.tudelft.simulation.language.Throw;
10
11
12
13
14
15
16
17
18
19
20
21 public class InfrastructureLaneChangeInfo implements Comparable<InfrastructureLaneChangeInfo>, Serializable
22 {
23
24
25 private static final long serialVersionUID = 20160811L;
26
27
28 private final int requiredNumberOfLaneChanges;
29
30
31 private final LaneStructureRecord record;
32
33
34 private final Length afterStartLength;
35
36
37 private boolean deadEnd;
38
39
40 private final LateralDirectionality lat;
41
42
43
44
45
46
47 protected InfrastructureLaneChangeInfo(final int requiredNumberOfLaneChanges, final boolean deadEnd)
48 {
49 this.requiredNumberOfLaneChanges = requiredNumberOfLaneChanges;
50 this.record = null;
51 this.deadEnd = deadEnd;
52 this.afterStartLength = null;
53 this.lat = LateralDirectionality.NONE;
54 }
55
56
57
58
59
60
61
62
63
64
65
66 public InfrastructureLaneChangeInfo(final int requiredNumberOfLaneChanges, final LaneStructureRecord record,
67 final RelativePosition relativePosition, final boolean deadEnd, final LateralDirectionality lat)
68 {
69 Throw.when(requiredNumberOfLaneChanges < 0, IllegalArgumentException.class,
70 "Required number of lane changes may not be negative.");
71 Throw.whenNull(lat, "Lateral directionality may not be null.");
72 Throw.when(requiredNumberOfLaneChanges != 0 && lat.equals(LateralDirectionality.NONE), IllegalArgumentException.class,
73 "Lateral directionality may not be NONE for non-zero lane changes.");
74 Throw.whenNull(record, "Record may not be null.");
75 this.requiredNumberOfLaneChanges = requiredNumberOfLaneChanges;
76 this.record = record;
77 this.afterStartLength = this.record.getLane().getLength().minus(relativePosition.getDx());
78 this.deadEnd = deadEnd;
79 this.lat = lat;
80 }
81
82
83
84
85 public final int getRequiredNumberOfLaneChanges()
86 {
87 return this.requiredNumberOfLaneChanges;
88 }
89
90
91
92
93 public Length getRemainingDistance()
94 {
95 return this.record.getStartDistance().plus(this.afterStartLength);
96 }
97
98
99
100
101 public final boolean isDeadEnd()
102 {
103 return this.deadEnd;
104 }
105
106
107
108
109
110 public final void setDeadEnd(final boolean deadEnd)
111 {
112 this.deadEnd = deadEnd;
113 }
114
115
116
117
118
119 public final LateralDirectionality getLateralDirectionality()
120 {
121 return this.lat;
122 }
123
124
125 @SuppressWarnings("checkstyle:designforextension")
126 @Override
127 public String toString()
128 {
129 return "InfrastructureLaneChangeInfo [requiredNumberOfLaneChanges=" + this.requiredNumberOfLaneChanges
130 + ", remainingDistance=" + getRemainingDistance() + "]";
131 }
132
133
134 @Override
135 public final int compareTo(final InfrastructureLaneChangeInfo infrastructureLaneChangeInfo)
136 {
137 return this.getRemainingDistance().compareTo(infrastructureLaneChangeInfo.getRemainingDistance());
138 }
139
140
141
142
143
144
145
146
147 public final InfrastructureLaneChangeInfo left(final LaneStructureRecord rec, final RelativePosition rel,
148 final boolean dead)
149 {
150 return new InfrastructureLaneChangeInfo(this.requiredNumberOfLaneChanges + 1, rec, rel, dead,
151 LateralDirectionality.LEFT);
152 }
153
154
155
156
157
158
159
160
161 public final InfrastructureLaneChangeInfo right(final LaneStructureRecord rec, final RelativePosition rel,
162 final boolean dead)
163 {
164 return new InfrastructureLaneChangeInfo(this.requiredNumberOfLaneChanges + 1, rec, rel, dead,
165 LateralDirectionality.RIGHT);
166 }
167
168
169
170
171
172
173 public static InfrastructureLaneChangeInfo fromInaccessibleLane(final boolean deadEnd)
174 {
175 return new InfrastructureLaneChangeInfoInaccessibleLane(deadEnd);
176 }
177
178
179
180
181
182
183
184
185
186
187
188
189
190 private static class InfrastructureLaneChangeInfoInaccessibleLane extends InfrastructureLaneChangeInfo
191 {
192
193
194 private static final long serialVersionUID = 20180214L;
195
196
197
198
199 InfrastructureLaneChangeInfoInaccessibleLane(final boolean deadEnd)
200 {
201 super(1, deadEnd);
202 }
203
204
205 @Override
206 public Length getRemainingDistance()
207 {
208 return Length.ZERO;
209 }
210
211 }
212
213 }