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");
45 EUR_PER_LITER = new MoneyPerVolumeUnit(MoneyUnit.EUR, VolumeUnit.LITER, "EUR per liter", "\u20AC/l");
46 USD_PER_GALLON_US_FLUID =
47 new MoneyPerVolumeUnit(MoneyUnit.USD, VolumeUnit.GALLON_US_FLUID, "USD per gallon (US)", "US$/gallon");
48 USD_PER_OUNCE_US_FLUID =
49 new MoneyPerVolumeUnit(MoneyUnit.USD, VolumeUnit.OUNCE_US_FLUID, "USD per ounce (US)", "US$/ounce");
50 standardMoneyPerVolumeUnit = EUR_PER_CUBIC_METER;
51 }
52
53
54
55
56
57
58
59 private MoneyPerVolumeUnit(final MoneyUnit moneyUnit, final VolumeUnit volumeUnit, final String abbreviationKey)
60 {
61 super(abbreviationKey, UnitSystem.OTHER, standardMoneyPerVolumeUnit,
62 moneyUnit.getScaleFactor() / volumeUnit.getScaleFactor());
63 this.moneyUnit = moneyUnit;
64 this.volumeUnit = volumeUnit;
65 }
66
67
68
69
70
71
72
73
74 public MoneyPerVolumeUnit(final MoneyUnit moneyUnit, final VolumeUnit volumeUnit, final String name,
75 final String abbreviation)
76 {
77 super(name, abbreviation, UnitSystem.OTHER, standardMoneyPerVolumeUnit,
78 moneyUnit.getScaleFactor() / volumeUnit.getScaleFactor());
79 this.moneyUnit = moneyUnit;
80 this.volumeUnit = volumeUnit;
81 }
82
83
84
85
86
87
88
89
90 private MoneyPerVolumeUnit(final String abbreviationKey, final MoneyPerVolumeUnit referenceUnit,
91 final double scaleFactorToReferenceUnit)
92 {
93 super(abbreviationKey, UnitSystem.OTHER, referenceUnit, scaleFactorToReferenceUnit);
94 this.moneyUnit = referenceUnit.getMoneyUnit();
95 this.volumeUnit = referenceUnit.getVolumeUnit();
96 }
97
98
99
100
101
102
103
104
105
106 public MoneyPerVolumeUnit(final String name, final String abbreviation, final MoneyPerVolumeUnit referenceUnit,
107 final double scaleFactorToReferenceUnit)
108 {
109 super(name, abbreviation, UnitSystem.OTHER, referenceUnit, scaleFactorToReferenceUnit);
110 this.moneyUnit = referenceUnit.getMoneyUnit();
111 this.volumeUnit = referenceUnit.getVolumeUnit();
112 }
113
114
115
116
117 public final MoneyUnit getMoneyUnit()
118 {
119 return this.moneyUnit;
120 }
121
122
123
124
125 public final VolumeUnit getVolumeUnit()
126 {
127 return this.volumeUnit;
128 }
129
130
131
132
133
134 protected static void setStandardUnit(final MoneyUnit standardMoneyUnit)
135 {
136 try
137 {
138 standardMoneyPerVolumeUnit = new MoneyPerVolumeUnit(standardMoneyUnit, VolumeUnit.CUBIC_METER,
139 standardMoneyUnit.getName() + " per cubic meter", standardMoneyUnit.getAbbreviation() + "/m^3");
140 }
141 catch (Exception e)
142 {
143
144 e = null;
145 }
146 }
147
148
149 @Override
150 public final MoneyPerVolumeUnit getStandardUnit()
151 {
152 return standardMoneyPerVolumeUnit;
153 }
154
155
156
157
158 public static MoneyPerVolumeUnit getStandardMoneyPerVolumeUnit()
159 {
160 return standardMoneyPerVolumeUnit;
161 }
162
163
164 @Override
165 public final String getSICoefficientsString()
166 {
167 return "1/m3";
168 }
169
170
171 @Override
172 public int hashCode()
173 {
174 final int prime = 31;
175 int result = super.hashCode();
176 result = prime * result + ((this.moneyUnit == null) ? 0 : this.moneyUnit.hashCode());
177 result = prime * result + ((this.volumeUnit == null) ? 0 : this.volumeUnit.hashCode());
178 return result;
179 }
180
181
182 @SuppressWarnings("checkstyle:needbraces")
183 @Override
184 public boolean equals(final Object obj)
185 {
186 if (this == obj)
187 return true;
188 if (!super.equals(obj))
189 return false;
190 if (getClass() != obj.getClass())
191 return false;
192 MoneyPerVolumeUnit other = (MoneyPerVolumeUnit) obj;
193 if (this.moneyUnit == null)
194 {
195 if (other.moneyUnit != null)
196 return false;
197 }
198 else if (!this.moneyUnit.equals(other.moneyUnit))
199 return false;
200 if (this.volumeUnit == null)
201 {
202 if (other.volumeUnit != null)
203 return false;
204 }
205 else if (!this.volumeUnit.equals(other.volumeUnit))
206 return false;
207 return true;
208 }
209
210 }