1 package org.opentrafficsim.core.unit;
2
3 import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.IMPERIAL;
4 import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.OTHER;
5 import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_DERIVED;
6
7 import org.opentrafficsim.core.unit.unitsystem.UnitSystem;
8
9
10
11
12
13
14
15
16
17
18 public class AreaUnit extends Unit<AreaUnit>
19 {
20
21 private static final long serialVersionUID = 20140607L;
22
23
24 private final LengthUnit lengthUnit;
25
26
27 public static final AreaUnit SI;
28
29
30 public static final AreaUnit SQUARE_METER;
31
32
33 public static final AreaUnit SQUARE_KM;
34
35
36 public static final AreaUnit SQUARE_CENTIMETER;
37
38
39 public static final AreaUnit SQUARE_MILLIMETER;
40
41
42 public static final AreaUnit ARE;
43
44
45 public static final AreaUnit HECTARE;
46
47
48 public static final AreaUnit SQUARE_MILE;
49
50
51 public static final AreaUnit SQUARE_FOOT;
52
53
54 public static final AreaUnit SQUARE_INCH;
55
56
57 public static final AreaUnit SQUARE_YARD;
58
59
60 public static final AreaUnit ACRE;
61
62 static
63 {
64 SI = new AreaUnit(LengthUnit.METER, "AreaUnit.square_meter", "AreaUnit.m^2", SI_DERIVED);
65 SQUARE_METER = SI;
66 SQUARE_KM = new AreaUnit(LengthUnit.KILOMETER, "AreaUnit.square_kilometer", "AreaUnit.km^2", SI_DERIVED);
67 SQUARE_CENTIMETER =
68 new AreaUnit(LengthUnit.CENTIMETER, "AreaUnit.square_centimeter", "AreaUnit.cm^2", SI_DERIVED);
69 SQUARE_MILLIMETER =
70 new AreaUnit(LengthUnit.MILLIMETER, "AreaUnit.square_millimeter", "AreaUnit.mm^2", SI_DERIVED);
71 ARE = new AreaUnit("AreaUnit.are", "AreaUnit.a", OTHER, SQUARE_METER, 100.0);
72 HECTARE = new AreaUnit("AreaUnit.hectare", "AreaUnit.ha", OTHER, ARE, 100.0);
73 SQUARE_MILE = new AreaUnit(LengthUnit.MILE, "AreaUnit.square_mile", "AreaUnit.mi^2", IMPERIAL);
74 SQUARE_FOOT = new AreaUnit(LengthUnit.FOOT, "AreaUnit.square_foot", "AreaUnit.ft^2", IMPERIAL);
75 SQUARE_INCH = new AreaUnit(LengthUnit.INCH, "AreaUnit.square_inch", "AreaUnit.in^2", IMPERIAL);
76 SQUARE_YARD = new AreaUnit(LengthUnit.YARD, "AreaUnit.square_yard", "AreaUnit.yd^2", IMPERIAL);
77 ACRE = new AreaUnit("AreaUnit.acre", "AreaUnit.ac", IMPERIAL, SQUARE_YARD, 4840.0);
78 }
79
80
81
82
83
84
85
86
87 public AreaUnit(final LengthUnit lengthUnit, final String nameKey, final String abbreviationKey,
88 final UnitSystem unitSystem)
89 {
90 super(nameKey, abbreviationKey, unitSystem, SQUARE_METER, lengthUnit.getConversionFactorToStandardUnit()
91 * lengthUnit.getConversionFactorToStandardUnit(), true);
92 this.lengthUnit = lengthUnit;
93 }
94
95
96
97
98
99
100
101
102
103
104 public AreaUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
105 final AreaUnit referenceUnit, final double conversionFactorToReferenceUnit)
106 {
107 super(nameKey, abbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit, true);
108 this.lengthUnit = referenceUnit.getLengthUnit();
109 }
110
111
112
113
114 public final LengthUnit getLengthUnit()
115 {
116 return this.lengthUnit;
117 }
118
119
120 @Override
121 public final AreaUnit getStandardUnit()
122 {
123 return SQUARE_METER;
124 }
125
126
127 @Override
128 public final String getSICoefficientsString()
129 {
130 return "m2";
131 }
132
133 }