1 package org.opentrafficsim.kpi.sampling;
2
3 import org.djunits.value.vdouble.scalar.Length;
4 import org.djunits.value.vdouble.scalar.Time;
5 import org.djutils.exceptions.Throw;
6 import org.opentrafficsim.kpi.interfaces.LaneData;
7
8
9
10
11
12
13
14
15
16
17
18
19 public class SpaceTimeRegion<L extends LaneData>
20 {
21
22
23 private final L lane;
24
25
26 private final Length startPosition;
27
28
29 private final Length endPosition;
30
31
32 private final Time startTime;
33
34
35 private final Time endTime;
36
37
38
39
40
41
42
43
44
45 public SpaceTimeRegion(final L lane, final Length startPosition, final Length endPosition, final Time startTime,
46 final Time endTime)
47 {
48 Throw.whenNull(startPosition, "Start position may not be null.");
49 Throw.whenNull(endPosition, "End position may not be null.");
50 Throw.whenNull(startTime, "Start time may not be null.");
51 Throw.whenNull(endTime, "End time may not be null.");
52 Throw.when(endPosition.lt(startPosition), IllegalArgumentException.class,
53 "End position should be greater than start position.");
54 Throw.when(endTime.lt(startTime), IllegalArgumentException.class, "End time should be greater than start time.");
55 this.lane = lane;
56 this.startPosition = startPosition;
57 this.endPosition = endPosition;
58 this.startTime = startTime;
59 this.endTime = endTime;
60 }
61
62
63
64
65
66 public final L getLane()
67 {
68 return this.lane;
69 }
70
71
72
73
74
75 public final Length getStartPosition()
76 {
77 return this.startPosition;
78 }
79
80
81
82
83
84 public final Length getEndPosition()
85 {
86 return this.endPosition;
87 }
88
89
90
91
92
93 public final Time getStartTime()
94 {
95 return this.startTime;
96 }
97
98
99
100
101
102 public final Time getEndTime()
103 {
104 return this.endTime;
105 }
106
107
108 @Override
109 public final int hashCode()
110 {
111 final int prime = 31;
112 int result = 1;
113 result = prime * result + ((this.endPosition == null) ? 0 : this.endPosition.hashCode());
114 result = prime * result + ((this.endTime == null) ? 0 : this.endTime.hashCode());
115 result = prime * result + ((this.lane == null) ? 0 : this.lane.hashCode());
116 result = prime * result + ((this.startPosition == null) ? 0 : this.startPosition.hashCode());
117 result = prime * result + ((this.startTime == null) ? 0 : this.startTime.hashCode());
118 return result;
119 }
120
121
122 @Override
123 public final boolean equals(final Object obj)
124 {
125 if (this == obj)
126 {
127 return true;
128 }
129 if (obj == null)
130 {
131 return false;
132 }
133 if (getClass() != obj.getClass())
134 {
135 return false;
136 }
137 SpaceTimeRegion<?> other = (SpaceTimeRegion<?>) obj;
138 if (this.endPosition == null)
139 {
140 if (other.endPosition != null)
141 {
142 return false;
143 }
144 }
145 else if (!this.endPosition.equals(other.endPosition))
146 {
147 return false;
148 }
149 if (this.endTime == null)
150 {
151 if (other.endTime != null)
152 {
153 return false;
154 }
155 }
156 else if (!this.endTime.equals(other.endTime))
157 {
158 return false;
159 }
160 if (this.lane == null)
161 {
162 if (other.lane != null)
163 {
164 return false;
165 }
166 }
167 else if (!this.lane.equals(other.lane))
168 {
169 return false;
170 }
171 if (this.startPosition == null)
172 {
173 if (other.startPosition != null)
174 {
175 return false;
176 }
177 }
178 else if (!this.startPosition.equals(other.startPosition))
179 {
180 return false;
181 }
182 if (this.startTime == null)
183 {
184 if (other.startTime != null)
185 {
186 return false;
187 }
188 }
189 else if (!this.startTime.equals(other.startTime))
190 {
191 return false;
192 }
193 return true;
194 }
195
196
197 @Override
198 public final String toString()
199 {
200 return "SpaceTimeRegion [laneDirection=" + this.lane + ", startPosition=" + this.startPosition + ", endPosition="
201 + this.endPosition + ", startTime=" + this.startTime + ", endTime=" + this.endTime + "]";
202 }
203
204 }