1 package org.opentrafficsim.core.gtu;
2
3 import java.io.Serializable;
4
5 import org.opentrafficsim.core.unit.LengthUnit;
6 import org.opentrafficsim.core.value.vdouble.scalar.DoubleScalar;
7
8
9
10
11
12
13
14
15
16
17 public class RelativePosition implements Serializable
18 {
19
20 private static final long serialVersionUID = 20141231L;
21
22
23 private final DoubleScalar.Rel<LengthUnit> dx;
24
25
26 private final DoubleScalar.Rel<LengthUnit> dy;
27
28
29 private final DoubleScalar.Rel<LengthUnit> dz;
30
31
32 private final TYPE type;
33
34
35 public static final TYPE FRONT = new TYPE("FRONT");
36
37
38 public static final TYPE REAR = new TYPE("REAR");
39
40
41 public static final TYPE CENTER = new TYPE("CENTER");
42
43
44 public static final TYPE REFERENCE = new TYPE("REFERENCE");
45
46
47 public static final TYPE DRIVER = new TYPE("DRIVER");
48
49
50 public static final RelativePosition REFERENCE_POSITION = new RelativePosition(new DoubleScalar.Rel<LengthUnit>(0.0d,
51 LengthUnit.METER), new DoubleScalar.Rel<LengthUnit>(0.0d, LengthUnit.METER), new DoubleScalar.Rel<LengthUnit>(0.0d,
52 LengthUnit.METER), RelativePosition.REFERENCE);
53
54
55
56
57
58
59
60 public RelativePosition(final DoubleScalar.Rel<LengthUnit> dx, final DoubleScalar.Rel<LengthUnit> dy,
61 final DoubleScalar.Rel<LengthUnit> 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().copy();
77 this.dy = p.getDy().copy();
78 this.dz = p.getDz().copy();
79 this.type = p.getType();
80 }
81
82
83
84
85 public final DoubleScalar.Rel<LengthUnit> getDx()
86 {
87 return this.dx;
88 }
89
90
91
92
93 public final DoubleScalar.Rel<LengthUnit> getDy()
94 {
95 return this.dy;
96 }
97
98
99
100
101 public final DoubleScalar.Rel<LengthUnit> 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 public static class TYPE implements Serializable
190 {
191
192 private static final long serialVersionUID = 20141231L;
193
194
195 private final String name;
196
197
198
199
200 public TYPE(final String name)
201 {
202 super();
203 this.name = name;
204 }
205
206
207
208
209 public final String getName()
210 {
211 return this.name;
212 }
213
214
215 @Override
216 public final String toString()
217 {
218 return this.name;
219 }
220
221
222 @Override
223 @SuppressWarnings("checkstyle:designforextension")
224 public int hashCode()
225 {
226 final int prime = 31;
227 int result = 1;
228 result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
229 return result;
230 }
231
232
233 @Override
234 @SuppressWarnings({"checkstyle:designforextension", "checkstyle:needbraces"})
235 public boolean equals(final Object obj)
236 {
237 if (this == obj)
238 return true;
239 if (obj == null)
240 return false;
241 if (getClass() != obj.getClass())
242 return false;
243 TYPE other = (TYPE) obj;
244 if (this.name == null)
245 {
246 if (other.name != null)
247 return false;
248 }
249 else if (!this.name.equals(other.name))
250 return false;
251 return true;
252 }
253
254 }
255 }