View Javadoc
1   package org.djunits.unit;
2   
3   import static org.djunits.unit.unitsystem.UnitSystem.IMPERIAL;
4   import static org.djunits.unit.unitsystem.UnitSystem.OTHER;
5   import static org.djunits.unit.unitsystem.UnitSystem.SI_DERIVED;
6   
7   import org.djunits.unit.unitsystem.UnitSystem;
8   
9   /**
10   * AreaUnit defines a number of common units for areas.
11   * <p>
12   * Copyright (c) 2015-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
14   * <p>
15   * $LastChangedDate: 2019-03-02 19:06:46 +0100 (Sat, 02 Mar 2019) $, @version $Revision: 342 $, by $Author: averbraeck $,
16   * initial version May 15, 2014 <br>
17   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
18   */
19  public class AreaUnit extends LinearUnit<AreaUnit>
20  {
21      /** */
22      private static final long serialVersionUID = 20140607L;
23  
24      /** The unit of length for the area unit, e.g., meter. */
25      private final LengthUnit lengthUnit;
26  
27      /** The SI unit for area is m^2. */
28      public static final AreaUnit SI;
29  
30      /** am^2. */
31      public static final AreaUnit SQUARE_ATTOMETER;
32  
33      /** fm^2. */
34      public static final AreaUnit SQUARE_FEMTOMETER;
35  
36      /** pm^2. */
37      public static final AreaUnit SQUARE_PICOMETER;
38  
39      /** nm^2. */
40      public static final AreaUnit SQUARE_NANOMETER;
41  
42      /** &#181;m^2. */
43      public static final AreaUnit SQUARE_MICROMETER;
44  
45      /** mm^2. */
46      public static final AreaUnit SQUARE_MILLIMETER;
47  
48      /** m^2. */
49      public static final AreaUnit SQUARE_METER;
50  
51      /** cm^2. */
52      public static final AreaUnit SQUARE_CENTIMETER;
53  
54      /** dm^2. */
55      public static final AreaUnit SQUARE_DECIMETER;
56  
57      /** dam^2. */
58      public static final AreaUnit SQUARE_DEKAMETER;
59  
60      /** hm^2. */
61      public static final AreaUnit SQUARE_HECTOMETER;
62  
63      /** km^2. */
64      public static final AreaUnit SQUARE_KILOMETER;
65  
66      /** Mm^2. */
67      public static final AreaUnit SQUARE_MEGAMETER;
68  
69      /** centiare. */
70      public static final AreaUnit CENTIARE;
71  
72      /** are. */
73      public static final AreaUnit ARE;
74  
75      /** hectare. */
76      public static final AreaUnit HECTARE;
77  
78      /** mile^2. */
79      public static final AreaUnit SQUARE_MILE;
80  
81      /** Nautical mile^2. */
82      public static final AreaUnit SQUARE_NAUTICAL_MILE;
83  
84      /** ft^2. */
85      public static final AreaUnit SQUARE_FOOT;
86  
87      /** in^2. */
88      public static final AreaUnit SQUARE_INCH;
89  
90      /** yd^2. */
91      public static final AreaUnit SQUARE_YARD;
92  
93      /** acre (international). */
94      public static final AreaUnit ACRE;
95  
96      static
97      {
98          SI = new AreaUnit(LengthUnit.METER, "AreaUnit.m^2", SI_DERIVED);
99          SQUARE_METER = SI;
100         SQUARE_ATTOMETER = new AreaUnit(LengthUnit.ATTOMETER, "AreaUnit.am^2", SI_DERIVED);
101         SQUARE_FEMTOMETER = new AreaUnit(LengthUnit.FEMTOMETER, "AreaUnit.fm^2", SI_DERIVED);
102         SQUARE_PICOMETER = new AreaUnit(LengthUnit.PICOMETER, "AreaUnit.pm^2", SI_DERIVED);
103         SQUARE_NANOMETER = new AreaUnit(LengthUnit.NANOMETER, "AreaUnit.nm^2", SI_DERIVED);
104         SQUARE_MICROMETER = new AreaUnit(LengthUnit.MICROMETER, "AreaUnit.mum^2", SI_DERIVED);
105         SQUARE_MILLIMETER = new AreaUnit(LengthUnit.MILLIMETER, "AreaUnit.mm^2", SI_DERIVED);
106         SQUARE_CENTIMETER = new AreaUnit(LengthUnit.CENTIMETER, "AreaUnit.cm^2", SI_DERIVED);
107         SQUARE_DECIMETER = new AreaUnit(LengthUnit.DECIMETER, "AreaUnit.dm^2", SI_DERIVED);
108         SQUARE_DEKAMETER = new AreaUnit(LengthUnit.DEKAMETER, "AreaUnit.dam^2", SI_DERIVED);
109         SQUARE_HECTOMETER = new AreaUnit(LengthUnit.HECTOMETER, "AreaUnit.hm^2", SI_DERIVED);
110         SQUARE_KILOMETER = new AreaUnit(LengthUnit.KILOMETER, "AreaUnit.km^2", SI_DERIVED);
111         SQUARE_MEGAMETER = new AreaUnit(LengthUnit.MEGAMETER, "AreaUnit.Mm^2", SI_DERIVED);
112         CENTIARE = new AreaUnit("AreaUnit.ca", OTHER, SQUARE_METER, 1.0);
113         ARE = new AreaUnit("AreaUnit.a", OTHER, SQUARE_METER, 100.0);
114         HECTARE = new AreaUnit("AreaUnit.ha", OTHER, ARE, 100.0);
115         SQUARE_NAUTICAL_MILE = new AreaUnit(LengthUnit.NAUTICAL_MILE, "AreaUnit.Nmi^2", OTHER);
116         SQUARE_MILE = new AreaUnit(LengthUnit.MILE, "AreaUnit.mi^2", IMPERIAL);
117         SQUARE_FOOT = new AreaUnit(LengthUnit.FOOT, "AreaUnit.ft^2", IMPERIAL);
118         SQUARE_INCH = new AreaUnit(LengthUnit.INCH, "AreaUnit.in^2", IMPERIAL);
119         SQUARE_YARD = new AreaUnit(LengthUnit.YARD, "AreaUnit.yd^2", IMPERIAL);
120         ACRE = new AreaUnit("AreaUnit.ac", IMPERIAL, SQUARE_YARD, 4840.0);
121     }
122 
123     /**
124      * Define area unit based on length.
125      * @param lengthUnit LengthUnit; the unit of length for the area unit, e.g., meter
126      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
127      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
128      */
129     private AreaUnit(final LengthUnit lengthUnit, final String abbreviationKey, final UnitSystem unitSystem)
130     {
131         super(abbreviationKey, unitSystem, SQUARE_METER, lengthUnit.getScaleFactor() * lengthUnit.getScaleFactor());
132         this.lengthUnit = lengthUnit;
133     }
134 
135     /**
136      * Create a user-defined area unit based on length.
137      * @param lengthUnit LengthUnit; the unit of length for the area unit, e.g., meter
138      * @param name String; the long name of the unit
139      * @param abbreviation String; the abbreviation of the unit
140      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
141      */
142     public AreaUnit(final LengthUnit lengthUnit, final String name, final String abbreviation, final UnitSystem unitSystem)
143     {
144         super(name, abbreviation, unitSystem, SQUARE_METER, lengthUnit.getScaleFactor() * lengthUnit.getScaleFactor());
145         this.lengthUnit = lengthUnit;
146     }
147 
148     /**
149      * This constructor constructs a unit out of another defined unit, e.g. an are is 100 m^2.
150      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
151      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
152      * @param referenceUnit AreaUnit; the unit to convert to
153      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
154      *            unit
155      */
156     private AreaUnit(final String abbreviationKey, final UnitSystem unitSystem, final AreaUnit referenceUnit,
157             final double scaleFactorToReferenceUnit)
158     {
159         super(abbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
160         this.lengthUnit = referenceUnit.getLengthUnit();
161     }
162 
163     /**
164      * Build a user-defined unit with a conversion factor to another unit, e.g. an are is 100 m^2.
165      * @param name String; the long name of the unit
166      * @param abbreviation String; the abbreviation of the unit
167      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
168      * @param referenceUnit AreaUnit; the unit to convert to
169      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
170      *            unit
171      */
172     public AreaUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final AreaUnit referenceUnit,
173             final double scaleFactorToReferenceUnit)
174     {
175         super(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
176         this.lengthUnit = referenceUnit.getLengthUnit();
177     }
178 
179     /**
180      * @return lengthUnit
181      */
182     public final LengthUnit getLengthUnit()
183     {
184         return this.lengthUnit;
185     }
186 
187     /** {@inheritDoc} */
188     @Override
189     public final AreaUnit getStandardUnit()
190     {
191         return SQUARE_METER;
192     }
193 
194     /** {@inheritDoc} */
195     @Override
196     public final String getSICoefficientsString()
197     {
198         return "m2";
199     }
200 
201 }