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