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