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
20
21
22
23 public record RelativePosition(Length dx, Length dy, Length dz, Type type) implements Serializable
24 {
25
26
27 private static final long serialVersionUID = 20141231L;
28
29
30 public static final Type FRONT = new Type("FRONT");
31
32
33 public static final Type REAR = new Type("REAR");
34
35
36 public static final Type CENTER = new Type("CENTER");
37
38
39 public static final Type REFERENCE = new Type("REFERENCE");
40
41
42 public static final Type DRIVER = new Type("DRIVER");
43
44
45 public static final Type CONTOUR = new Type("CONTOUR");
46
47
48 public static final RelativePosition REFERENCE_POSITION =
49 new RelativePosition(Length.ZERO, Length.ZERO, Length.ZERO, RelativePosition.REFERENCE);
50
51
52
53
54 public RelativePosition(final RelativePosition p)
55 {
56 this(p.dx(), p.dy(), p.dz(), p.type());
57 }
58
59
60
61
62
63
64
65
66
67
68
69
70 public static class Type implements Serializable
71 {
72
73 private static final long serialVersionUID = 20141231L;
74
75
76 private final String name;
77
78
79 private final int hash;
80
81
82
83
84 public Type(final String name)
85 {
86 this.name = name;
87 this.hash = 31 + ((this.name == null) ? 0 : this.name.hashCode());
88 }
89
90
91
92
93 public final String getName()
94 {
95 return this.name;
96 }
97
98 @Override
99 public final String toString()
100 {
101 return this.name;
102 }
103
104 @Override
105 @SuppressWarnings("checkstyle:designforextension")
106 public int hashCode()
107 {
108 return this.hash;
109 }
110
111 @Override
112 @SuppressWarnings({"checkstyle:designforextension", "checkstyle:needbraces"})
113 public boolean equals(final Object obj)
114 {
115 if (this == obj)
116 return true;
117 if (obj == null)
118 return false;
119 if (getClass() != obj.getClass())
120 return false;
121 Type other = (Type) obj;
122 if (this.name == null)
123 {
124 if (other.name != null)
125 return false;
126 }
127 else if (!this.name.equals(other.name))
128 return false;
129 return true;
130 }
131
132 }
133
134 }