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