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