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