1 package org.opentrafficsim.road.gtu.lane.perception;
2
3 import java.io.Serializable;
4 import java.util.HashMap;
5 import java.util.Map;
6
7 import org.djunits.value.vdouble.scalar.Speed;
8 import org.djutils.exceptions.Throw;
9 import org.opentrafficsim.base.parameters.Parameters;
10 import org.opentrafficsim.core.gtu.GTUType;
11 import org.opentrafficsim.road.gtu.lane.tactical.following.CarFollowingModel;
12 import org.opentrafficsim.road.network.lane.LaneType;
13
14
15
16
17
18
19
20
21
22
23
24
25 public class GTUTypeAssumptions implements Serializable
26 {
27
28 private static final long serialVersionUID = 20160527L;
29
30
31 private final Map<GTUType, CarFollowingModel> carFollowingModelMap = new HashMap<>();
32
33
34 private final Map<GTUType, Parameters> parametersMap = new HashMap<>();
35
36
37 private final Map<GTUType, Map<LaneType, Speed>> laneTypeSpeedMap = new HashMap<>();
38
39
40
41
42
43
44 public final void setCarFollowingModel(final GTUType gtuType, final CarFollowingModel carFollowingModel)
45 {
46 Throw.whenNull(gtuType, "gtuType cannot be null");
47 Throw.whenNull(carFollowingModel, "carFollowingModel cannot be null");
48 this.carFollowingModelMap.put(gtuType, carFollowingModel);
49 }
50
51
52
53
54
55
56 public final void setParameters(final GTUType gtuType, final Parameters parameters)
57 {
58 Throw.whenNull(gtuType, "gtuType cannot be null");
59 Throw.whenNull(parameters, "parameters cannot be null");
60 this.parametersMap.put(gtuType, parameters);
61 }
62
63
64
65
66
67
68
69 public final void setLaneTypeMaxSpeed(final GTUType gtuType, final LaneType laneType, final Speed maxSpeed)
70 {
71 Throw.whenNull(gtuType, "gtuType cannot be null");
72 Throw.whenNull(laneType, "laneType cannot be null");
73 Throw.whenNull(maxSpeed, "maxSpeed cannot be null");
74 Map<LaneType, Speed> maxLaneTypeSpeed = this.laneTypeSpeedMap.get(gtuType);
75 if (maxLaneTypeSpeed == null)
76 {
77 maxLaneTypeSpeed = new HashMap<>();
78 this.laneTypeSpeedMap.put(gtuType, maxLaneTypeSpeed);
79 }
80 maxLaneTypeSpeed.put(laneType, maxSpeed);
81 }
82
83
84
85
86
87
88 public final CarFollowingModel getCarFollowingModel(final GTUType gtuType)
89 {
90 return this.carFollowingModelMap.get(gtuType);
91 }
92
93
94
95
96
97
98 public final Parameters getParameters(final GTUType gtuType)
99 {
100 return this.parametersMap.get(gtuType);
101 }
102
103
104
105
106
107
108
109
110 public final Speed getLaneTypeMaxSpeed(final GTUType gtuType, final LaneType laneType)
111 {
112 if (!this.laneTypeSpeedMap.containsKey(gtuType))
113 {
114 return null;
115 }
116 return this.laneTypeSpeedMap.get(gtuType).get(laneType);
117 }
118
119
120
121
122
123
124
125 public final Map<LaneType, Speed> getMaxSpeeds(final GTUType gtuType)
126 {
127 if (!this.laneTypeSpeedMap.containsKey(gtuType))
128 {
129 return null;
130 }
131 Map<LaneType, Speed> maxSpeeds = new HashMap<>();
132 maxSpeeds.putAll(this.laneTypeSpeedMap.get(gtuType));
133 return maxSpeeds;
134 }
135
136
137 @Override
138 public final int hashCode()
139 {
140 final int prime = 31;
141 int result = 1;
142 result = prime * result + ((this.parametersMap == null) ? 0 : this.parametersMap.hashCode());
143 result = prime * result + ((this.carFollowingModelMap == null) ? 0 : this.carFollowingModelMap.hashCode());
144 result = prime * result + ((this.laneTypeSpeedMap == null) ? 0 : this.laneTypeSpeedMap.hashCode());
145 return result;
146 }
147
148
149 @Override
150 @SuppressWarnings("checkstyle:needbraces")
151 public final boolean equals(final Object obj)
152 {
153 if (this == obj)
154 return true;
155 if (obj == null)
156 return false;
157 if (getClass() != obj.getClass())
158 return false;
159 GTUTypeAssumptions other = (GTUTypeAssumptions) obj;
160 if (this.parametersMap == null)
161 {
162 if (other.parametersMap != null)
163 return false;
164 }
165 else if (!this.parametersMap.equals(other.parametersMap))
166 return false;
167 if (this.carFollowingModelMap == null)
168 {
169 if (other.carFollowingModelMap != null)
170 return false;
171 }
172 else if (!this.carFollowingModelMap.equals(other.carFollowingModelMap))
173 return false;
174 if (this.laneTypeSpeedMap == null)
175 {
176 if (other.laneTypeSpeedMap != null)
177 return false;
178 }
179 else if (!this.laneTypeSpeedMap.equals(other.laneTypeSpeedMap))
180 return false;
181 return true;
182 }
183
184
185 @Override
186 public final String toString()
187 {
188 return "GTUTypeAssumptions [carFollowingModelMap=" + this.carFollowingModelMap + ", parametersMap=" + this.parametersMap
189 + ", laneTypeSpeedMap=" + this.laneTypeSpeedMap + "]";
190 }
191
192 }