1 package org.djunits.unit;
2
3 import static org.djunits.unit.unitsystem.UnitSystem.IMPERIAL;
4 import static org.djunits.unit.unitsystem.UnitSystem.SI_DERIVED;
5
6 import org.djunits.unit.unitsystem.UnitSystem;
7
8
9
10
11
12
13
14
15
16
17
18
19 public class SpeedUnit extends LinearUnit<SpeedUnit>
20 {
21
22 private static final long serialVersionUID = 20140607L;
23
24
25 private final LengthUnit lengthUnit;
26
27
28 private final DurationUnit durationUnit;
29
30
31 public static final SpeedUnit SI;
32
33
34 public static final SpeedUnit METER_PER_SECOND;
35
36
37 public static final SpeedUnit METER_PER_HOUR;
38
39
40 public static final SpeedUnit KM_PER_SECOND;
41
42
43 public static final SpeedUnit KM_PER_HOUR;
44
45
46 public static final SpeedUnit INCH_PER_SECOND;
47
48
49 public static final SpeedUnit INCH_PER_MINUTE;
50
51
52 public static final SpeedUnit INCH_PER_HOUR;
53
54
55 public static final SpeedUnit FOOT_PER_SECOND;
56
57
58 public static final SpeedUnit FOOT_PER_MINUTE;
59
60
61 public static final SpeedUnit FOOT_PER_HOUR;
62
63
64 public static final SpeedUnit MILE_PER_SECOND;
65
66
67 public static final SpeedUnit MILE_PER_MINUTE;
68
69
70 public static final SpeedUnit MILE_PER_HOUR;
71
72
73 public static final SpeedUnit KNOT;
74
75 static
76 {
77 SI = new SpeedUnit(LengthUnit.METER, DurationUnit.SECOND, "SpeedUnit.meter_per_second", "SpeedUnit.m/s", SI_DERIVED,
78 true);
79 METER_PER_SECOND = SI;
80 METER_PER_HOUR = new SpeedUnit(LengthUnit.METER, DurationUnit.HOUR, "SpeedUnit.meter_per_hour", "SpeedUnit.m/h",
81 SI_DERIVED, true);
82 KM_PER_SECOND = new SpeedUnit(LengthUnit.KILOMETER, DurationUnit.SECOND, "SpeedUnit.kilometer_per_second",
83 "SpeedUnit.km/s", SI_DERIVED, true);
84 KM_PER_HOUR = new SpeedUnit(LengthUnit.KILOMETER, DurationUnit.HOUR, "SpeedUnit.kilometer_per_hour", "SpeedUnit.km/h",
85 SI_DERIVED, true);
86 INCH_PER_SECOND = new SpeedUnit(LengthUnit.INCH, DurationUnit.SECOND, "SpeedUnit.inch_per_second", "SpeedUnit.in/s",
87 IMPERIAL, true);
88 INCH_PER_MINUTE = new SpeedUnit(LengthUnit.INCH, DurationUnit.MINUTE, "SpeedUnit.inch_per_minute", "SpeedUnit.in/min",
89 IMPERIAL, true);
90 INCH_PER_HOUR =
91 new SpeedUnit(LengthUnit.INCH, DurationUnit.HOUR, "SpeedUnit.inch_per_hour", "SpeedUnit.in/h", IMPERIAL, true);
92 FOOT_PER_SECOND = new SpeedUnit(LengthUnit.FOOT, DurationUnit.SECOND, "SpeedUnit.foot_per_second", "SpeedUnit.fps",
93 IMPERIAL, true);
94 FOOT_PER_MINUTE = new SpeedUnit(LengthUnit.FOOT, DurationUnit.MINUTE, "SpeedUnit.foot_per_minute", "SpeedUnit.ft/min",
95 IMPERIAL, true);
96 FOOT_PER_HOUR =
97 new SpeedUnit(LengthUnit.FOOT, DurationUnit.HOUR, "SpeedUnit.foot_per_hour", "SpeedUnit.ft/h", IMPERIAL, true);
98 MILE_PER_SECOND = new SpeedUnit(LengthUnit.MILE, DurationUnit.SECOND, "SpeedUnit.mile_per_second", "SpeedUnit.mi/s",
99 IMPERIAL, true);
100 MILE_PER_MINUTE = new SpeedUnit(LengthUnit.MILE, DurationUnit.MINUTE, "SpeedUnit.mile_per_minute", "SpeedUnit.mi/min",
101 IMPERIAL, true);
102 MILE_PER_HOUR =
103 new SpeedUnit(LengthUnit.MILE, DurationUnit.HOUR, "SpeedUnit.mile_per_hour", "SpeedUnit.mph", IMPERIAL, true);
104 KNOT = new SpeedUnit(LengthUnit.NAUTICAL_MILE, DurationUnit.HOUR, "SpeedUnit.knot", "SpeedUnit.kt", IMPERIAL, true);
105 }
106
107
108
109
110
111
112
113
114
115
116
117
118
119 private SpeedUnit(final LengthUnit lengthUnit, final DurationUnit durationUnit, final String nameOrNameKey,
120 final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
121 {
122 super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, METER_PER_SECOND,
123 lengthUnit.getScaleFactor() / durationUnit.getScaleFactor(), standardUnit);
124 this.lengthUnit = lengthUnit;
125 this.durationUnit = durationUnit;
126 }
127
128
129
130
131
132
133
134
135
136 public SpeedUnit(final LengthUnit lengthUnit, final DurationUnit durationUnit, final String name, final String abbreviation,
137 final UnitSystem unitSystem)
138 {
139 this(lengthUnit, durationUnit, name, abbreviation, unitSystem, false);
140 }
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155 private SpeedUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
156 final SpeedUnit referenceUnit, final double scaleFactorToReferenceUnit, final boolean standardUnit)
157 {
158 super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
159 standardUnit);
160 this.lengthUnit = referenceUnit.getLengthUnit();
161 this.durationUnit = referenceUnit.getDurationUnit();
162 }
163
164
165
166
167
168
169
170
171
172
173 public SpeedUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final SpeedUnit referenceUnit,
174 final double scaleFactorToReferenceUnit)
175 {
176 this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
177 }
178
179
180
181
182 public final LengthUnit getLengthUnit()
183 {
184 return this.lengthUnit;
185 }
186
187
188
189
190 public final DurationUnit getDurationUnit()
191 {
192 return this.durationUnit;
193 }
194
195
196 @Override
197 public final SpeedUnit getStandardUnit()
198 {
199 return METER_PER_SECOND;
200 }
201
202
203 @Override
204 public final String getSICoefficientsString()
205 {
206 return "m/s";
207 }
208
209 }