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