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 private MoneyPerLengthUnit(final MoneyUnit moneyUnit, final LengthUnit lengthUnit, final String nameOrNameKey,
61 final String abbreviationOrAbbreviationKey, final boolean standardUnit)
62 {
63 super(nameOrNameKey, abbreviationOrAbbreviationKey, UnitSystem.OTHER, standardMoneyPerLengthUnit,
64 moneyUnit.getScaleFactor() / lengthUnit.getScaleFactor(), standardUnit);
65 this.moneyUnit = moneyUnit;
66 this.lengthUnit = lengthUnit;
67 }
68
69
70
71
72
73
74
75
76 public MoneyPerLengthUnit(final MoneyUnit moneyUnit, final LengthUnit lengthUnit, final String name,
77 final String abbreviation)
78 {
79 this(moneyUnit, lengthUnit, name, abbreviation, false);
80 }
81
82
83
84
85
86
87
88
89
90
91 private MoneyPerLengthUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey,
92 final MoneyPerLengthUnit 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.lengthUnit = referenceUnit.getLengthUnit();
98 }
99
100
101
102
103
104
105
106
107 public MoneyPerLengthUnit(final String name, final String abbreviation, final MoneyPerLengthUnit 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 LengthUnit getLengthUnit()
125 {
126 return this.lengthUnit;
127 }
128
129
130
131
132
133 protected static void setStandardUnit(final MoneyUnit standardMoneyUnit)
134 {
135 try
136 {
137 standardMoneyPerLengthUnit = new MoneyPerLengthUnit(standardMoneyUnit, LengthUnit.METER,
138 standardMoneyUnit.getName() + " per meter", standardMoneyUnit.getAbbreviation() + "/m");
139 }
140 catch (Exception e)
141 {
142
143 e = null;
144 }
145 }
146
147
148 @Override
149 public final MoneyPerLengthUnit getStandardUnit()
150 {
151 return standardMoneyPerLengthUnit;
152 }
153
154
155
156
157 public static MoneyPerLengthUnit getStandardMoneyPerLengthUnit()
158 {
159 return standardMoneyPerLengthUnit;
160 }
161
162
163 @Override
164 public final String getSICoefficientsString()
165 {
166 return "1/m";
167 }
168
169 }