1 package org.opentrafficsim.road.gtu.lane.perception.headway;
2
3 import java.util.SortedSet;
4 import java.util.TreeSet;
5
6 import org.djunits.value.vdouble.scalar.Length;
7 import org.djunits.value.vdouble.scalar.Speed;
8 import org.opentrafficsim.core.gtu.GTUException;
9 import org.opentrafficsim.road.network.lane.conflict.ConflictRule;
10 import org.opentrafficsim.road.network.lane.conflict.ConflictType;
11
12 import nl.tudelft.simulation.language.Throw;
13
14
15
16
17
18
19
20
21
22
23
24 public class HeadwayConflict extends AbstractHeadway
25 {
26
27
28 private static final long serialVersionUID = 20160602L;
29
30
31 private final ConflictType conflictType;
32
33
34 private final ConflictRule conflictRule;
35
36
37 private final Length conflictingLength;
38
39
40
41
42
43 private final SortedSet<AbstractHeadwayGTU> upstreamConflictingGTUs;
44
45
46
47
48
49 private final SortedSet<AbstractHeadwayGTU> downstreamConflictingGTUs;
50
51
52 private final Length conflictingVisibility;
53
54
55 private final Speed conflictingSpeedLimit;
56
57
58 private final HeadwayStopLine stopLine;
59
60
61 private final HeadwayStopLine conflictingStopLine;
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 @SuppressWarnings("checkstyle:parameternumber")
80 public HeadwayConflict(final ConflictType conflictType, final ConflictRule conflictRule, final String id,
81 final Length distance, final Length length, final Length conflictingLength,
82 final SortedSet<AbstractHeadwayGTU> upstreamConflictingGTUs,
83 final SortedSet<AbstractHeadwayGTU> downstreamConflictingGTUs, final Length conflictingVisibility,
84 final Speed conflictingSpeedLimit, final HeadwayStopLine stopLine, final HeadwayStopLine conflictingStopLine)
85 throws GTUException
86 {
87 super(ObjectType.CONFLICT, id, distance, length);
88 Throw.whenNull(conflictType, "Conflict type may not be null.");
89 Throw.whenNull(conflictRule, "Conflict rule may not be null.");
90 Throw.whenNull(id, "Conflict id may not be null.");
91 Throw.whenNull(distance, "Conflict distance may not be null.");
92 Throw.whenNull(conflictingLength, "Conflict length may not be null.");
93 Throw.whenNull(upstreamConflictingGTUs, "Upstreaem conflicting GTU's may not be null.");
94 Throw.whenNull(downstreamConflictingGTUs, "Downstream conflicting GTU's may not be null.");
95 Throw.whenNull(conflictingVisibility, "Conflict visibility may not be null.");
96 Throw.whenNull(conflictingSpeedLimit, "Conflict speed limit may not be null.");
97 this.conflictType = conflictType;
98 this.conflictRule = conflictRule;
99 this.conflictingLength = conflictingLength;
100 this.upstreamConflictingGTUs = upstreamConflictingGTUs;
101 this.downstreamConflictingGTUs = downstreamConflictingGTUs;
102 this.conflictingVisibility = conflictingVisibility;
103 this.conflictingSpeedLimit = conflictingSpeedLimit;
104 this.stopLine = stopLine;
105 this.conflictingStopLine = conflictingStopLine;
106 }
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122 @SuppressWarnings("checkstyle:parameternumber")
123 public HeadwayConflict(final ConflictType conflictType, final ConflictRule conflictRule, final String id,
124 final Length distance, final Length length, final Length conflictingLength,
125 final SortedSet<AbstractHeadwayGTU> upstreamConflictingGTUs,
126 final SortedSet<AbstractHeadwayGTU> downstreamConflictingGTUs, final Length conflictingVisibility,
127 final Speed conflictingSpeedLimit) throws GTUException
128 {
129 this(conflictType, conflictRule, id, distance, length, conflictingLength, upstreamConflictingGTUs,
130 downstreamConflictingGTUs, conflictingVisibility, conflictingSpeedLimit, null, null);
131 }
132
133
134
135
136
137 public final ConflictType getConflictType()
138 {
139 return this.conflictType;
140 }
141
142
143
144
145
146 public final boolean isCrossing()
147 {
148 return this.conflictType == ConflictType.CROSSING;
149 }
150
151
152
153
154
155 public final boolean isMerge()
156 {
157 return this.conflictType == ConflictType.MERGE;
158 }
159
160
161
162
163
164 public final boolean isSplit()
165 {
166 return this.conflictType == ConflictType.SPLIT;
167 }
168
169
170
171
172
173 public final ConflictRule getConflictRule()
174 {
175 return this.conflictRule;
176 }
177
178
179
180
181
182 public final boolean isPriority()
183 {
184 return this.conflictRule == ConflictRule.PRIORITY;
185 }
186
187
188
189
190
191 public final boolean isGiveWay()
192 {
193 return this.conflictRule == ConflictRule.GIVE_WAY;
194 }
195
196
197
198
199
200 public final boolean isStop()
201 {
202 return this.conflictRule == ConflictRule.STOP;
203 }
204
205
206
207
208
209 public final boolean isAllStop()
210 {
211 return this.conflictRule == ConflictRule.ALL_STOP;
212 }
213
214
215
216
217
218 public final Length getConflictingLength()
219 {
220 return this.conflictingLength;
221 }
222
223
224
225
226
227 public final SortedSet<AbstractHeadwayGTU> getUpstreamConflictingGTUs()
228 {
229 return new TreeSet<>(this.upstreamConflictingGTUs);
230 }
231
232
233
234
235
236
237
238 public final SortedSet<AbstractHeadwayGTU> getDownstreamConflictingGTUs()
239 {
240 return new TreeSet<>(this.downstreamConflictingGTUs);
241 }
242
243
244
245
246
247
248
249 public final Length getConflictingVisibility()
250 {
251 return this.conflictingVisibility;
252 }
253
254
255
256
257
258 public final Speed getConflictingSpeedLimit()
259 {
260 return this.conflictingSpeedLimit;
261 }
262
263
264
265
266
267 public final HeadwayStopLine getStopLine()
268 {
269 return this.stopLine;
270 }
271
272
273
274
275
276 public final HeadwayStopLine getConflictingStopLine()
277 {
278 return this.conflictingStopLine;
279 }
280
281
282 public final String toString()
283 {
284 return String.format("Headway %s to object %s of type %s", getDistance(), getId(), getObjectType());
285 }
286
287 }