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   * Objects per unit of distance.
11   * <p>
12   * Copyright (c) 2013-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 11 nov. 2014 <br>
17   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
18   */
19  public class LinearDensityUnit extends LinearUnit<LinearDensityUnit>
20  {
21      /** */
22      private static final long serialVersionUID = 20141111L;
23  
24      /** the actual length unit, e.g. meter. */
25      private final LengthUnit lengthUnit;
26  
27      /** The SI unit for objects per unit of distance is 1/meter. */
28      public static final LinearDensityUnit SI;
29  
30      /** 1/am. */
31      public static final LinearDensityUnit PER_ATTOMETER;
32  
33      /** 1/fm. */
34      public static final LinearDensityUnit PER_FEMTOMETER;
35  
36      /** 1/pm. */
37      public static final LinearDensityUnit PER_PICOMETER;
38  
39      /** 1/nm. */
40      public static final LinearDensityUnit PER_NANOMETER;
41  
42      /** 1/&#181;m. */
43      public static final LinearDensityUnit PER_MICROMETER;
44  
45      /** 1/meter. */
46      public static final LinearDensityUnit PER_METER;
47  
48      /** 1/millimeter. */
49      public static final LinearDensityUnit PER_MILLIMETER;
50  
51      /** 1/centimeter. */
52      public static final LinearDensityUnit PER_CENTIMETER;
53  
54      /** 1/decimeter. */
55      public static final LinearDensityUnit PER_DECIMETER;
56  
57      /** 1/decameter. */
58      public static final LinearDensityUnit PER_DEKAMETER;
59  
60      /** 1/hectometer. */
61      public static final LinearDensityUnit PER_HECTOMETER;
62  
63      /** 1/kilometer. */
64      public static final LinearDensityUnit PER_KILOMETER;
65  
66      /** 1/megameter. */
67      public static final LinearDensityUnit PER_MEGAMETER;
68  
69      /** 1/foot (international) = 0.3048 m = 1/3 yd = 12 inches. */
70      public static final LinearDensityUnit PER_FOOT;
71  
72      /** 1/inch (international) = 2.54 cm = 1/36 yd = 1/12 ft. */
73      public static final LinearDensityUnit PER_INCH;
74  
75      /** 1/mile (international) = 5280 ft = 1760 yd. */
76      public static final LinearDensityUnit PER_MILE;
77  
78      /** 1/nautical mile (international) = 1852 m. */
79      public static final LinearDensityUnit PER_NAUTICAL_MILE;
80  
81      /** 1/yard (international) = 0.9144 m = 3 ft = 36 in. */
82      public static final LinearDensityUnit PER_YARD;
83  
84      /** 1/Astronomical Unit. */
85      public static final LinearDensityUnit PER_ASTRONOMICAL_UNIT;
86  
87      /** 1/Lightyear. */
88      public static final LinearDensityUnit PER_LIGHTYEAR;
89  
90      /** 1/Parsec. */
91      public static final LinearDensityUnit PER_PARSEC;
92  
93      /** 1/Angstrom. */
94      public static final LinearDensityUnit PER_ANGSTROM;
95  
96      static
97      {
98          SI = new LinearDensityUnit(LengthUnit.METER, "LinearDensityUnit./m", SI_DERIVED);
99          PER_METER = SI;
100         PER_ATTOMETER = new LinearDensityUnit("LinearDensityUnit./am", SI_DERIVED, PER_METER, 1.0E18);
101         PER_FEMTOMETER = new LinearDensityUnit("LinearDensityUnit./fm", SI_DERIVED, PER_METER, 1.0E15);
102         PER_PICOMETER = new LinearDensityUnit("LinearDensityUnit./pm", SI_DERIVED, PER_METER, 1.0E12);
103         PER_NANOMETER = new LinearDensityUnit("LinearDensityUnit./nm", SI_DERIVED, PER_METER, 1.0E9);
104         PER_MICROMETER = new LinearDensityUnit("LinearDensityUnit./mum", SI_DERIVED, PER_METER, 1.0E6);
105         PER_MILLIMETER = new LinearDensityUnit("LinearDensityUnit./mm", SI_DERIVED, PER_METER, 1000.0);
106         PER_CENTIMETER = new LinearDensityUnit("LinearDensityUnit./cm", SI_DERIVED, PER_METER, 100.0);
107         PER_DECIMETER = new LinearDensityUnit("LinearDensityUnit./dm", SI_DERIVED, PER_METER, 10.0);
108         PER_DEKAMETER = new LinearDensityUnit("LinearDensityUnit./dam", SI_DERIVED, PER_METER, 0.1);
109         PER_HECTOMETER = new LinearDensityUnit("LinearDensityUnit./hm", SI_DERIVED, PER_METER, 0.01);
110         PER_KILOMETER = new LinearDensityUnit("LinearDensityUnit./km", SI_DERIVED, PER_METER, 0.001);
111         PER_MEGAMETER = new LinearDensityUnit("LinearDensityUnit./Mm", SI_DERIVED, PER_METER, 1.0E-6);
112         PER_FOOT = new LinearDensityUnit("LinearDensityUnit./ft", IMPERIAL, PER_METER, 1.0 / 0.3048);
113         PER_INCH = new LinearDensityUnit("LinearDensityUnit./in", IMPERIAL, PER_FOOT, 12.0);
114         PER_MILE = new LinearDensityUnit("LinearDensityUnit./mi", IMPERIAL, PER_FOOT, 1.0 / 5280.0);
115         PER_NAUTICAL_MILE = new LinearDensityUnit("LinearDensityUnit./NM", IMPERIAL, PER_METER, 1.0 / 1852.0);
116         PER_YARD = new LinearDensityUnit("LinearDensityUnit./yd", IMPERIAL, PER_FOOT, 1.0 / 3.0);
117         PER_ASTRONOMICAL_UNIT = new LinearDensityUnit("LinearDensityUnit./AU", OTHER, PER_METER, 1.0 / 149597870700.0);
118         PER_LIGHTYEAR = new LinearDensityUnit("LinearDensityUnit./ly", OTHER, PER_METER, 1.0 / 9460730472580800.0);
119         PER_PARSEC = new LinearDensityUnit("LinearDensityUnit./pc", OTHER, PER_LIGHTYEAR, Math.PI / 648000.0);
120         PER_ANGSTROM = new LinearDensityUnit("LinearDensityUnit./A", OTHER, PER_METER, 1.0 / 1E-10);
121     }
122 
123     /**
124      * Define a LinearDensityUnit based on length. You can define unit like "per meter" here.
125      * @param lengthUnit LengthUnit; the unit of length for the linear density 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 LinearDensityUnit(final LengthUnit lengthUnit, final String abbreviationKey, final UnitSystem unitSystem)
130     {
131         super(abbreviationKey, unitSystem, PER_METER, 1.0 / lengthUnit.getScaleFactor());
132         this.lengthUnit = lengthUnit;
133     }
134 
135     /**
136      * Define a user-defined LinearDensityUnit based on length. You can define unit like "per furlong" here.
137      * @param lengthUnit LengthUnit; the unit of length for the linear density 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 LinearDensityUnit(final LengthUnit lengthUnit, final String name, final String abbreviation,
143             final UnitSystem unitSystem)
144     {
145         super(name, abbreviation, unitSystem, PER_METER, 1.0 / lengthUnit.getScaleFactor());
146         this.lengthUnit = lengthUnit;
147     }
148 
149     /**
150      * Build a LinearDensityUnit with a conversion factor to another LinearDensityUnit.
151      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
152      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
153      * @param referenceUnit LinearDensityUnit; the unit to convert to
154      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
155      *            unit
156      */
157     private LinearDensityUnit(final String abbreviationKey, final UnitSystem unitSystem, final LinearDensityUnit referenceUnit,
158             final double scaleFactorToReferenceUnit)
159     {
160         super(abbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
161         this.lengthUnit = referenceUnit.getLengthUnit();
162     }
163 
164     /**
165      * Build a user-defined LinearDensityUnit with a conversion factor to another LinearDensityUnit.
166      * @param name String; the long name of the unit
167      * @param abbreviation String; the abbreviation of the unit
168      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
169      * @param referenceUnit LinearDensityUnit; the unit to convert to
170      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
171      *            unit
172      */
173     public LinearDensityUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
174             final LinearDensityUnit referenceUnit, final double scaleFactorToReferenceUnit)
175     {
176         super(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
177         this.lengthUnit = referenceUnit.getLengthUnit();
178     }
179 
180     /**
181      * @return durationUnit
182      */
183     public final LengthUnit getLengthUnit()
184     {
185         return this.lengthUnit;
186     }
187 
188     /** {@inheritDoc} */
189     @Override
190     public final LinearDensityUnit getStandardUnit()
191     {
192         return PER_METER;
193     }
194 
195     /** {@inheritDoc} */
196     @Override
197     public final String getSICoefficientsString()
198     {
199         return "1/m";
200     }
201 
202 }