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