1 package org.djunits.unit;
2
3 import org.djunits.unit.quantity.Quantity;
4 import org.djunits.unit.scale.IdentityScale;
5 import org.djunits.unit.si.SIPrefixes;
6 import org.djunits.unit.unitsystem.UnitSystem;
7
8
9
10
11
12
13
14
15
16 public class VolumeUnit extends Unit<VolumeUnit>
17 {
18
19 private static final long serialVersionUID = 20140604L;
20
21
22 public static final Quantity<VolumeUnit> BASE = new Quantity<>("Volume", "m3");
23
24
25 public static final VolumeUnit SI =
26 new VolumeUnit().build(new Unit.Builder<VolumeUnit>().setQuantity(BASE).setId("m^3").setName("cubic meter")
27 .setUnitSystem(UnitSystem.SI_DERIVED).setSiPrefixes(SIPrefixes.UNIT, 3.0).setScale(IdentityScale.SCALE));
28
29
30 public static final VolumeUnit CUBIC_METER = SI;
31
32
33 public static final VolumeUnit CUBIC_MILLIMETER = CUBIC_METER.deriveLinear(1.0E-9, "mm^3", "cubic millimeter");
34
35
36 public static final VolumeUnit CUBIC_CENTIMETER = CUBIC_METER.deriveLinear(1.0E-6, "cm^3", "cubic centimeter");
37
38
39 public static final VolumeUnit CUBIC_DECIMETER = CUBIC_METER.deriveLinear(1.0E-3, "dm^3", "cubic decimeter");
40
41
42 public static final VolumeUnit CUBIC_DECAMETER = CUBIC_METER.deriveLinear(1.0E3, "dam^3", "cubic decameter");
43
44
45 public static final VolumeUnit CUBIC_HECTOMETER = CUBIC_METER.deriveLinear(1.0E6, "hm^3", "cubic hectometer");
46
47
48 public static final VolumeUnit CUBIC_KILOMETER = CUBIC_METER.deriveLinear(1.0E9, "km^3", "cubic kilometer");
49
50
51 public static final VolumeUnit CUBIC_MILE =
52 CUBIC_METER.deriveLinear(cubedLength(LengthUnit.MILE), "mi^3", "cubic mile", UnitSystem.IMPERIAL);
53
54
55 public static final VolumeUnit CUBIC_NAUTICAL_MILE =
56 CUBIC_METER.deriveLinear(cubedLength(LengthUnit.NAUTICAL_MILE), "NM^3", "cubic Nautical Mile", UnitSystem.OTHER);
57
58
59 public static final VolumeUnit CUBIC_FOOT =
60 CUBIC_METER.deriveLinear(cubedLength(LengthUnit.FOOT), "ft^3", "cubic foot", UnitSystem.IMPERIAL);
61
62
63 public static final VolumeUnit CUBIC_INCH =
64 CUBIC_METER.deriveLinear(cubedLength(LengthUnit.INCH), "in^3", "cubic inch", UnitSystem.IMPERIAL);
65
66
67 public static final VolumeUnit CUBIC_YARD =
68 CUBIC_METER.deriveLinear(cubedLength(LengthUnit.YARD), "yd^3", "cubic yard", UnitSystem.IMPERIAL);
69
70
71 public static final VolumeUnit LITER = CUBIC_DECIMETER.deriveLinear(1.0, "L", "liter", UnitSystem.SI_ACCEPTED);
72
73
74 public static final VolumeUnit GALLON_US =
75 CUBIC_INCH.deriveLinear(231.0, "gal(US)", "gallon (US)", UnitSystem.US_CUSTOMARY);
76
77
78 public static final VolumeUnit GALLON_IMP = LITER.deriveLinear(4.54609, "gal(imp)", "gallon (imp)", UnitSystem.IMPERIAL);
79
80
81 public static final VolumeUnit QUART_US = GALLON_US.deriveLinear(0.25, "qt(US)", "quart (US)");
82
83
84 public static final VolumeUnit QUART_IMP = GALLON_IMP.deriveLinear(0.25, "qt(imp)", "quart (imp)");
85
86
87 public static final VolumeUnit PINT_US = QUART_US.deriveLinear(0.5, "pt(US)", "pint (US)");
88
89
90 public static final VolumeUnit PINT_IMP = QUART_IMP.deriveLinear(0.5, "pt(imp)", "pint (imp)");
91
92
93 public static final VolumeUnit FLUID_OUNCE_US = PINT_US.deriveLinear(1.0 / 16.0, "fl.oz(US)", "fluid ounce (US)");
94
95
96 public static final VolumeUnit FLUID_OUNCE_IMP = PINT_IMP.deriveLinear(1.0 / 20.0, "fl.oz(imp)", "fluid ounce (imp)");
97
98
99 public static final VolumeUnit CUBIC_LIGHTYEAR =
100 CUBIC_METER.deriveLinear(cubedLength(LengthUnit.LIGHTYEAR), "ly^3", "cubic lightyear", UnitSystem.OTHER);
101
102
103 public static final VolumeUnit CUBIC_PARSEC =
104 CUBIC_METER.deriveLinear(cubedLength(LengthUnit.PARSEC), "pc^3", "cubic Parsec", UnitSystem.OTHER);
105
106
107
108
109
110
111 private static double cubedLength(final LengthUnit lu)
112 {
113 double factor = lu.getScale().toStandardUnit(1.0);
114 return factor * factor * factor;
115 }
116
117 }