1 package org.opentrafficsim.road.network.lane.object;
2
3 import org.djunits.value.vdouble.scalar.Duration;
4 import org.djunits.value.vdouble.scalar.Length;
5 import org.djunits.value.vdouble.scalar.Speed;
6 import org.opentrafficsim.core.dsol.OtsSimulatorInterface;
7 import org.opentrafficsim.core.gtu.GtuType;
8 import org.opentrafficsim.core.network.NetworkException;
9 import org.opentrafficsim.road.network.lane.Lane;
10
11
12
13
14
15
16
17
18
19
20
21 public class SpeedSign extends AbstractLaneBasedObject
22 {
23
24
25 private static final long serialVersionUID = 20170420L;
26
27
28 private final Speed speed;
29
30
31 private final GtuType gtuType;
32
33
34 private final Duration startTimeOfDay;
35
36
37 private final Duration endTimeOfDay;
38
39
40
41
42
43
44
45
46
47
48
49
50
51 @SuppressWarnings("checkstyle:parameternumber")
52 public SpeedSign(final String id, final Lane lane, final Length longitudinalPosition, final OtsSimulatorInterface simulator,
53 final Speed speed, final GtuType gtuType, final Duration startTimeOfDay, final Duration endTimeOfDay)
54 throws NetworkException
55 {
56 super(id, lane, longitudinalPosition, LaneBasedObject.makeGeometry(lane, longitudinalPosition));
57 this.speed = speed;
58 this.gtuType = gtuType;
59 this.startTimeOfDay = startTimeOfDay;
60 this.endTimeOfDay = endTimeOfDay;
61
62 init();
63 }
64
65
66
67
68
69
70
71 public final boolean isActive(final GtuType gtuTypeIn, final Duration time)
72 {
73 return gtuTypeIn.isOfType(this.gtuType) && time.ge(this.startTimeOfDay) && time.le(this.endTimeOfDay);
74 }
75
76
77
78
79
80 public final Speed getSpeed()
81 {
82 return this.speed;
83 }
84
85
86 @Override
87 public int hashCode()
88 {
89 final int prime = 31;
90 int result = 1;
91 result = prime * result + ((this.endTimeOfDay == null) ? 0 : this.endTimeOfDay.hashCode());
92 result = prime * result + ((this.gtuType == null) ? 0 : this.gtuType.hashCode());
93 result = prime * result + ((this.speed == null) ? 0 : this.speed.hashCode());
94 result = prime * result + ((this.startTimeOfDay == null) ? 0 : this.startTimeOfDay.hashCode());
95 return result;
96 }
97
98
99 @Override
100 public boolean equals(final Object obj)
101 {
102 if (this == obj)
103 {
104 return true;
105 }
106 if (obj == null)
107 {
108 return false;
109 }
110 if (getClass() != obj.getClass())
111 {
112 return false;
113 }
114 SpeedSign other = (SpeedSign) obj;
115 if (this.endTimeOfDay == null)
116 {
117 if (other.endTimeOfDay != null)
118 {
119 return false;
120 }
121 }
122 else if (!this.endTimeOfDay.equals(other.endTimeOfDay))
123 {
124 return false;
125 }
126 if (this.gtuType == null)
127 {
128 if (other.gtuType != null)
129 {
130 return false;
131 }
132 }
133 else if (!this.gtuType.equals(other.gtuType))
134 {
135 return false;
136 }
137 if (this.speed == null)
138 {
139 if (other.speed != null)
140 {
141 return false;
142 }
143 }
144 else if (!this.speed.equals(other.speed))
145 {
146 return false;
147 }
148 if (this.startTimeOfDay == null)
149 {
150 if (other.startTimeOfDay != null)
151 {
152 return false;
153 }
154 }
155 else if (!this.startTimeOfDay.equals(other.startTimeOfDay))
156 {
157 return false;
158 }
159 return true;
160 }
161
162
163 @Override
164 public final String toString()
165 {
166 return "SpeedSign [speed=" + this.speed + ", gtuType=" + this.gtuType + ", startTime=" + this.startTimeOfDay
167 + ", endTime=" + this.endTimeOfDay + "]";
168 }
169
170 }