View Javadoc
1   package org.djunits.unit;
2   
3   import static org.djunits.unit.unitsystem.UnitSystem.OTHER;
4   
5   import org.djunits.unit.unitsystem.UnitSystem;
6   
7   /**
8    * Standard absolute position units.
9    * <p>
10   * Copyright (c) 2015-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
12   * <p>
13   * $LastChangedDate: 2017-04-15 02:11:44 +0200 (Sat, 15 Apr 2017) $, @version $Revision: 239 $, by $Author: averbraeck $,
14   * initial version May 15, 2014 <br>
15   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16   */
17  public class PositionUnit extends AbsoluteLinearUnit<PositionUnit, LengthUnit>
18  {
19      /** */
20      private static final long serialVersionUID = 20140607L;
21  
22      /** The BASE unit for position with an artificial zero-point. */
23      public static final PositionUnit BASE;
24  
25      /** Positions scaled to am. */
26      public static final PositionUnit ATTOMETER;
27  
28      /** Positions scaled to fm. */
29      public static final PositionUnit FEMTOMETER;
30  
31      /** Positions scaled to pm. */
32      public static final PositionUnit PICOMETER;
33  
34      /** Positions scaled to nm. */
35      public static final PositionUnit NANOMETER;
36  
37      /** Positions scaled to &#181;m. */
38      public static final PositionUnit MICROMETER;
39  
40      /** Positions scaled to mm. */
41      public static final PositionUnit MILLIMETER;
42  
43      /** Positions scaled to m. */
44      public static final PositionUnit METER;
45  
46      /** Positions scaled to cm. */
47      public static final PositionUnit CENTIMETER;
48  
49      /** Positions scaled to dm. */
50      public static final PositionUnit DECIMETER;
51  
52      /** Positions scaled to dam. */
53      public static final PositionUnit DEKAMETER;
54  
55      /** Positions scaled to hm. */
56      public static final PositionUnit HECTOMETER;
57  
58      /** Positions scaled to km. */
59      public static final PositionUnit KILOMETER;
60  
61      /** Positions scaled to Mm. */
62      public static final PositionUnit MEGAMETER;
63  
64      /** Positions scaled to inch (international) = 2.54 cm = 1/36 yd = 1/12 ft. */
65      public static final PositionUnit INCH;
66  
67      /** Positions scaled to foot (international) = 0.3048 m = 1/3 yd = 12 inches. */
68      public static final PositionUnit FOOT;
69  
70      /** Positions scaled to yard (international) = 0.9144 m = 3 ft = 36 in. */
71      public static final PositionUnit YARD;
72  
73      /** Positions scaled to mile (international) = 5280 ft = 1760 yd. */
74      public static final PositionUnit MILE;
75  
76      /** Positions scaled to nautical mile (international) = 1852 m. */
77      public static final PositionUnit NAUTICAL_MILE;
78  
79      /** Positions scaled to Astronomical Unit = 149,597,870,700 m. */
80      public static final PositionUnit ASTRONOMICAL_UNIT;
81  
82      /** Positions scaled to Lightyear = 9,460,730,472,580,800 m. */
83      public static final PositionUnit LIGHTYEAR;
84  
85      /** Positions scaled to Parsec = 648,000 / PI Pc. */
86      public static final PositionUnit PARSEC;
87  
88      /** Positions scaled to Angstrom = 10^-10 m. */
89      public static final PositionUnit ANGSTROM;
90  
91      static
92      {
93          BASE = new PositionUnit("PositionUnit.base", "PositionUnit.base", OTHER, 1.0, 0.0, LengthUnit.METER);
94          METER = new PositionUnit("PositionUnit.meter", "PositionUnit.m", OTHER, 1.0, 0.0, true, LengthUnit.METER);
95          ATTOMETER =
96                  new PositionUnit("PositionUnit.attometer", "PositionUnit.am", OTHER, 1.0E-18, 0.0, true, LengthUnit.ATTOMETER);
97          FEMTOMETER = new PositionUnit("PositionUnit.femtometer", "PositionUnit.fm", OTHER, 1.0E-15, 0.0, true,
98                  LengthUnit.FEMTOMETER);
99          PICOMETER =
100                 new PositionUnit("PositionUnit.picometer", "PositionUnit.pm", OTHER, 1.0E-12, 0.0, true, LengthUnit.PICOMETER);
101         NANOMETER =
102                 new PositionUnit("PositionUnit.nanometer", "PositionUnit.nm", OTHER, 1.0E-9, 0.0, true, LengthUnit.NANOMETER);
103         MICROMETER = new PositionUnit("PositionUnit.micrometer", "PositionUnit.mum", OTHER, 1.0E-6, 0.0, true,
104                 LengthUnit.MICROMETER);
105         MILLIMETER =
106                 new PositionUnit("PositionUnit.millimeter", "PositionUnit.mm", OTHER, 0.001, 0.0, true, LengthUnit.MILLIMETER);
107         CENTIMETER =
108                 new PositionUnit("PositionUnit.centimeter", "PositionUnit.cm", OTHER, 0.01, 0.0, true, LengthUnit.CENTIMETER);
109         DECIMETER = new PositionUnit("PositionUnit.decimeter", "PositionUnit.dm", OTHER, 0.1, 0.0, true, LengthUnit.DECIMETER);
110         DEKAMETER =
111                 new PositionUnit("PositionUnit.dekameter", "PositionUnit.dam", OTHER, 10.0, 0.0, true, LengthUnit.DEKAMETER);
112         HECTOMETER =
113                 new PositionUnit("PositionUnit.hectometer", "PositionUnit.hm", OTHER, 100.0, 0.0, true, LengthUnit.HECTOMETER);
114         KILOMETER =
115                 new PositionUnit("PositionUnit.kilometer", "PositionUnit.km", OTHER, 1000.0, 0.0, true, LengthUnit.KILOMETER);
116         MEGAMETER = new PositionUnit("PositionUnit.megameter", "PositionUnit.Mm", OTHER, 1000000.0, 0.0, true,
117                 LengthUnit.MEGAMETER);
118         FOOT = new PositionUnit("PositionUnit.foot", "PositionUnit.ft", OTHER, 0.3048, 0.0, true, LengthUnit.FOOT);
119         INCH = new PositionUnit("PositionUnit.inch", "PositionUnit.in", OTHER, 0.3048 / 12.0, 0.0, true, LengthUnit.INCH);
120         MILE = new PositionUnit("PositionUnit.mile", "PositionUnit.mi", OTHER, 0.3048 * 5280.0, 0.0, true, LengthUnit.MILE);
121         YARD = new PositionUnit("PositionUnit.yard", "PositionUnit.yd", OTHER, 0.3048 * 3.0, 0.0, true, LengthUnit.YARD);
122         NAUTICAL_MILE = new PositionUnit("PositionUnit.nauticalMile", "PositionUnit.NM", OTHER, 1852.0, 0.0, true,
123                 LengthUnit.NAUTICAL_MILE);
124         ASTRONOMICAL_UNIT = new PositionUnit("PositionUnit.astronomicalUnit", "PositionUnit.AU", OTHER, 149597870700.0, 0.0,
125                 true, LengthUnit.ASTRONOMICAL_UNIT);
126         LIGHTYEAR = new PositionUnit("PositionUnit.lightyear", "PositionUnit.ly", OTHER, 9460730472580800.0, 0.0, true,
127                 LengthUnit.LIGHTYEAR);
128         PARSEC = new PositionUnit("PositionUnit.parsec", "PositionUnit.pc", OTHER, 648000 / Math.PI, 0.0, true,
129                 LengthUnit.PARSEC);
130         ANGSTROM = new PositionUnit("PositionUnit.angstrom", "PositionUnit.A", OTHER, 1E-10, 0.0, true, LengthUnit.ANGSTROM);
131     }
132 
133     /**
134      * Build a PositionUnit with a scale factor and offset to the base PositionUnit.
135      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
136      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
137      *            otherwise the abbreviation itself
138      * @param unitSystem the unit system, e.g. SI or Imperial
139      * @param scaleFactor multiply a value in this unit by the factor to convert to the given reference unit
140      * @param offset the offset to the reference unit to add to convert to the standard (e.g., BASE) unit
141      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
142      * @param relativeUnit the corresponding relative unit belonging to this absolute unit
143      */
144     private PositionUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
145             final double scaleFactor, final double offset, final boolean standardUnit, final LengthUnit relativeUnit)
146     {
147         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, scaleFactor, offset, standardUnit, relativeUnit);
148     }
149 
150     /**
151      * Build a user-defined PositionUnit with a scale factor and offset to the base PositionUnit.
152      * @param name the long name of the unit
153      * @param abbreviation the abbreviation of the unit
154      * @param unitSystem the unit system, e.g. SI or Imperial
155      * @param scaleFactor multiply a value in this unit by the factor to convert to the given reference unit
156      * @param offset the offset to the reference unit to add to convert to the standard (e.g., BASE) unit
157      * @param relativeUnit the corresponding relative unit belonging to this absolute unit
158      */
159     public PositionUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final double scaleFactor,
160             final double offset, final LengthUnit relativeUnit)
161     {
162         this(name, abbreviation, unitSystem, scaleFactor, offset, false, relativeUnit);
163     }
164 
165     /** {@inheritDoc} */
166     @Override
167     public final PositionUnit getStandardUnit()
168     {
169         return BASE;
170     }
171 
172     /** {@inheritDoc} */
173     @Override
174     public final String getSICoefficientsString()
175     {
176         return "m";
177     }
178 
179 }