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.m/s", SI_DERIVED);
78 METER_PER_SECOND = SI;
79 METER_PER_HOUR = new SpeedUnit(LengthUnit.METER, DurationUnit.HOUR, "SpeedUnit.m/h", SI_DERIVED);
80 KM_PER_SECOND = new SpeedUnit(LengthUnit.KILOMETER, DurationUnit.SECOND, "SpeedUnit.km/s", SI_DERIVED);
81 KM_PER_HOUR = new SpeedUnit(LengthUnit.KILOMETER, DurationUnit.HOUR, "SpeedUnit.km/h", SI_DERIVED);
82 INCH_PER_SECOND = new SpeedUnit(LengthUnit.INCH, DurationUnit.SECOND, "SpeedUnit.in/s", IMPERIAL);
83 INCH_PER_MINUTE = new SpeedUnit(LengthUnit.INCH, DurationUnit.MINUTE, "SpeedUnit.in/min", IMPERIAL);
84 INCH_PER_HOUR = new SpeedUnit(LengthUnit.INCH, DurationUnit.HOUR, "SpeedUnit.in/h", IMPERIAL);
85 FOOT_PER_SECOND = new SpeedUnit(LengthUnit.FOOT, DurationUnit.SECOND, "SpeedUnit.fps", IMPERIAL);
86 FOOT_PER_MINUTE = new SpeedUnit(LengthUnit.FOOT, DurationUnit.MINUTE, "SpeedUnit.ft/min", IMPERIAL);
87 FOOT_PER_HOUR = new SpeedUnit(LengthUnit.FOOT, DurationUnit.HOUR, "SpeedUnit.ft/h", IMPERIAL);
88 MILE_PER_SECOND = new SpeedUnit(LengthUnit.MILE, DurationUnit.SECOND, "SpeedUnit.mi/s", IMPERIAL);
89 MILE_PER_MINUTE = new SpeedUnit(LengthUnit.MILE, DurationUnit.MINUTE, "SpeedUnit.mi/min", IMPERIAL);
90 MILE_PER_HOUR = new SpeedUnit(LengthUnit.MILE, DurationUnit.HOUR, "SpeedUnit.mph", IMPERIAL);
91 KNOT = new SpeedUnit(LengthUnit.NAUTICAL_MILE, DurationUnit.HOUR, "SpeedUnit.kt", IMPERIAL);
92 }
93
94
95
96
97
98
99
100
101 private SpeedUnit(final LengthUnit lengthUnit, final DurationUnit durationUnit, final String abbreviationKey,
102 final UnitSystem unitSystem)
103 {
104 super(abbreviationKey, unitSystem, METER_PER_SECOND, lengthUnit.getScaleFactor() / durationUnit.getScaleFactor());
105 this.lengthUnit = lengthUnit;
106 this.durationUnit = durationUnit;
107 }
108
109
110
111
112
113
114
115
116
117 public SpeedUnit(final LengthUnit lengthUnit, final DurationUnit durationUnit, final String name, final String abbreviation,
118 final UnitSystem unitSystem)
119 {
120 super(name, abbreviation, unitSystem, METER_PER_SECOND, lengthUnit.getScaleFactor() / durationUnit.getScaleFactor());
121 this.lengthUnit = lengthUnit;
122 this.durationUnit = durationUnit;
123 }
124
125
126
127
128
129
130
131
132
133 private SpeedUnit(final String abbreviationKey, final UnitSystem unitSystem, final SpeedUnit referenceUnit,
134 final double scaleFactorToReferenceUnit)
135 {
136 super(abbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
137 this.lengthUnit = referenceUnit.getLengthUnit();
138 this.durationUnit = referenceUnit.getDurationUnit();
139 }
140
141
142
143
144
145
146
147
148
149
150 public SpeedUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final SpeedUnit referenceUnit,
151 final double scaleFactorToReferenceUnit)
152 {
153 super(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
154 this.lengthUnit = referenceUnit.getLengthUnit();
155 this.durationUnit = referenceUnit.getDurationUnit();
156 }
157
158
159
160
161 public final LengthUnit getLengthUnit()
162 {
163 return this.lengthUnit;
164 }
165
166
167
168
169 public final DurationUnit getDurationUnit()
170 {
171 return this.durationUnit;
172 }
173
174
175 @Override
176 public final SpeedUnit getStandardUnit()
177 {
178 return METER_PER_SECOND;
179 }
180
181
182 @Override
183 public final String getSICoefficientsString()
184 {
185 return "m/s";
186 }
187
188 }