1 package org.opentrafficsim.core.gtu;
2
3 import java.io.Serializable;
4
5 import org.djunits.value.vdouble.scalar.Length;
6
7
8
9
10
11
12
13
14
15
16
17
18
19 public class RelativePosition implements Serializable
20 {
21
22 private static final long serialVersionUID = 20141231L;
23
24
25 private final Length dx;
26
27
28 private final Length dy;
29
30
31 private final Length dz;
32
33
34 private final TYPE type;
35
36
37 public static final TYPE FRONT = new TYPE("FRONT");
38
39
40 public static final TYPE REAR = new TYPE("REAR");
41
42
43 public static final TYPE CENTER = new TYPE("CENTER");
44
45
46 public static final TYPE REFERENCE = new TYPE("REFERENCE");
47
48
49 public static final TYPE DRIVER = new TYPE("DRIVER");
50
51
52 public static final TYPE CONTOUR = new TYPE("CONTOUR");
53
54
55 public static final RelativePosition REFERENCE_POSITION =
56 new RelativePosition(Length.ZERO, Length.ZERO, Length.ZERO, RelativePosition.REFERENCE);
57
58
59 private final int hash;
60
61
62
63
64
65
66
67 public RelativePosition(final Length dx, final Length dy, final Length dz, final TYPE type)
68 {
69 super();
70 this.dx = dx;
71 this.dy = dy;
72 this.dz = dz;
73 this.type = type;
74
75 this.hash = calcHashCode();
76 }
77
78
79
80
81 public RelativePosition(final RelativePosition p)
82 {
83 super();
84 this.dx = p.getDx();
85 this.dy = p.getDy();
86 this.dz = p.getDz();
87 this.type = p.getType();
88
89 this.hash = calcHashCode();
90 }
91
92
93
94
95 public final Length getDx()
96 {
97 return this.dx;
98 }
99
100
101
102
103 public final Length getDy()
104 {
105 return this.dy;
106 }
107
108
109
110
111 public final Length getDz()
112 {
113 return this.dz;
114 }
115
116
117
118
119 public final TYPE getType()
120 {
121 return this.type;
122 }
123
124
125 @Override
126 public final String toString()
127 {
128 return "(" + this.dx + ", " + this.dy + ", " + this.dz + "): " + this.type;
129 }
130
131
132
133
134
135 public final int calcHashCode()
136 {
137 final int prime = 31;
138 int result = 1;
139 result = prime * result + ((this.dx == null) ? 0 : this.dx.hashCode());
140 result = prime * result + ((this.dy == null) ? 0 : this.dy.hashCode());
141 result = prime * result + ((this.dz == null) ? 0 : this.dz.hashCode());
142 result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
143 return result;
144 }
145
146
147 @Override
148 @SuppressWarnings("checkstyle:designforextension")
149 public int hashCode()
150 {
151 return this.hash;
152 }
153
154
155 @Override
156 @SuppressWarnings({ "checkstyle:designforextension", "checkstyle:needbraces" })
157 public boolean equals(final Object obj)
158 {
159 if (this == obj)
160 return true;
161 if (obj == null)
162 return false;
163 if (getClass() != obj.getClass())
164 return false;
165 RelativePosition other = (RelativePosition) obj;
166 if (this.dx == null)
167 {
168 if (other.dx != null)
169 return false;
170 }
171 else if (!this.dx.equals(other.dx))
172 return false;
173 if (this.dy == null)
174 {
175 if (other.dy != null)
176 return false;
177 }
178 else if (!this.dy.equals(other.dy))
179 return false;
180 if (this.dz == null)
181 {
182 if (other.dz != null)
183 return false;
184 }
185 else if (!this.dz.equals(other.dz))
186 return false;
187 if (this.type == null)
188 {
189 if (other.type != null)
190 return false;
191 }
192 else if (!this.type.equals(other.type))
193 return false;
194 return true;
195 }
196
197
198
199
200
201
202
203
204
205
206
207
208
209 public static class TYPE implements Serializable
210 {
211
212 private static final long serialVersionUID = 20141231L;
213
214
215 private final String name;
216
217
218 private final int hash;
219
220
221
222
223 public TYPE(final String name)
224 {
225 super();
226 this.name = name;
227 this.hash = 31 + ((this.name == null) ? 0 : this.name.hashCode());
228 }
229
230
231
232
233 public final String getName()
234 {
235 return this.name;
236 }
237
238
239 @Override
240 public final String toString()
241 {
242 return this.name;
243 }
244
245
246 @Override
247 @SuppressWarnings("checkstyle:designforextension")
248 public int hashCode()
249 {
250 return this.hash;
251 }
252
253
254 @Override
255 @SuppressWarnings({ "checkstyle:designforextension", "checkstyle:needbraces" })
256 public boolean equals(final Object obj)
257 {
258 if (this == obj)
259 return true;
260 if (obj == null)
261 return false;
262 if (getClass() != obj.getClass())
263 return false;
264 TYPE other = (TYPE) obj;
265 if (this.name == null)
266 {
267 if (other.name != null)
268 return false;
269 }
270 else if (!this.name.equals(other.name))
271 return false;
272 return true;
273 }
274
275 }
276
277 }