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-2018 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: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, 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.meter", "LengthUnit.m", SI_BASE);
97          METER = SI;
98          ATTOMETER = new LengthUnit("LengthUnit.attometer", "LengthUnit.am", SI_BASE, METER, 1.0E-18, true);
99          FEMTOMETER = new LengthUnit("LengthUnit.femtometer", "LengthUnit.fm", SI_BASE, METER, 1.0E-15, true);
100         PICOMETER = new LengthUnit("LengthUnit.picometer", "LengthUnit.pm", SI_BASE, METER, 1.0E-12, true);
101         NANOMETER = new LengthUnit("LengthUnit.nanometer", "LengthUnit.nm", SI_BASE, METER, 1.0E-9, true);
102         MICROMETER = new LengthUnit("LengthUnit.micrometer", "LengthUnit.mum", SI_BASE, METER, 1.0E-6, true);
103         MILLIMETER = new LengthUnit("LengthUnit.millimeter", "LengthUnit.mm", SI_BASE, METER, 0.001, true);
104         CENTIMETER = new LengthUnit("LengthUnit.centimeter", "LengthUnit.cm", SI_BASE, METER, 0.01, true);
105         DECIMETER = new LengthUnit("LengthUnit.decimeter", "LengthUnit.dm", SI_BASE, METER, 0.1, true);
106         DEKAMETER = new LengthUnit("LengthUnit.dekameter", "LengthUnit.dam", SI_BASE, METER, 10.0, true);
107         HECTOMETER = new LengthUnit("LengthUnit.hectometer", "LengthUnit.hm", SI_BASE, METER, 100.0, true);
108         KILOMETER = new LengthUnit("LengthUnit.kilometer", "LengthUnit.km", SI_BASE, METER, 1000.0, true);
109         MEGAMETER = new LengthUnit("LengthUnit.megameter", "LengthUnit.Mm", SI_BASE, METER, 1000000.0, true);
110         FOOT = new LengthUnit("LengthUnit.foot", "LengthUnit.ft", IMPERIAL, METER, 0.3048, true);
111         INCH = new LengthUnit("LengthUnit.inch", "LengthUnit.in", IMPERIAL, FOOT, 1.0 / 12.0, true);
112         MILE = new LengthUnit("LengthUnit.mile", "LengthUnit.mi", IMPERIAL, FOOT, 5280.0, true);
113         YARD = new LengthUnit("LengthUnit.yard", "LengthUnit.yd", IMPERIAL, FOOT, 3.0, true);
114         NAUTICAL_MILE = new LengthUnit("LengthUnit.nauticalMile", "LengthUnit.NM", IMPERIAL, METER, 1852.0, true);
115         ASTRONOMICAL_UNIT = new LengthUnit("LengthUnit.astronomicalUnit", "LengthUnit.AU", OTHER, METER, 149597870700.0, true);
116         LIGHTYEAR = new LengthUnit("LengthUnit.lightyear", "LengthUnit.ly", OTHER, METER, 9460730472580800.0, true);
117         PARSEC = new LengthUnit("LengthUnit.parsec", "LengthUnit.pc", OTHER, LIGHTYEAR, 648000 / Math.PI, true);
118         ANGSTROM = new LengthUnit("LengthUnit.angstrom", "LengthUnit.A", OTHER, METER, 1E-10, true);
119     }
120 
121     /**
122      * Build a standard LengthUnit.
123      * @param nameKey the key to the locale file for the long name of the unit
124      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
125      * @param unitSystem the unit system, e.g. SI or Imperial
126      */
127     private LengthUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem)
128     {
129         super(nameKey, abbreviationKey, unitSystem, true);
130     }
131 
132     /**
133      * Build a LengthUnit with a conversion factor to another LengthUnit.
134      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
135      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
136      *            otherwise the abbreviation itself
137      * @param unitSystem the unit system, e.g. SI or Imperial
138      * @param referenceUnit the unit to convert to
139      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
140      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
141      */
142     private LengthUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
143             final LengthUnit referenceUnit, final double scaleFactorToReferenceUnit, final boolean standardUnit)
144     {
145         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
146                 standardUnit);
147     }
148 
149     /**
150      * Build a user-defined LengthUnit with a conversion factor to another LengthUnit.
151      * @param name the long name of the unit
152      * @param abbreviation the abbreviation of the unit
153      * @param unitSystem the unit system, e.g. SI or Imperial
154      * @param referenceUnit the unit to convert to
155      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
156      */
157     public LengthUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final LengthUnit referenceUnit,
158             final double scaleFactorToReferenceUnit)
159     {
160         this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
161     }
162 
163     /** {@inheritDoc} */
164     @Override
165     public final LengthUnit getStandardUnit()
166     {
167         return METER;
168     }
169 
170     /** {@inheritDoc} */
171     @Override
172     public final String getSICoefficientsString()
173     {
174         return "m";
175     }
176 
177 }