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-01-18 00:35:01 +0100 (Fri, 18 Jan 2019) $, @version $Revision: 324 $, 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.per_meter", "LinearDensityUnit./m", SI_DERIVED, true);
99          PER_METER = SI;
100         PER_ATTOMETER = new LinearDensityUnit("LinearDensityUnit.per_attometer", "LinearDensityUnit./am", SI_DERIVED, PER_METER,
101                 1.0E18, true);
102         PER_FEMTOMETER = new LinearDensityUnit("LinearDensityUnit.per_femtometer", "LinearDensityUnit./fm", SI_DERIVED,
103                 PER_METER, 1.0E15, true);
104         PER_PICOMETER = new LinearDensityUnit("LinearDensityUnit.per_picometer", "LinearDensityUnit./pm", SI_DERIVED, PER_METER,
105                 1.0E12, true);
106         PER_NANOMETER = new LinearDensityUnit("LinearDensityUnit.per_nanometer", "LinearDensityUnit./nm", SI_DERIVED, PER_METER,
107                 1.0E9, true);
108         PER_MICROMETER = new LinearDensityUnit("LinearDensityUnit.per_micrometer", "LinearDensityUnit./mum", SI_DERIVED,
109                 PER_METER, 1.0E6, true);
110         PER_MILLIMETER = new LinearDensityUnit("LinearDensityUnit.per_millimeter", "LinearDensityUnit./mm", SI_DERIVED,
111                 PER_METER, 1000.0, true);
112         PER_CENTIMETER = new LinearDensityUnit("LinearDensityUnit.per_centimeter", "LinearDensityUnit./cm", SI_DERIVED,
113                 PER_METER, 100.0, true);
114         PER_DECIMETER = new LinearDensityUnit("LinearDensityUnit.per_decimeter", "LinearDensityUnit./dm", SI_DERIVED, PER_METER,
115                 10.0, true);
116         PER_DEKAMETER = new LinearDensityUnit("LinearDensityUnit.per_dekameter", "LinearDensityUnit./dam", SI_DERIVED,
117                 PER_METER, 0.1, true);
118         PER_HECTOMETER = new LinearDensityUnit("LinearDensityUnit.per_hectometer", "LinearDensityUnit./hm", SI_DERIVED,
119                 PER_METER, 0.01, true);
120         PER_KILOMETER = new LinearDensityUnit("LinearDensityUnit.per_kilometer", "LinearDensityUnit./km", SI_DERIVED, PER_METER,
121                 0.001, true);
122         PER_MEGAMETER = new LinearDensityUnit("LinearDensityUnit.per_megameter", "LinearDensityUnit./Mm", SI_DERIVED, PER_METER,
123                 1.0E-6, true);
124         PER_FOOT = new LinearDensityUnit("LinearDensityUnit.per_foot", "LinearDensityUnit./ft", IMPERIAL, PER_METER,
125                 1.0 / 0.3048, true);
126         PER_INCH = new LinearDensityUnit("LinearDensityUnit.per_inch", "LinearDensityUnit./in", IMPERIAL, PER_FOOT, 12.0, true);
127         PER_MILE = new LinearDensityUnit("LinearDensityUnit.per_mile", "LinearDensityUnit./mi", IMPERIAL, PER_FOOT,
128                 1.0 / 5280.0, true);
129         PER_NAUTICAL_MILE = new LinearDensityUnit("LinearDensityUnit.per_nauticalMile", "LinearDensityUnit./NM", IMPERIAL,
130                 PER_METER, 1.0 / 1852.0, true);
131         PER_YARD = new LinearDensityUnit("LinearDensityUnit.per_yard", "LinearDensityUnit./yd", IMPERIAL, PER_FOOT, 1.0 / 3.0,
132                 true);
133         PER_ASTRONOMICAL_UNIT = new LinearDensityUnit("LinearDensityUnit.per_astronomicalUnit", "LinearDensityUnit./AU", OTHER,
134                 PER_METER, 1.0 / 149597870700.0, true);
135         PER_LIGHTYEAR = new LinearDensityUnit("LinearDensityUnit.per_lightyear", "LinearDensityUnit./ly", OTHER, PER_METER,
136                 1.0 / 9460730472580800.0, true);
137         PER_PARSEC = new LinearDensityUnit("LinearDensityUnit.per_parsec", "LinearDensityUnit./pc", OTHER, PER_LIGHTYEAR,
138                 Math.PI / 648000.0, true);
139         PER_ANGSTROM = new LinearDensityUnit("LinearDensityUnit.per_angstrom", "LinearDensityUnit./A", OTHER, PER_METER,
140                 1.0 / 1E-10, true);
141     }
142 
143     /**
144      * Define a LinearDensityUnit based on length. You can define unit like "per meter" here.
145      * @param lengthUnit LengthUnit; the unit of length for the linear density unit, e.g., meter
146      * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
147      *            name itself
148      * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
149      *            unit, otherwise the abbreviation itself
150      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
151      * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
152      *            unit
153      */
154     private LinearDensityUnit(final LengthUnit lengthUnit, final String nameOrNameKey,
155             final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
156     {
157         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, PER_METER, 1.0 / lengthUnit.getScaleFactor(),
158                 standardUnit);
159         this.lengthUnit = lengthUnit;
160     }
161 
162     /**
163      * Define a user-defined LinearDensityUnit based on length. You can define unit like "per furlong" here.
164      * @param lengthUnit LengthUnit; the unit of length for the linear density unit, e.g., meter
165      * @param name String; the long name of the unit
166      * @param abbreviation String; the abbreviation of the unit
167      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
168      */
169     public LinearDensityUnit(final LengthUnit lengthUnit, final String name, final String abbreviation,
170             final UnitSystem unitSystem)
171     {
172         this(lengthUnit, name, abbreviation, unitSystem, false);
173     }
174 
175     /**
176      * Build a LinearDensityUnit with a conversion factor to another LinearDensityUnit.
177      * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
178      *            name itself
179      * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
180      *            unit, otherwise the abbreviation itself
181      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
182      * @param referenceUnit LinearDensityUnit; the unit to convert to
183      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
184      *            unit
185      * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
186      *            unit
187      */
188     private LinearDensityUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey,
189             final UnitSystem unitSystem, final LinearDensityUnit referenceUnit, final double scaleFactorToReferenceUnit,
190             final boolean standardUnit)
191     {
192         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
193                 standardUnit);
194         this.lengthUnit = referenceUnit.getLengthUnit();
195     }
196 
197     /**
198      * Build a user-defined LinearDensityUnit with a conversion factor to another LinearDensityUnit.
199      * @param name String; the long name of the unit
200      * @param abbreviation String; the abbreviation of the unit
201      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
202      * @param referenceUnit LinearDensityUnit; the unit to convert to
203      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
204      *            unit
205      */
206     public LinearDensityUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
207             final LinearDensityUnit referenceUnit, final double scaleFactorToReferenceUnit)
208     {
209         this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
210     }
211 
212     /**
213      * @return durationUnit
214      */
215     public final LengthUnit getLengthUnit()
216     {
217         return this.lengthUnit;
218     }
219 
220     /** {@inheritDoc} */
221     @Override
222     public final LinearDensityUnit getStandardUnit()
223     {
224         return PER_METER;
225     }
226 
227     /** {@inheritDoc} */
228     @Override
229     public final String getSICoefficientsString()
230     {
231         return "1/m";
232     }
233 
234 }