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