1 package org.djunits.unit;
2
3 import static org.djunits.unit.unitsystem.UnitSystem.IMPERIAL;
4 import static org.djunits.unit.unitsystem.UnitSystem.SI_ACCEPTED;
5 import static org.djunits.unit.unitsystem.UnitSystem.SI_DERIVED;
6 import static org.djunits.unit.unitsystem.UnitSystem.US_CUSTOMARY;
7
8 import org.djunits.unit.unitsystem.UnitSystem;
9
10
11
12
13
14
15
16
17
18
19
20 public class VolumeUnit extends LinearUnit<VolumeUnit>
21 {
22
23 private static final long serialVersionUID = 20140604L;
24
25
26 private final LengthUnit lengthUnit;
27
28
29 public static final VolumeUnit SI;
30
31
32 public static final VolumeUnit CUBIC_ATTOMETER;
33
34
35 public static final VolumeUnit CUBIC_FEMTOMETER;
36
37
38 public static final VolumeUnit CUBIC_PICOMETER;
39
40
41 public static final VolumeUnit CUBIC_NANOMETER;
42
43
44 public static final VolumeUnit CUBIC_MICROMETER;
45
46
47 public static final VolumeUnit CUBIC_MILLIMETER;
48
49
50 public static final VolumeUnit CUBIC_CENTIMETER;
51
52
53 public static final VolumeUnit CUBIC_DECIMETER;
54
55
56 public static final VolumeUnit CUBIC_METER;
57
58
59 public static final VolumeUnit CUBIC_DEKAMETER;
60
61
62 public static final VolumeUnit CUBIC_HECTOMETER;
63
64
65 public static final VolumeUnit CUBIC_KILOMETER;
66
67
68 public static final VolumeUnit CUBIC_MEGAMETER;
69
70
71 public static final VolumeUnit LITER;
72
73
74 public static final VolumeUnit CUBIC_MILE;
75
76
77 public static final VolumeUnit CUBIC_FOOT;
78
79
80 public static final VolumeUnit CUBIC_INCH;
81
82
83 public static final VolumeUnit CUBIC_YARD;
84
85
86 public static final VolumeUnit GALLON_US_FLUID;
87
88
89 public static final VolumeUnit GALLON_IMP;
90
91
92 public static final VolumeUnit OUNCE_US_FLUID;
93
94
95 public static final VolumeUnit OUNCE_IMP_FLUID;
96
97
98 public static final VolumeUnit PINT_US_FLUID;
99
100
101 public static final VolumeUnit PINT_IMP;
102
103
104 public static final VolumeUnit QUART_US_FLUID;
105
106
107 public static final VolumeUnit QUART_IMP;
108
109
110 public static final VolumeUnit CUBIC_LIGHTYEAR;
111
112
113 public static final VolumeUnit CUBIC_PARSEC;
114
115 static
116 {
117 SI = new VolumeUnit(LengthUnit.METER, "VolumeUnit.cubic_meter", "VolumeUnit.m^3", SI_DERIVED, true);
118 CUBIC_METER = SI;
119 CUBIC_ATTOMETER =
120 new VolumeUnit(LengthUnit.ATTOMETER, "VolumeUnit.cubic_attometer", "VolumeUnit.am^3", SI_DERIVED, true);
121 CUBIC_FEMTOMETER =
122 new VolumeUnit(LengthUnit.FEMTOMETER, "VolumeUnit.cubic_femtometer", "VolumeUnit.fm^3", SI_DERIVED, true);
123 CUBIC_PICOMETER =
124 new VolumeUnit(LengthUnit.PICOMETER, "VolumeUnit.cubic_picometer", "VolumeUnit.pm^3", SI_DERIVED, true);
125 CUBIC_NANOMETER =
126 new VolumeUnit(LengthUnit.NANOMETER, "VolumeUnit.cubic_nanometer", "VolumeUnit.nm^3", SI_DERIVED, true);
127 CUBIC_MICROMETER =
128 new VolumeUnit(LengthUnit.MICROMETER, "VolumeUnit.cubic_micrometer", "VolumeUnit.mum^3", SI_DERIVED, true);
129 CUBIC_MILLIMETER =
130 new VolumeUnit(LengthUnit.MILLIMETER, "VolumeUnit.cubic_millimeter", "VolumeUnit.mm^3", SI_DERIVED, true);
131 CUBIC_CENTIMETER =
132 new VolumeUnit(LengthUnit.CENTIMETER, "VolumeUnit.cubic_centimeter", "VolumeUnit.cm^3", SI_DERIVED, true);
133 CUBIC_DECIMETER =
134 new VolumeUnit(LengthUnit.DECIMETER, "VolumeUnit.cubic_decimeter", "VolumeUnit.dm^3", SI_DERIVED, true);
135 CUBIC_DEKAMETER =
136 new VolumeUnit(LengthUnit.DEKAMETER, "VolumeUnit.cubic_dekameter", "VolumeUnit.dam^3", SI_DERIVED, true);
137 CUBIC_HECTOMETER =
138 new VolumeUnit(LengthUnit.HECTOMETER, "VolumeUnit.cubic_hectometer", "VolumeUnit.hm^3", SI_DERIVED, true);
139 CUBIC_KILOMETER =
140 new VolumeUnit(LengthUnit.KILOMETER, "VolumeUnit.cubic_kilometer", "VolumeUnit.km^3", SI_DERIVED, true);
141 CUBIC_MEGAMETER =
142 new VolumeUnit(LengthUnit.MEGAMETER, "VolumeUnit.cubic_megameter", "VolumeUnit.Mm^3", SI_DERIVED, true);
143 LITER = new VolumeUnit("VolumeUnit.liter", "VolumeUnit.L", SI_ACCEPTED, CUBIC_DECIMETER, 1.0, true);
144 CUBIC_MILE = new VolumeUnit(LengthUnit.MILE, "VolumeUnit.cubic_mile", "VolumeUnit.mi^3", IMPERIAL, true);
145 CUBIC_FOOT = new VolumeUnit(LengthUnit.FOOT, "VolumeUnit.cubic_foot", "VolumeUnit.ft^3", IMPERIAL, true);
146 CUBIC_INCH = new VolumeUnit(LengthUnit.INCH, "VolumeUnit.cubic_inch", "VolumeUnit.in^3", IMPERIAL, true);
147 CUBIC_YARD = new VolumeUnit(LengthUnit.YARD, "VolumeUnit.cubic_yard", "VolumeUnit.yd^3", IMPERIAL, true);
148 GALLON_US_FLUID = new VolumeUnit("VolumeUnit.gallon_(US)", "VolumeUnit.gal(US)", US_CUSTOMARY, CUBIC_INCH, 231.0, true);
149 GALLON_IMP = new VolumeUnit("VolumeUnit.gallon_(imp)", "VolumeUnit.gal(imp)", IMPERIAL, LITER, 4.5409, true);
150 OUNCE_US_FLUID = new VolumeUnit("VolumeUnit.ounce_(fluid_US)", "VolumeUnit.US_fl_oz", US_CUSTOMARY, GALLON_US_FLUID,
151 1.0 / 128.0, true);
152 OUNCE_IMP_FLUID = new VolumeUnit("VolumeUnit.ounce_(fluid_imperial)", "VolumeUnit.fl_oz_(imp)", IMPERIAL, GALLON_IMP,
153 1.0 / 160.0, true);
154 PINT_US_FLUID = new VolumeUnit("VolumeUnit.pint_(US_fluid)", "VolumeUnit.pt(US_fl)", US_CUSTOMARY, GALLON_US_FLUID,
155 1.0 / 8.0, true);
156 PINT_IMP = new VolumeUnit("VolumeUnit.pint_(imperial)", "VolumeUnit.pt_(imp)", IMPERIAL, GALLON_IMP, 1.0 / 8.0, true);
157 QUART_US_FLUID = new VolumeUnit("VolumeUnit.quart_(US_fluid)", "VolumeUnit.qt(US_fl)", US_CUSTOMARY, GALLON_US_FLUID,
158 1.0 / 4.0, true);
159 QUART_IMP = new VolumeUnit("VolumeUnit.quart_(imperial)", "VolumeUnit.qt_(imp)", IMPERIAL, GALLON_IMP, 1.0 / 4.0, true);
160 CUBIC_LIGHTYEAR =
161 new VolumeUnit(LengthUnit.LIGHTYEAR, "VolumeUnit.cubic_lightyear", "VolumeUnit.ly^3", SI_DERIVED, true);
162 CUBIC_PARSEC = new VolumeUnit(LengthUnit.PARSEC, "VolumeUnit.cubic_parsec", "VolumeUnit.pc^3", SI_DERIVED, true);
163 }
164
165
166
167
168
169
170
171
172
173
174
175
176 private VolumeUnit(final LengthUnit lengthUnit, final String nameOrNameKey, final String abbreviationOrAbbreviationKey,
177 final UnitSystem unitSystem, final boolean standardUnit)
178 {
179 super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, CUBIC_METER, Math.pow(lengthUnit.getScaleFactor(), 3),
180 standardUnit);
181 this.lengthUnit = lengthUnit;
182 }
183
184
185
186
187
188
189
190
191 public VolumeUnit(final LengthUnit lengthUnit, final String name, final String abbreviation, final UnitSystem unitSystem)
192 {
193 this(lengthUnit, name, abbreviation, unitSystem, false);
194 }
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209 private VolumeUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
210 final VolumeUnit referenceUnit, final double scaleFactorToReferenceUnit, final boolean standardUnit)
211 {
212 super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
213 standardUnit);
214 this.lengthUnit = referenceUnit.getLengthUnit();
215 }
216
217
218
219
220
221
222
223
224
225
226 public VolumeUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final VolumeUnit referenceUnit,
227 final double scaleFactorToReferenceUnit)
228 {
229 this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
230 }
231
232
233
234
235 public final LengthUnit getLengthUnit()
236 {
237 return this.lengthUnit;
238 }
239
240
241 @Override
242 public final VolumeUnit getStandardUnit()
243 {
244 return CUBIC_METER;
245 }
246
247
248 @Override
249 public final String getSICoefficientsString()
250 {
251 return "m3";
252 }
253
254 }