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 MoneyPerMassUnit extends LinearUnit<MoneyPerMassUnit>
16 {
17
18 private static final long serialVersionUID = 20150905L;
19
20
21 private final MoneyUnit moneyUnit;
22
23
24 private final MassUnit massUnit;
25
26
27 public static final MoneyPerMassUnit EUR_PER_KILOGRAM;
28
29
30 public static final MoneyPerMassUnit EUR_PER_METRIC_TON;
31
32
33 public static final MoneyPerMassUnit USD_PER_POUND;
34
35
36 public static final MoneyPerMassUnit USD_PER_LONG_TON;
37
38
39 public static final MoneyPerMassUnit USD_PER_SHORT_TON;
40
41
42 private static MoneyPerMassUnit standardMoneyPerMassUnit;
43
44 static
45 {
46 EUR_PER_KILOGRAM = new MoneyPerMassUnit(MoneyUnit.EUR, MassUnit.KILOGRAM, "EUR per kilogram", "\u20AC/kg");
47 EUR_PER_METRIC_TON =
48 new MoneyPerMassUnit(MoneyUnit.EUR, MassUnit.TON_METRIC, "EUR per metric ton", "\u20AC/ton(metric)");
49 USD_PER_POUND = new MoneyPerMassUnit(MoneyUnit.USD, MassUnit.POUND, "USD per pound", "US$/lb");
50 USD_PER_LONG_TON = new MoneyPerMassUnit(MoneyUnit.USD, MassUnit.TON_LONG, "USD per long ton", "US$/ton(long)");
51 USD_PER_SHORT_TON = new MoneyPerMassUnit(MoneyUnit.USD, MassUnit.TON_SHORT, "USD per short ton", "US$/ton(short)");
52 standardMoneyPerMassUnit = EUR_PER_KILOGRAM;
53 }
54
55
56
57
58
59
60
61 private MoneyPerMassUnit(final MoneyUnit moneyUnit, final MassUnit massUnit, final String abbreviationKey)
62 {
63 super(abbreviationKey, UnitSystem.OTHER, standardMoneyPerMassUnit,
64 moneyUnit.getScaleFactor() / massUnit.getScaleFactor());
65 this.moneyUnit = moneyUnit;
66 this.massUnit = massUnit;
67 }
68
69
70
71
72
73
74
75
76 public MoneyPerMassUnit(final MoneyUnit moneyUnit, final MassUnit massUnit, final String name, final String abbreviation)
77 {
78 super(name, abbreviation, UnitSystem.OTHER, standardMoneyPerMassUnit,
79 moneyUnit.getScaleFactor() / massUnit.getScaleFactor());
80 this.moneyUnit = moneyUnit;
81 this.massUnit = massUnit;
82 }
83
84
85
86
87
88
89
90
91 private MoneyPerMassUnit(final String abbreviationKey, final MoneyPerMassUnit referenceUnit,
92 final double scaleFactorToReferenceUnit)
93 {
94 super(abbreviationKey, UnitSystem.OTHER, referenceUnit, scaleFactorToReferenceUnit);
95 this.moneyUnit = referenceUnit.getMoneyUnit();
96 this.massUnit = referenceUnit.getMassUnit();
97 }
98
99
100
101
102
103
104
105
106
107 public MoneyPerMassUnit(final String name, final String abbreviation, final MoneyPerMassUnit referenceUnit,
108 final double scaleFactorToReferenceUnit)
109 {
110 super(name, abbreviation, UnitSystem.OTHER, referenceUnit, scaleFactorToReferenceUnit);
111 this.moneyUnit = referenceUnit.getMoneyUnit();
112 this.massUnit = referenceUnit.getMassUnit();
113 }
114
115
116
117
118 public final MoneyUnit getMoneyUnit()
119 {
120 return this.moneyUnit;
121 }
122
123
124
125
126 public final MassUnit getMassUnit()
127 {
128 return this.massUnit;
129 }
130
131
132
133
134
135 protected static void setStandardUnit(final MoneyUnit standardMoneyUnit)
136 {
137 try
138 {
139 standardMoneyPerMassUnit = new MoneyPerMassUnit(standardMoneyUnit, MassUnit.KILOGRAM,
140 standardMoneyUnit.getName() + " per kilogram", standardMoneyUnit.getAbbreviation() + "/kg");
141 }
142 catch (Exception e)
143 {
144
145 e = null;
146 }
147 }
148
149
150 @Override
151 public final MoneyPerMassUnit getStandardUnit()
152 {
153 return standardMoneyPerMassUnit;
154 }
155
156
157
158
159 public static MoneyPerMassUnit getStandardMoneyPerMassUnit()
160 {
161 return standardMoneyPerMassUnit;
162 }
163
164
165 @Override
166 public final String getSICoefficientsString()
167 {
168 return "1/kg";
169 }
170
171
172 @Override
173 public int hashCode()
174 {
175 final int prime = 31;
176 int result = super.hashCode();
177 result = prime * result + ((this.massUnit == null) ? 0 : this.massUnit.hashCode());
178 result = prime * result + ((this.moneyUnit == null) ? 0 : this.moneyUnit.hashCode());
179 return result;
180 }
181
182
183 @SuppressWarnings("checkstyle:needbraces")
184 @Override
185 public boolean equals(final Object obj)
186 {
187 if (this == obj)
188 return true;
189 if (!super.equals(obj))
190 return false;
191 if (getClass() != obj.getClass())
192 return false;
193 MoneyPerMassUnit other = (MoneyPerMassUnit) obj;
194 if (this.massUnit == null)
195 {
196 if (other.massUnit != null)
197 return false;
198 }
199 else if (!this.massUnit.equals(other.massUnit))
200 return false;
201 if (this.moneyUnit == null)
202 {
203 if (other.moneyUnit != null)
204 return false;
205 }
206 else if (!this.moneyUnit.equals(other.moneyUnit))
207 return false;
208 return true;
209 }
210
211 }