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