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 MoneyPerLengthUnit extends LinearUnit<MoneyPerLengthUnit>
16 {
17
18 private static final long serialVersionUID = 20150905L;
19
20
21 private final MoneyUnit moneyUnit;
22
23
24 private final LengthUnit lengthUnit;
25
26
27 public static final MoneyPerLengthUnit EUR_PER_METER;
28
29
30 public static final MoneyPerLengthUnit EUR_PER_KILOMETER;
31
32
33 public static final MoneyPerLengthUnit USD_PER_MILE;
34
35
36 public static final MoneyPerLengthUnit USD_PER_FOOT;
37
38
39 private static MoneyPerLengthUnit standardMoneyPerLengthUnit;
40
41 static
42 {
43 EUR_PER_METER = new MoneyPerLengthUnit(MoneyUnit.EUR, LengthUnit.METER, "EUR per meter", "\u20AC/m", false);
44 EUR_PER_KILOMETER =
45 new MoneyPerLengthUnit(MoneyUnit.EUR, LengthUnit.KILOMETER, "EUR per kilometer", "\u20AC/km", false);
46 USD_PER_MILE = new MoneyPerLengthUnit(MoneyUnit.USD, LengthUnit.MILE, "USD per mile", "US$/mi", false);
47 USD_PER_FOOT = new MoneyPerLengthUnit(MoneyUnit.USD, LengthUnit.FOOT, "USD per foot", "US$/ft", false);
48 standardMoneyPerLengthUnit = EUR_PER_METER;
49 }
50
51
52
53
54
55
56
57
58
59
60
61
62 private MoneyPerLengthUnit(final MoneyUnit moneyUnit, final LengthUnit lengthUnit, final String nameOrNameKey,
63 final String abbreviationOrAbbreviationKey, final boolean standardUnit)
64 {
65 super(nameOrNameKey, abbreviationOrAbbreviationKey, UnitSystem.OTHER, standardMoneyPerLengthUnit,
66 moneyUnit.getScaleFactor() / lengthUnit.getScaleFactor(), standardUnit);
67 this.moneyUnit = moneyUnit;
68 this.lengthUnit = lengthUnit;
69 }
70
71
72
73
74
75
76
77
78 public MoneyPerLengthUnit(final MoneyUnit moneyUnit, final LengthUnit lengthUnit, final String name,
79 final String abbreviation)
80 {
81 this(moneyUnit, lengthUnit, name, abbreviation, false);
82 }
83
84
85
86
87
88
89
90
91
92
93
94
95
96 private MoneyPerLengthUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey,
97 final MoneyPerLengthUnit referenceUnit, final double scaleFactorToReferenceUnit, final boolean standardUnit)
98 {
99 super(nameOrNameKey, abbreviationOrAbbreviationKey, UnitSystem.OTHER, referenceUnit, scaleFactorToReferenceUnit,
100 standardUnit);
101 this.moneyUnit = referenceUnit.getMoneyUnit();
102 this.lengthUnit = referenceUnit.getLengthUnit();
103 }
104
105
106
107
108
109
110
111
112
113 public MoneyPerLengthUnit(final String name, final String abbreviation, final MoneyPerLengthUnit referenceUnit,
114 final double scaleFactorToReferenceUnit)
115 {
116 this(name, abbreviation, referenceUnit, scaleFactorToReferenceUnit, false);
117 }
118
119
120
121
122 public final MoneyUnit getMoneyUnit()
123 {
124 return this.moneyUnit;
125 }
126
127
128
129
130 public final LengthUnit getLengthUnit()
131 {
132 return this.lengthUnit;
133 }
134
135
136
137
138
139 protected static void setStandardUnit(final MoneyUnit standardMoneyUnit)
140 {
141 try
142 {
143 standardMoneyPerLengthUnit = new MoneyPerLengthUnit(standardMoneyUnit, LengthUnit.METER,
144 standardMoneyUnit.getName() + " per meter", standardMoneyUnit.getAbbreviation() + "/m");
145 }
146 catch (Exception e)
147 {
148
149 e = null;
150 }
151 }
152
153
154 @Override
155 public final MoneyPerLengthUnit getStandardUnit()
156 {
157 return standardMoneyPerLengthUnit;
158 }
159
160
161
162
163 public static MoneyPerLengthUnit getStandardMoneyPerLengthUnit()
164 {
165 return standardMoneyPerLengthUnit;
166 }
167
168
169 @Override
170 public final String getSICoefficientsString()
171 {
172 return "1/m";
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.lengthUnit == null) ? 0 : this.lengthUnit.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 MoneyPerLengthUnit other = (MoneyPerLengthUnit) obj;
198 if (this.lengthUnit == null)
199 {
200 if (other.lengthUnit != null)
201 return false;
202 }
203 else if (!this.lengthUnit.equals(other.lengthUnit))
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 }