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_BASE;
6   
7   import org.djunits.unit.unitsystem.UnitSystem;
8   
9   /**
10   * Standard length units. Several conversion factors have been taken from
11   * <a href="http://en.wikipedia.org/wiki/Conversion_of_units">http://en.wikipedia.org/wiki/Conversion_of_units</a>.
12   * <p>
13   * Copyright (c) 2015-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
14   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
15   * <p>
16   * $LastChangedDate: 2019-03-02 19:06:46 +0100 (Sat, 02 Mar 2019) $, @version $Revision: 342 $, by $Author: averbraeck $,
17   * initial version May 15, 2014 <br>
18   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19   */
20  public class LengthUnit extends LinearUnit<LengthUnit>
21  {
22      /** */
23      private static final long serialVersionUID = 20140607L;
24  
25      /** The SI unit for length is meter. */
26      public static final LengthUnit SI;
27  
28      /** am. */
29      public static final LengthUnit ATTOMETER;
30  
31      /** fm. */
32      public static final LengthUnit FEMTOMETER;
33  
34      /** pm. */
35      public static final LengthUnit PICOMETER;
36  
37      /** nm. */
38      public static final LengthUnit NANOMETER;
39  
40      /** &#181;m. */
41      public static final LengthUnit MICROMETER;
42  
43      /** mm. */
44      public static final LengthUnit MILLIMETER;
45  
46      /** m. */
47      public static final LengthUnit METER;
48  
49      /** cm. */
50      public static final LengthUnit CENTIMETER;
51  
52      /** dm. */
53      public static final LengthUnit DECIMETER;
54  
55      /** dam. */
56      public static final LengthUnit DEKAMETER;
57  
58      /** hm. */
59      public static final LengthUnit HECTOMETER;
60  
61      /** km. */
62      public static final LengthUnit KILOMETER;
63  
64      /** Mm. */
65      public static final LengthUnit MEGAMETER;
66  
67      /** inch (international) = 2.54 cm = 1/36 yd = 1/12 ft. */
68      public static final LengthUnit INCH;
69  
70      /** foot (international) = 0.3048 m = 1/3 yd = 12 inches. */
71      public static final LengthUnit FOOT;
72  
73      /** yard (international) = 0.9144 m = 3 ft = 36 in. */
74      public static final LengthUnit YARD;
75  
76      /** mile (international) = 5280 ft = 1760 yd. */
77      public static final LengthUnit MILE;
78  
79      /** nautical mile (international) = 1852 m. */
80      public static final LengthUnit NAUTICAL_MILE;
81  
82      /** Astronomical Unit = 149,597,870,700 m. */
83      public static final LengthUnit ASTRONOMICAL_UNIT;
84  
85      /** Lightyear = 9,460,730,472,580,800 m. */
86      public static final LengthUnit LIGHTYEAR;
87  
88      /** Parsec = 648,000 / PI Pc. */
89      public static final LengthUnit PARSEC;
90  
91      /** Angstrom = 10^-10 m. */
92      public static final LengthUnit ANGSTROM;
93  
94      static
95      {
96          SI = new LengthUnit("LengthUnit.m", SI_BASE);
97          METER = SI;
98          ATTOMETER = new LengthUnit("LengthUnit.am", SI_BASE, METER, 1.0E-18);
99          FEMTOMETER = new LengthUnit("LengthUnit.fm", SI_BASE, METER, 1.0E-15);
100         PICOMETER = new LengthUnit("LengthUnit.pm", SI_BASE, METER, 1.0E-12);
101         NANOMETER = new LengthUnit("LengthUnit.nm", SI_BASE, METER, 1.0E-9);
102         MICROMETER = new LengthUnit("LengthUnit.mum", SI_BASE, METER, 1.0E-6);
103         MILLIMETER = new LengthUnit("LengthUnit.mm", SI_BASE, METER, 0.001);
104         CENTIMETER = new LengthUnit("LengthUnit.cm", SI_BASE, METER, 0.01);
105         DECIMETER = new LengthUnit("LengthUnit.dm", SI_BASE, METER, 0.1);
106         DEKAMETER = new LengthUnit("LengthUnit.dam", SI_BASE, METER, 10.0);
107         HECTOMETER = new LengthUnit("LengthUnit.hm", SI_BASE, METER, 100.0);
108         KILOMETER = new LengthUnit("LengthUnit.km", SI_BASE, METER, 1000.0);
109         MEGAMETER = new LengthUnit("LengthUnit.Mm", SI_BASE, METER, 1000000.0);
110         FOOT = new LengthUnit("LengthUnit.ft", IMPERIAL, METER, 0.3048);
111         INCH = new LengthUnit("LengthUnit.in", IMPERIAL, FOOT, 1.0 / 12.0);
112         MILE = new LengthUnit("LengthUnit.mi", IMPERIAL, FOOT, 5280.0);
113         YARD = new LengthUnit("LengthUnit.yd", IMPERIAL, FOOT, 3.0);
114         NAUTICAL_MILE = new LengthUnit("LengthUnit.NM", IMPERIAL, METER, 1852.0);
115         ASTRONOMICAL_UNIT = new LengthUnit("LengthUnit.AU", OTHER, METER, 149597870700.0);
116         LIGHTYEAR = new LengthUnit("LengthUnit.ly", OTHER, METER, 9460730472580800.0);
117         PARSEC = new LengthUnit("LengthUnit.pc", OTHER, LIGHTYEAR, 648000 / Math.PI);
118         ANGSTROM = new LengthUnit("LengthUnit.A", OTHER, METER, 1E-10);
119     }
120 
121     /**
122      * Build a standard LengthUnit.
123      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
124      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
125      */
126     private LengthUnit(final String abbreviationKey, final UnitSystem unitSystem)
127     {
128         super(abbreviationKey, unitSystem);
129     }
130 
131     /**
132      * Build a LengthUnit with a conversion factor to another LengthUnit.
133      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
134      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
135      * @param referenceUnit LengthUnit; the unit to convert to
136      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
137      *            unit
138      */
139     private LengthUnit(final String abbreviationKey, final UnitSystem unitSystem, final LengthUnit referenceUnit,
140             final double scaleFactorToReferenceUnit)
141     {
142         super(abbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
143     }
144 
145     /**
146      * Build a user-defined LengthUnit with a conversion factor to another LengthUnit.
147      * @param name String; the long name of the unit
148      * @param abbreviation String; the abbreviation of the unit
149      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
150      * @param referenceUnit LengthUnit; the unit to convert to
151      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
152      *            unit
153      */
154     public LengthUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final LengthUnit referenceUnit,
155             final double scaleFactorToReferenceUnit)
156     {
157         super(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
158     }
159 
160     /** {@inheritDoc} */
161     @Override
162     public final LengthUnit getStandardUnit()
163     {
164         return METER;
165     }
166 
167     /** {@inheritDoc} */
168     @Override
169     public final String getSICoefficientsString()
170     {
171         return "m";
172     }
173 
174 }