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