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