View Javadoc
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.SI_BASE;
5   
6   import org.opentrafficsim.core.unit.unitsystem.UnitSystem;
7   
8   /**
9    * Standard length units. Several conversion factors have been taken from <a
10   * href="http://en.wikipedia.org/wiki/Conversion_of_units">http://en.wikipedia.org/wiki/Conversion_of_units</a>.
11   * <p>
12   * Copyright (c) 2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
14   * <p>
15   * @version May 15, 2014 <br>
16   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
17   */
18  public class LengthUnit extends Unit<LengthUnit>
19  {
20      /** */
21      private static final long serialVersionUID = 20140607L;
22  
23      /** The SI unit for length is meter. */
24      public static final LengthUnit SI;
25  
26      /** meter. */
27      public static final LengthUnit METER;
28  
29      /** millimeter. */
30      public static final LengthUnit MILLIMETER;
31  
32      /** centimeter. */
33      public static final LengthUnit CENTIMETER;
34  
35      /** decimeter. */
36      public static final LengthUnit DECIMETER;
37  
38      /** decameter. */
39      public static final LengthUnit DEKAMETER;
40  
41      /** hectometer. */
42      public static final LengthUnit HECTOMETER;
43  
44      /** kilometer. */
45      public static final LengthUnit KILOMETER;
46  
47      /** foot (international) = 0.3048 m = 1/3 yd = 12 inches. */
48      public static final LengthUnit FOOT;
49  
50      /** inch (international) = 2.54 cm = 1/36 yd = 1/12 ft. */
51      public static final LengthUnit INCH;
52  
53      /** mile (international) = 5280 ft = 1760 yd. */
54      public static final LengthUnit MILE;
55  
56      /** nautical mile (international) = 1852 m. */
57      public static final LengthUnit NAUTICAL_MILE;
58  
59      /** yard (international) = 0.9144 m = 3 ft = 36 in. */
60      public static final LengthUnit YARD;
61  
62      static
63      {
64          SI = new LengthUnit("LengthUnit.meter", "LengthUnit.m", SI_BASE);
65          METER = SI;
66          MILLIMETER = new LengthUnit("LengthUnit.millimeter", "LengthUnit.mm", SI_BASE, METER, 0.001);
67          CENTIMETER = new LengthUnit("LengthUnit.centimeter", "LengthUnit.cm", SI_BASE, METER, 0.01);
68          DECIMETER = new LengthUnit("LengthUnit.decimeter", "LengthUnit.dm", SI_BASE, METER, 0.1);
69          DEKAMETER = new LengthUnit("LengthUnit.dekameter", "LengthUnit.dam", SI_BASE, METER, 10.0);
70          HECTOMETER = new LengthUnit("LengthUnit.hectometer", "LengthUnit.hm", SI_BASE, METER, 100.0);
71          KILOMETER = new LengthUnit("LengthUnit.kilometer", "LengthUnit.km", SI_BASE, METER, 1000.0);
72          FOOT = new LengthUnit("LengthUnit.foot", "LengthUnit.ft", IMPERIAL, METER, 0.3048);
73          INCH = new LengthUnit("LengthUnit.inch", "LengthUnit.in", IMPERIAL, FOOT, 1.0 / 12.0);
74          MILE = new LengthUnit("LengthUnit.mile", "LengthUnit.mi", IMPERIAL, FOOT, 5280.0);
75          NAUTICAL_MILE = new LengthUnit("LengthUnit.nauticalMile", "LengthUnit.NM", IMPERIAL, METER, 1852.0);
76          YARD = new LengthUnit("LengthUnit.yard", "LengthUnit.yd", IMPERIAL, FOOT, 3.0);
77      }
78  
79      /**
80       * Build a standard unit.
81       * @param nameKey the key to the locale file for the long name of the unit
82       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
83       * @param unitSystem the unit system, e.g. SI or Imperial
84       */
85      public LengthUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem)
86      {
87          super(nameKey, abbreviationKey, unitSystem, true);
88      }
89  
90      /**
91       * Build a unit with a conversion factor to another unit.
92       * @param nameKey the key to the locale file for the long name of the unit
93       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
94       * @param unitSystem the unit system, e.g. SI or Imperial
95       * @param referenceUnit the unit to convert to
96       * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given
97       *            reference unit
98       */
99      public LengthUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
100             final LengthUnit referenceUnit, final double conversionFactorToReferenceUnit)
101     {
102         super(nameKey, abbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit, true);
103     }
104 
105     /** {@inheritDoc} */
106     @Override
107     public final LengthUnit getStandardUnit()
108     {
109         return METER;
110     }
111 
112     /** {@inheritDoc} */
113     @Override
114     public final String getSICoefficientsString()
115     {
116         return "m";
117     }
118 
119 }