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