1 package org.opentrafficsim.core.gtu;
2
3 import java.io.Serializable;
4
5 import org.opentrafficsim.base.Type;
6
7 import nl.tudelft.simulation.language.Throw;
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 public final class GTUType extends Type<GTUType> implements Serializable
23 {
24
25 private static final long serialVersionUID = 20141231L;
26
27
28 private final String id;
29
30
31 private final GTUType parent;
32
33
34 public static final GTUType ALL;
35
36
37 public static final GTUType NONE;
38
39
40 public static final GTUType PEDESTRIAN;
41
42
43 public static final GTUType BIKE;
44
45
46 public static final GTUType VEHICLE;
47
48
49 public static final GTUType BOAT;
50
51
52 public static final GTUType TRAIN;
53
54
55 static
56 {
57 ALL = new GTUType("ALL");
58 NONE = new GTUType("NONE");
59 PEDESTRIAN = new GTUType("PEDESTRIAN", ALL);
60 BIKE = new GTUType("BIKE", ALL);
61 VEHICLE = new GTUType("VEHICLE", ALL);
62 BOAT = new GTUType("BOAT", ALL);
63 TRAIN = new GTUType("TRAIN", ALL);
64 }
65
66
67
68
69
70 private GTUType(final String id) throws NullPointerException
71 {
72 Throw.whenNull(id, "id cannot be null for GTUType");
73 this.id = id;
74 this.parent = null;
75 }
76
77
78
79
80
81
82 public GTUType(final String id, final GTUType parent) throws NullPointerException
83 {
84 Throw.whenNull(id, "id cannot be null for GTUType");
85 this.id = id;
86 this.parent = parent;
87 }
88
89
90
91
92 public String getId()
93 {
94 return this.id;
95 }
96
97
98
99
100 public GTUType getParent()
101 {
102 return this.parent;
103 }
104
105
106
107
108
109
110 public boolean isOfType(final GTUType gtuType)
111 {
112 if (this.equals(gtuType))
113 {
114 return true;
115 }
116 if (this.parent != null)
117 {
118 return this.parent.isOfType(gtuType);
119 }
120 return false;
121 }
122
123
124 public String toString()
125 {
126 return "GTUType: " + this.id;
127 }
128
129
130 @Override
131 public int hashCode()
132 {
133 final int prime = 31;
134 int result = 1;
135 result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
136 result = prime * result + ((this.parent == null) ? 0 : this.parent.hashCode());
137 return result;
138 }
139
140
141 @SuppressWarnings("checkstyle:needbraces")
142 @Override
143 public boolean equals(final Object obj)
144 {
145 if (this == obj)
146 return true;
147 if (obj == null)
148 return false;
149 if (getClass() != obj.getClass())
150 return false;
151 GTUType other = (GTUType) obj;
152 if (!this.id.equals(other.id))
153 return false;
154 if (this.parent == null)
155 if (other.parent != null)
156 return false;
157 else if (!this.parent.equals(other.parent))
158 return false;
159 return true;
160 }
161
162 }