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