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