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