1 package org.djunits.unit;
2
3 import static org.djunits.unit.unitsystem.UnitSystem.SI_DERIVED;
4
5 import org.djunits.unit.unitsystem.UnitSystem;
6
7
8
9
10
11
12
13
14
15
16
17 public class DensityUnit extends LinearUnit<DensityUnit>
18 {
19
20 private static final long serialVersionUID = 20140607L;
21
22
23 private final MassUnit massUnit;
24
25
26 private final LengthUnit lengthUnit;
27
28
29 public static final DensityUnit SI;
30
31
32 public static final DensityUnit KG_PER_METER_3;
33
34
35 public static final DensityUnit GRAM_PER_CENTIMETER_3;
36
37 static
38 {
39 SI = new DensityUnit(MassUnit.KILOGRAM, LengthUnit.METER, "DensityUnit.kg/m^3", SI_DERIVED);
40 KG_PER_METER_3 = SI;
41 GRAM_PER_CENTIMETER_3 = new DensityUnit(MassUnit.GRAM, LengthUnit.CENTIMETER, "DensityUnit.g/cm^3", SI_DERIVED);
42 }
43
44
45
46
47
48
49
50
51 private DensityUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final String abbreviationKey,
52 final UnitSystem unitSystem)
53 {
54 super(abbreviationKey, unitSystem, KG_PER_METER_3,
55 massUnit.getScaleFactor() / Math.pow(lengthUnit.getScaleFactor(), 3.0));
56 this.massUnit = massUnit;
57 this.lengthUnit = lengthUnit;
58 }
59
60
61
62
63
64
65
66
67
68 public DensityUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final String name, final String abbreviation,
69 final UnitSystem unitSystem)
70 {
71 super(name, abbreviation, unitSystem, KG_PER_METER_3,
72 massUnit.getScaleFactor() / Math.pow(lengthUnit.getScaleFactor(), 3.0));
73 this.massUnit = massUnit;
74 this.lengthUnit = lengthUnit;
75 }
76
77
78
79
80
81
82
83
84
85 private DensityUnit(final String abbreviationKey, final UnitSystem unitSystem, final DensityUnit referenceUnit,
86 final double scaleFactorToReferenceUnit)
87 {
88 super(abbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
89 this.massUnit = referenceUnit.getMassUnit();
90 this.lengthUnit = referenceUnit.getLengthUnit();
91 }
92
93
94
95
96
97
98
99
100
101
102 public DensityUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
103 final DensityUnit referenceUnit, final double scaleFactorToReferenceUnit)
104 {
105 super(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
106 this.massUnit = referenceUnit.getMassUnit();
107 this.lengthUnit = referenceUnit.getLengthUnit();
108 }
109
110
111
112
113 public final MassUnit getMassUnit()
114 {
115 return this.massUnit;
116 }
117
118
119
120
121 public final LengthUnit getLengthUnit()
122 {
123 return this.lengthUnit;
124 }
125
126
127 @Override
128 public final DensityUnit getStandardUnit()
129 {
130 return KG_PER_METER_3;
131 }
132
133
134 @Override
135 public final String getSICoefficientsString()
136 {
137 return "kg/m3";
138 }
139
140 }