1 package org.opentrafficsim.road.network.lane.object;
2
3 import org.djunits.unit.DurationUnit;
4 import org.djunits.value.vdouble.scalar.Duration;
5 import org.djunits.value.vdouble.scalar.Length;
6 import org.djunits.value.vdouble.scalar.Speed;
7 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
8 import org.opentrafficsim.core.gtu.GTUType;
9 import org.opentrafficsim.core.network.LongitudinalDirectionality;
10 import org.opentrafficsim.core.network.NetworkException;
11 import org.opentrafficsim.road.network.lane.CrossSectionElement;
12 import org.opentrafficsim.road.network.lane.Lane;
13
14
15
16
17
18
19
20
21
22
23
24
25 public class SpeedSign extends AbstractLaneBasedObject
26 {
27
28
29 private static final long serialVersionUID = 20170420L;
30
31
32 private static final Duration ENDOFDAY = new Duration(24, DurationUnit.HOUR);
33
34
35 private final Speed speed;
36
37
38 private final GTUType gtuType;
39
40
41 private final Duration startTimeOfDay;
42
43
44 private final Duration endTimeOfDay;
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 @SuppressWarnings("checkstyle:parameternumber")
60 public SpeedSign(final String id, final Lane lane, final LongitudinalDirectionality direction,
61 final Length longitudinalPosition, final OTSSimulatorInterface simulator, final Speed speed,
62 final GTUType gtuType, final Duration startTimeOfDay, final Duration endTimeOfDay) throws NetworkException
63 {
64 super(id, lane, direction, longitudinalPosition, LaneBasedObject.makeGeometry(lane, longitudinalPosition));
65 this.speed = speed;
66 this.gtuType = gtuType;
67 this.startTimeOfDay = startTimeOfDay;
68 this.endTimeOfDay = endTimeOfDay;
69
70 init();
71 }
72
73
74
75
76
77
78
79
80
81
82
83
84 public SpeedSign(final String id, final Lane lane, final LongitudinalDirectionality direction,
85 final Length longitudinalPosition, final OTSSimulatorInterface simulator, final Speed speed,
86 final GTUType gtuType) throws NetworkException
87 {
88 this(id, lane, direction, longitudinalPosition, simulator, speed, gtuType, Duration.ZERO, ENDOFDAY);
89 }
90
91
92
93
94
95
96
97
98
99
100
101
102
103 @SuppressWarnings("checkstyle:parameternumber")
104 public SpeedSign(final String id, final Lane lane, final LongitudinalDirectionality direction,
105 final Length longitudinalPosition, final OTSSimulatorInterface simulator, final Speed speed,
106 final Duration startTimeOfDay, final Duration endTimeOfDay) throws NetworkException
107 {
108 this(id, lane, direction, longitudinalPosition, simulator, speed,
109 lane.getNetwork().getGtuType(GTUType.DEFAULTS.VEHICLE), startTimeOfDay, endTimeOfDay);
110 }
111
112
113
114
115
116
117
118
119
120
121
122 public SpeedSign(final String id, final Lane lane, final LongitudinalDirectionality direction,
123 final Length longitudinalPosition, final OTSSimulatorInterface simulator, final Speed speed)
124 throws NetworkException
125 {
126 this(id, lane, direction, longitudinalPosition, simulator, speed,
127 lane.getNetwork().getGtuType(GTUType.DEFAULTS.VEHICLE), Duration.ZERO, ENDOFDAY);
128 }
129
130
131
132
133
134
135
136 public final boolean isActive(final GTUType gtuTypeIn, final Duration time)
137 {
138 return gtuTypeIn.isOfType(this.gtuType) && time.ge(this.startTimeOfDay) && time.le(this.endTimeOfDay);
139 }
140
141
142
143
144
145 public final Speed getSpeed()
146 {
147 return this.speed;
148 }
149
150
151 @Override
152 public final AbstractLaneBasedObject clone(final CrossSectionElement newCSE,
153 final OTSSimulatorInterface newSimulator) throws NetworkException
154 {
155 return new SpeedSign(getId(), (Lane) newCSE, getDirection(), getLongitudinalPosition(), newSimulator, this.speed,
156 this.gtuType, this.startTimeOfDay, this.endTimeOfDay);
157 }
158
159
160 @Override
161 public int hashCode()
162 {
163 final int prime = 31;
164 int result = 1;
165 result = prime * result + ((this.endTimeOfDay == null) ? 0 : this.endTimeOfDay.hashCode());
166 result = prime * result + ((this.gtuType == null) ? 0 : this.gtuType.hashCode());
167 result = prime * result + ((this.speed == null) ? 0 : this.speed.hashCode());
168 result = prime * result + ((this.startTimeOfDay == null) ? 0 : this.startTimeOfDay.hashCode());
169 return result;
170 }
171
172
173 @Override
174 public boolean equals(final Object obj)
175 {
176 if (this == obj)
177 {
178 return true;
179 }
180 if (obj == null)
181 {
182 return false;
183 }
184 if (getClass() != obj.getClass())
185 {
186 return false;
187 }
188 SpeedSign other = (SpeedSign) obj;
189 if (this.endTimeOfDay == null)
190 {
191 if (other.endTimeOfDay != null)
192 {
193 return false;
194 }
195 }
196 else if (!this.endTimeOfDay.equals(other.endTimeOfDay))
197 {
198 return false;
199 }
200 if (this.gtuType == null)
201 {
202 if (other.gtuType != null)
203 {
204 return false;
205 }
206 }
207 else if (!this.gtuType.equals(other.gtuType))
208 {
209 return false;
210 }
211 if (this.speed == null)
212 {
213 if (other.speed != null)
214 {
215 return false;
216 }
217 }
218 else if (!this.speed.equals(other.speed))
219 {
220 return false;
221 }
222 if (this.startTimeOfDay == null)
223 {
224 if (other.startTimeOfDay != null)
225 {
226 return false;
227 }
228 }
229 else if (!this.startTimeOfDay.equals(other.startTimeOfDay))
230 {
231 return false;
232 }
233 return true;
234 }
235
236
237 @Override
238 public final String toString()
239 {
240 return "SpeedSign [speed=" + this.speed + ", gtuType=" + this.gtuType + ", startTime=" + this.startTimeOfDay
241 + ", endTime=" + this.endTimeOfDay + "]";
242 }
243
244 }