1 package org.opentrafficsim.core.unit;
2
3 import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_DERIVED;
4
5 import org.opentrafficsim.core.unit.unitsystem.UnitSystem;
6
7
8
9
10
11
12
13
14
15
16 public class DensityUnit extends Unit<DensityUnit>
17 {
18
19 private static final long serialVersionUID = 20140607L;
20
21
22 private final MassUnit massUnit;
23
24
25 private final LengthUnit lengthUnit;
26
27
28 public static final DensityUnit SI;
29
30
31 public static final DensityUnit KG_PER_METER_3;
32
33
34 public static final DensityUnit GRAM_PER_CENTIMETER_3;
35
36 static
37 {
38 SI =
39 new DensityUnit(MassUnit.KILOGRAM, LengthUnit.METER, "DensityUnit.kilogram_per_cubic_meter",
40 "DensityUnit.kg/m^3", SI_DERIVED);
41 KG_PER_METER_3 = SI;
42 GRAM_PER_CENTIMETER_3 =
43 new DensityUnit(MassUnit.GRAM, LengthUnit.CENTIMETER, "DensityUnit.gram_per_cubic_centimeter",
44 "DensityUnit.g/cm^3", SI_DERIVED);
45 }
46
47
48
49
50
51
52
53
54
55 public DensityUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final String nameKey,
56 final String abbreviationKey, final UnitSystem unitSystem)
57 {
58 super(nameKey, abbreviationKey, unitSystem, KG_PER_METER_3, massUnit.getConversionFactorToStandardUnit()
59 / Math.pow(lengthUnit.getConversionFactorToStandardUnit(), 3.0), true);
60 this.massUnit = massUnit;
61 this.lengthUnit = lengthUnit;
62 }
63
64
65
66
67
68
69
70
71
72 public DensityUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
73 final DensityUnit referenceUnit, final double conversionFactorToReferenceUnit)
74 {
75 super(nameKey, abbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit, true);
76 this.massUnit = referenceUnit.getMassUnit();
77 this.lengthUnit = referenceUnit.getLengthUnit();
78 }
79
80
81
82
83 public final MassUnit getMassUnit()
84 {
85 return this.massUnit;
86 }
87
88
89
90
91 public final LengthUnit getLengthUnit()
92 {
93 return this.lengthUnit;
94 }
95
96
97 @Override
98 public final DensityUnit getStandardUnit()
99 {
100 return KG_PER_METER_3;
101 }
102
103
104 @Override
105 public final String getSICoefficientsString()
106 {
107 return "kg/m3";
108 }
109
110 }