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