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