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