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