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 TYPE CENTER_GRAVITY = new TYPE("CENTER_GRAVITY");
56
57
58 public static final RelativePosition REFERENCE_POSITION =
59 new RelativePosition(Length.ZERO, Length.ZERO, Length.ZERO, RelativePosition.REFERENCE);
60
61
62 private final int hash;
63
64
65
66
67
68
69
70 public RelativePosition(final Length dx, final Length dy, final Length dz, final TYPE type)
71 {
72 this.dx = dx;
73 this.dy = dy;
74 this.dz = dz;
75 this.type = type;
76
77 this.hash = calcHashCode();
78 }
79
80
81
82
83 public RelativePositionativePosition.html#RelativePosition">RelativePosition(final RelativePosition p)
84 {
85 this.dx = p.getDx();
86 this.dy = p.getDy();
87 this.dz = p.getDz();
88 this.type = p.getType();
89
90 this.hash = calcHashCode();
91 }
92
93
94
95
96 public final Length getDx()
97 {
98 return this.dx;
99 }
100
101
102
103
104 public final Length getDy()
105 {
106 return this.dy;
107 }
108
109
110
111
112 public final Length getDz()
113 {
114 return this.dz;
115 }
116
117
118
119
120 public final TYPE getType()
121 {
122 return this.type;
123 }
124
125
126 @Override
127 public final String toString()
128 {
129 return "(" + this.dx + ", " + this.dy + ", " + this.dz + "): " + this.type;
130 }
131
132
133
134
135
136 public final int calcHashCode()
137 {
138 final int prime = 31;
139 int result = 1;
140 result = prime * result + ((this.dx == null) ? 0 : this.dx.hashCode());
141 result = prime * result + ((this.dy == null) ? 0 : this.dy.hashCode());
142 result = prime * result + ((this.dz == null) ? 0 : this.dz.hashCode());
143 result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
144 return result;
145 }
146
147
148 @Override
149 @SuppressWarnings("checkstyle:designforextension")
150 public int hashCode()
151 {
152 return this.hash;
153 }
154
155
156 @Override
157 @SuppressWarnings({"checkstyle:designforextension", "checkstyle:needbraces"})
158 public boolean equals(final Object obj)
159 {
160 if (this == obj)
161 return true;
162 if (obj == null)
163 return false;
164 if (getClass() != obj.getClass())
165 return false;
166 RelativePosition../org/opentrafficsim/core/gtu/RelativePosition.html#RelativePosition">RelativePosition other = (RelativePosition) obj;
167 if (this.dx == null)
168 {
169 if (other.dx != null)
170 return false;
171 }
172 else if (!this.dx.equals(other.dx))
173 return false;
174 if (this.dy == null)
175 {
176 if (other.dy != null)
177 return false;
178 }
179 else if (!this.dy.equals(other.dy))
180 return false;
181 if (this.dz == null)
182 {
183 if (other.dz != null)
184 return false;
185 }
186 else if (!this.dz.equals(other.dz))
187 return false;
188 if (this.type == null)
189 {
190 if (other.type != null)
191 return false;
192 }
193 else if (!this.type.equals(other.type))
194 return false;
195 return true;
196 }
197
198
199
200
201
202
203
204
205
206
207
208
209
210 public static class TYPE implements Serializable
211 {
212
213 private static final long serialVersionUID = 20141231L;
214
215
216 private final String name;
217
218
219 private final int hash;
220
221
222
223
224 public TYPE(final String name)
225 {
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 }