1 package org.djunits.unit;
2
3 import org.djunits.unit.unitsystem.UnitSystem;
4
5
6
7
8
9
10
11
12
13
14
15 public class MoneyPerVolumeUnit extends LinearUnit<MoneyPerVolumeUnit>
16 {
17
18 private static final long serialVersionUID = 20150905L;
19
20
21 private final MoneyUnit moneyUnit;
22
23
24 private final VolumeUnit volumeUnit;
25
26
27 public static final MoneyPerVolumeUnit EUR_PER_CUBIC_METER;
28
29
30 public static final MoneyPerVolumeUnit EUR_PER_LITER;
31
32
33 public static final MoneyPerVolumeUnit USD_PER_GALLON_US_FLUID;
34
35
36 public static final MoneyPerVolumeUnit USD_PER_OUNCE_US_FLUID;
37
38
39 private static MoneyPerVolumeUnit standardMoneyPerVolumeUnit;
40
41 static
42 {
43 EUR_PER_CUBIC_METER =
44 new MoneyPerVolumeUnit(MoneyUnit.EUR, VolumeUnit.CUBIC_METER, "EUR per cubic meter", "\u20AC/m^3", false);
45 EUR_PER_LITER = new MoneyPerVolumeUnit(MoneyUnit.EUR, VolumeUnit.LITER, "EUR per liter", "\u20AC/l", false);
46 USD_PER_GALLON_US_FLUID =
47 new MoneyPerVolumeUnit(MoneyUnit.USD, VolumeUnit.GALLON_US_FLUID, "USD per gallon (US)", "US$/gallon", false);
48 USD_PER_OUNCE_US_FLUID =
49 new MoneyPerVolumeUnit(MoneyUnit.USD, VolumeUnit.OUNCE_US_FLUID, "USD per ounce (US)", "US$/ounce", false);
50 standardMoneyPerVolumeUnit = EUR_PER_CUBIC_METER;
51 }
52
53
54
55
56
57
58
59
60
61
62 private MoneyPerVolumeUnit(final MoneyUnit moneyUnit, final VolumeUnit volumeUnit, final String nameOrNameKey,
63 final String abbreviationOrAbbreviationKey, final boolean standardUnit)
64 {
65 super(nameOrNameKey, abbreviationOrAbbreviationKey, UnitSystem.OTHER, standardMoneyPerVolumeUnit,
66 moneyUnit.getScaleFactor() / volumeUnit.getScaleFactor(), standardUnit);
67 this.moneyUnit = moneyUnit;
68 this.volumeUnit = volumeUnit;
69 }
70
71
72
73
74
75
76
77
78 public MoneyPerVolumeUnit(final MoneyUnit moneyUnit, final VolumeUnit volumeUnit, final String name,
79 final String abbreviation)
80 {
81 this(moneyUnit, volumeUnit, name, abbreviation, false);
82 }
83
84
85
86
87
88
89
90
91
92
93 private MoneyPerVolumeUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey,
94 final MoneyPerVolumeUnit referenceUnit, final double scaleFactorToReferenceUnit, final boolean standardUnit)
95 {
96 super(nameOrNameKey, abbreviationOrAbbreviationKey, UnitSystem.OTHER, referenceUnit, scaleFactorToReferenceUnit,
97 standardUnit);
98 this.moneyUnit = referenceUnit.getMoneyUnit();
99 this.volumeUnit = referenceUnit.getVolumeUnit();
100 }
101
102
103
104
105
106
107
108
109 public MoneyPerVolumeUnit(final String name, final String abbreviation, final MoneyPerVolumeUnit referenceUnit,
110 final double scaleFactorToReferenceUnit)
111 {
112 this(name, abbreviation, referenceUnit, scaleFactorToReferenceUnit, false);
113 }
114
115
116
117
118 public final MoneyUnit getMoneyUnit()
119 {
120 return this.moneyUnit;
121 }
122
123
124
125
126 public final VolumeUnit getVolumeUnit()
127 {
128 return this.volumeUnit;
129 }
130
131
132
133
134
135 protected static void setStandardUnit(final MoneyUnit standardMoneyUnit)
136 {
137 try
138 {
139 standardMoneyPerVolumeUnit = new MoneyPerVolumeUnit(standardMoneyUnit, VolumeUnit.CUBIC_METER,
140 standardMoneyUnit.getName() + " per cubic meter", standardMoneyUnit.getAbbreviation() + "/m^3");
141 }
142 catch (Exception e)
143 {
144
145 e = null;
146 }
147 }
148
149
150 @Override
151 public final MoneyPerVolumeUnit getStandardUnit()
152 {
153 return standardMoneyPerVolumeUnit;
154 }
155
156
157
158
159 public static MoneyPerVolumeUnit getStandardMoneyPerVolumeUnit()
160 {
161 return standardMoneyPerVolumeUnit;
162 }
163
164
165 @Override
166 public final String getSICoefficientsString()
167 {
168 return "1/m3";
169 }
170
171 }