1 package org.sim0mq.message.types;
2
3 import java.io.Serializable;
4 import java.util.HashMap;
5 import java.util.Map;
6
7 import org.djunits.unit.AbsoluteTemperatureUnit;
8 import org.djunits.unit.AccelerationUnit;
9 import org.djunits.unit.AngleSolidUnit;
10 import org.djunits.unit.AngleUnit;
11 import org.djunits.unit.AreaUnit;
12 import org.djunits.unit.DensityUnit;
13 import org.djunits.unit.DimensionlessUnit;
14 import org.djunits.unit.DirectionUnit;
15 import org.djunits.unit.DurationUnit;
16 import org.djunits.unit.ElectricalChargeUnit;
17 import org.djunits.unit.ElectricalCurrentUnit;
18 import org.djunits.unit.ElectricalPotentialUnit;
19 import org.djunits.unit.ElectricalResistanceUnit;
20 import org.djunits.unit.EnergyUnit;
21 import org.djunits.unit.FlowMassUnit;
22 import org.djunits.unit.FlowVolumeUnit;
23 import org.djunits.unit.ForceUnit;
24 import org.djunits.unit.FrequencyUnit;
25 import org.djunits.unit.LengthUnit;
26 import org.djunits.unit.LinearDensityUnit;
27 import org.djunits.unit.MassUnit;
28 import org.djunits.unit.MoneyPerAreaUnit;
29 import org.djunits.unit.MoneyPerDurationUnit;
30 import org.djunits.unit.MoneyPerEnergyUnit;
31 import org.djunits.unit.MoneyPerLengthUnit;
32 import org.djunits.unit.MoneyPerMassUnit;
33 import org.djunits.unit.MoneyPerVolumeUnit;
34 import org.djunits.unit.MoneyUnit;
35 import org.djunits.unit.PositionUnit;
36 import org.djunits.unit.PowerUnit;
37 import org.djunits.unit.PressureUnit;
38 import org.djunits.unit.SpeedUnit;
39 import org.djunits.unit.TemperatureUnit;
40 import org.djunits.unit.TimeUnit;
41 import org.djunits.unit.TorqueUnit;
42 import org.djunits.unit.Unit;
43 import org.djunits.unit.VolumeUnit;
44
45
46
47
48
49
50
51
52
53
54
55 public class Sim0MQUnitType implements Serializable
56 {
57
58 private static final long serialVersionUID = 20170304L;
59
60
61 private static Map<Byte, Sim0MQUnitType> byteTypeMap = new HashMap<>();
62
63
64 private static Map<Class<? extends Unit<?>>, Sim0MQUnitType> unitTypeMap = new HashMap<>();
65
66
67 public static final Sim0MQUnitType DIMENSIONLESS =
68 new Sim0MQUnitType(0, DimensionlessUnit.class, "Dimensionless", "Unit without a dimension", "[]");
69
70
71 public static final Sim0MQUnitType ACCELERATION =
72 new Sim0MQUnitType(1, AccelerationUnit.class, "Acceleration", "Acceleration", "[m/s^2]");
73
74
75 public static final Sim0MQUnitType ANGLESOLID =
76 new Sim0MQUnitType(2, AngleSolidUnit.class, "AngleSolid", "Solid angle ", "[steradian]");
77
78
79 public static final Sim0MQUnitType ANGLE = new Sim0MQUnitType(3, AngleUnit.class, "Angle", "Angle (relative)", "[rad]");
80
81
82 public static final Sim0MQUnitType DIRECTION =
83 new Sim0MQUnitType(4, DirectionUnit.class, "Direction", "Angle (absolute)", "[rad]");
84
85
86 public static final Sim0MQUnitType AREA = new Sim0MQUnitType(5, AreaUnit.class, "Area", "Area", "[m^2]");
87
88
89 public static final Sim0MQUnitType DENSITY =
90 new Sim0MQUnitType(6, DensityUnit.class, "Density", "Density based on mass and length", "[kg/m^3]");
91
92
93 public static final Sim0MQUnitType ELECTRICALCHARGE =
94 new Sim0MQUnitType(7, ElectricalChargeUnit.class, "ElectricalCharge", "Electrical charge (Coulomb)", "[sA]");
95
96
97 public static final Sim0MQUnitType ELECTRICALCURRENT =
98 new Sim0MQUnitType(8, ElectricalCurrentUnit.class, "ElectricalCurrent", "Electrical current (Ampere)", "[A]");
99
100
101 public static final Sim0MQUnitType ELECTRICALPOTENTIAL = new Sim0MQUnitType(9, ElectricalPotentialUnit.class,
102 "ElectricalPotential", "Electrical potential (Volt)", "[kgm^2/s^3A]");
103
104
105 public static final Sim0MQUnitType ELECTRICALRESISTANCE = new Sim0MQUnitType(10, ElectricalResistanceUnit.class,
106 "ElectricalResistance", "Electrical resistance (Ohm)", "[kgm^2/s^3A^2]");
107
108
109 public static final Sim0MQUnitType ENERGY =
110 new Sim0MQUnitType(11, EnergyUnit.class, "Energy", "Energy (Joule)", "[kgm^2/s^2]");
111
112
113 public static final Sim0MQUnitType FLOWMASS =
114 new Sim0MQUnitType(12, FlowMassUnit.class, "FlowMass", "Mass flow rate ", "[kg/s]");
115
116
117 public static final Sim0MQUnitType FLOWVOLUME =
118 new Sim0MQUnitType(13, FlowVolumeUnit.class, "FlowVolume", "Volume flow rate", "[m^3/s]");
119
120
121 public static final Sim0MQUnitType FORCE = new Sim0MQUnitType(14, ForceUnit.class, "Force", "Force (Newton)", "[kgm/s^2]");
122
123
124 public static final Sim0MQUnitType FREQUENCY =
125 new Sim0MQUnitType(15, FrequencyUnit.class, "Frequency", "Frequency (Hz)", "[1/s]");
126
127
128 public static final Sim0MQUnitType LENGTH = new Sim0MQUnitType(16, LengthUnit.class, "Length", "Length (relative)", "[m]");
129
130
131 public static final Sim0MQUnitType POSITION =
132 new Sim0MQUnitType(17, PositionUnit.class, "Position", "Length (absolute)", "[m]");
133
134
135 public static final Sim0MQUnitType LINEARDENSITY =
136 new Sim0MQUnitType(18, LinearDensityUnit.class, "LinearDensity", "Linear density ", "[1/m]");
137
138
139 public static final Sim0MQUnitType MASS = new Sim0MQUnitType(19, MassUnit.class, "Mass", "Mass", "[kg]");
140
141
142 public static final Sim0MQUnitType POWER = new Sim0MQUnitType(20, PowerUnit.class, "Power", "Power (Watt)", "[kgm^2/s^3]");
143
144
145 public static final Sim0MQUnitType PRESSURE =
146 new Sim0MQUnitType(21, PressureUnit.class, "Pressure", "Pressure (Pascal)", "[kg/ms^2]");
147
148
149 public static final Sim0MQUnitType SPEED = new Sim0MQUnitType(22, SpeedUnit.class, "Speed", "Speed", "[m/s]");
150
151
152 public static final Sim0MQUnitType TEMPERATURE =
153 new Sim0MQUnitType(23, TemperatureUnit.class, "Temperature", "Temperature (relative)", "[K]");
154
155
156 public static final Sim0MQUnitType ABSOLUTETEMPERATURE =
157 new Sim0MQUnitType(24, AbsoluteTemperatureUnit.class, "AbsoluteTemperature", "Temperature (absolute)", "[K]");
158
159
160 public static final Sim0MQUnitType DURATION = new Sim0MQUnitType(25, DurationUnit.class, "Duration", "Time (relative)", "[s]");
161
162
163 public static final Sim0MQUnitType TIME = new Sim0MQUnitType(26, TimeUnit.class, "Time", "Time (absolute)", "[s]");
164
165
166 public static final Sim0MQUnitType TORQUE =
167 new Sim0MQUnitType(27, TorqueUnit.class, "Torque", "Torque (Newton-meter)", "[kgm^2/s^2]");
168
169
170 public static final Sim0MQUnitType VOLUME = new Sim0MQUnitType(28, VolumeUnit.class, "Volume", "Volume", "[m^3]");
171
172
173 public static final Sim0MQUnitType MONEY =
174 new Sim0MQUnitType(100, MoneyUnit.class, "Money", "Money (cost in e.g., $, €, ...)", "[$]");
175
176
177 public static final Sim0MQUnitType MONEYPERAREA =
178 new Sim0MQUnitType(101, MoneyPerAreaUnit.class, "MoneyPerArea", "Money/Area (cost/m^2)", "[$/m^2]");
179
180
181 public static final Sim0MQUnitType MONEYPERENERGY =
182 new Sim0MQUnitType(102, MoneyPerEnergyUnit.class, "MoneyPerEnergy", "Money/Energy (cost/W)", "[$s^3/kgm^2]");
183
184
185 public static final Sim0MQUnitType MONEYPERLENGTH =
186 new Sim0MQUnitType(103, MoneyPerLengthUnit.class, "MoneyPerLength", "Money/Length (cost/m)", "[$/m]");
187
188
189 public static final Sim0MQUnitType MONEYPERMASS =
190 new Sim0MQUnitType(104, MoneyPerMassUnit.class, "MoneyPerMass", "Money/Mass (cost/kg)", "[$/kg]");
191
192
193 public static final Sim0MQUnitType MONEYPERDURATION =
194 new Sim0MQUnitType(105, MoneyPerDurationUnit.class, "MoneyPerDuration", "Money/Duration (cost/s)", "[$/s]");
195
196
197 public static final Sim0MQUnitType MONEYPERVOLUME =
198 new Sim0MQUnitType(106, MoneyPerVolumeUnit.class, "MoneyPerVolume", "Money/Volume (cost/m^3)", "[$/m^3]");
199
200
201 private final byte code;
202
203
204 private final Class<? extends Unit<?>> djunitsType;
205
206
207 private final String name;
208
209
210 private final String description;
211
212
213 private final String siUnit;
214
215
216
217
218
219
220
221
222
223 public <U extends Unit<U>> Sim0MQUnitType(final int code, final Class<U> djunitsType, final String name,
224 final String description, final String siUnit)
225 {
226 super();
227 this.code = (byte) code;
228 this.djunitsType = djunitsType;
229 this.name = name;
230 this.description = description;
231 this.siUnit = siUnit;
232
233 byteTypeMap.put(this.code, this);
234 unitTypeMap.put(this.djunitsType, this);
235 }
236
237
238
239
240
241
242 public static Sim0MQUnitType getUnitType(final byte code)
243 {
244 return byteTypeMap.get(code);
245 }
246
247
248
249
250
251
252 public static Class<? extends Unit<?>> getUnitClass(final byte code)
253 {
254 Sim0MQUnitType type = byteTypeMap.get(code);
255 return type == null ? null : type.getDjunitsType();
256 }
257
258
259
260
261
262
263
264 public static <U extends Unit<U>> Sim0MQUnitType getUnitType(final U unit)
265 {
266 return unitTypeMap.get(unit.getClass());
267 }
268
269
270
271
272
273
274
275 public static <U extends Unit<U>> byte getUnitCode(final U unit)
276 {
277 Sim0MQUnitType type = unitTypeMap.get(unit.getClass());
278 return type == null ? null : type.getCode();
279 }
280
281
282
283
284 public final byte getCode()
285 {
286 return this.code;
287 }
288
289
290
291
292 public final Class<? extends Unit<?>> getDjunitsType()
293 {
294 return this.djunitsType;
295 }
296
297
298
299
300 public final String getName()
301 {
302 return this.name;
303 }
304
305
306
307
308 public final String getDescription()
309 {
310 return this.description;
311 }
312
313
314
315
316 public final String getSiUnit()
317 {
318 return this.siUnit;
319 }
320
321
322 @Override
323 @SuppressWarnings("checkstyle:designforextension")
324 public int hashCode()
325 {
326 final int prime = 31;
327 int result = 1;
328 result = prime * result + this.code;
329 result = prime * result + ((this.description == null) ? 0 : this.description.hashCode());
330 result = prime * result + ((this.djunitsType == null) ? 0 : this.djunitsType.hashCode());
331 result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
332 result = prime * result + ((this.siUnit == null) ? 0 : this.siUnit.hashCode());
333 return result;
334 }
335
336
337 @Override
338 @SuppressWarnings({ "checkstyle:designforextension", "needbraces" })
339 public boolean equals(final Object obj)
340 {
341 if (this == obj)
342 return true;
343 if (obj == null)
344 return false;
345 if (getClass() != obj.getClass())
346 return false;
347 Sim0MQUnitType other = (Sim0MQUnitType) obj;
348 if (this.code != other.code)
349 return false;
350 if (this.description == null)
351 {
352 if (other.description != null)
353 return false;
354 }
355 else if (!this.description.equals(other.description))
356 return false;
357 if (this.djunitsType == null)
358 {
359 if (other.djunitsType != null)
360 return false;
361 }
362 else if (!this.djunitsType.equals(other.djunitsType))
363 return false;
364 if (this.name == null)
365 {
366 if (other.name != null)
367 return false;
368 }
369 else if (!this.name.equals(other.name))
370 return false;
371 if (this.siUnit == null)
372 {
373 if (other.siUnit != null)
374 return false;
375 }
376 else if (!this.siUnit.equals(other.siUnit))
377 return false;
378 return true;
379 }
380
381
382 @Override
383 @SuppressWarnings("checkstyle:designforextension")
384 public String toString()
385 {
386 return "Sim0MQUnitType [code=" + this.code + ", name=" + this.name + ", description=" + this.description + ", siUnit="
387 + this.siUnit + "]";
388 }
389
390 }