1 package org.opentrafficsim.core.unit;
2
3 import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.IMPERIAL;
4 import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_DERIVED;
5
6 import org.opentrafficsim.core.unit.unitsystem.UnitSystem;
7
8
9
10
11
12
13
14
15
16
17
18 public class SpeedUnit extends Unit<SpeedUnit>
19 {
20
21 private static final long serialVersionUID = 20140607L;
22
23
24 private final LengthUnit lengthUnit;
25
26
27 private final TimeUnit timeUnit;
28
29
30 public static final SpeedUnit SI;
31
32
33 public static final SpeedUnit METER_PER_SECOND;
34
35
36 public static final SpeedUnit KM_PER_HOUR;
37
38
39 public static final SpeedUnit MILE_PER_HOUR;
40
41
42 public static final SpeedUnit FOOT_PER_SECOND;
43
44
45 public static final SpeedUnit KNOT;
46
47 static
48 {
49 SI =
50 new SpeedUnit(LengthUnit.METER, TimeUnit.SECOND, "SpeedUnit.meter_per_second", "SpeedUnit.m/s",
51 SI_DERIVED);
52 METER_PER_SECOND = SI;
53 KM_PER_HOUR =
54 new SpeedUnit(LengthUnit.KILOMETER, TimeUnit.HOUR, "SpeedUnit.kilometer_per_hour", "SpeedUnit.km/h",
55 SI_DERIVED);
56 MILE_PER_HOUR =
57 new SpeedUnit(LengthUnit.MILE, TimeUnit.HOUR, "SpeedUnit.mile_per_hour", "SpeedUnit.mph", IMPERIAL);
58 FOOT_PER_SECOND =
59 new SpeedUnit(LengthUnit.FOOT, TimeUnit.SECOND, "SpeedUnit.foot_per_second", "SpeedUnit.fps", IMPERIAL);
60 KNOT = new SpeedUnit(LengthUnit.NAUTICAL_MILE, TimeUnit.HOUR, "SpeedUnit.knot", "SpeedUnit.kt", IMPERIAL);
61 }
62
63
64
65
66
67
68
69
70
71 public SpeedUnit(final LengthUnit lengthUnit, final TimeUnit timeUnit, final String nameKey,
72 final String abbreviationKey, final UnitSystem unitSystem)
73 {
74 super(nameKey, abbreviationKey, unitSystem, METER_PER_SECOND, lengthUnit.getConversionFactorToStandardUnit()
75 / timeUnit.getConversionFactorToStandardUnit(), true);
76 this.lengthUnit = lengthUnit;
77 this.timeUnit = timeUnit;
78 }
79
80
81
82
83
84
85
86
87
88
89 public SpeedUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
90 final SpeedUnit referenceUnit, final double conversionFactorToReferenceUnit)
91 {
92 super(nameKey, abbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit, true);
93 this.lengthUnit = referenceUnit.getLengthUnit();
94 this.timeUnit = referenceUnit.getTimeUnit();
95 }
96
97
98
99
100 public final LengthUnit getLengthUnit()
101 {
102 return this.lengthUnit;
103 }
104
105
106
107
108 public final TimeUnit getTimeUnit()
109 {
110 return this.timeUnit;
111 }
112
113
114 @Override
115 public final SpeedUnit getStandardUnit()
116 {
117 return METER_PER_SECOND;
118 }
119
120
121 @Override
122 public final String getSICoefficientsString()
123 {
124 return "m/s";
125 }
126
127 }