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-2018 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: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, 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 the unit of length for the linear density unit, e.g., meter
146      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
147      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
148      *            otherwise the abbreviation itself
149      * @param unitSystem the unit system, e.g. SI or Imperial
150      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
151      */
152     private LinearDensityUnit(final LengthUnit lengthUnit, final String nameOrNameKey,
153             final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
154     {
155         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, PER_METER, 1.0 / lengthUnit.getScaleFactor(),
156                 standardUnit);
157         this.lengthUnit = lengthUnit;
158     }
159 
160     /**
161      * Define a user-defined LinearDensityUnit based on length. You can define unit like "per furlong" here.
162      * @param lengthUnit the unit of length for the linear density unit, e.g., meter
163      * @param name the long name of the unit
164      * @param abbreviation the abbreviation of the unit
165      * @param unitSystem the unit system, e.g. SI or Imperial
166      */
167     public LinearDensityUnit(final LengthUnit lengthUnit, final String name, final String abbreviation,
168             final UnitSystem unitSystem)
169     {
170         this(lengthUnit, name, abbreviation, unitSystem, false);
171     }
172 
173     /**
174      * Build a LinearDensityUnit with a conversion factor to another LinearDensityUnit.
175      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
176      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
177      *            otherwise the abbreviation itself
178      * @param unitSystem the unit system, e.g. SI or Imperial
179      * @param referenceUnit the unit to convert to
180      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
181      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
182      */
183     private LinearDensityUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey,
184             final UnitSystem unitSystem, final LinearDensityUnit referenceUnit, final double scaleFactorToReferenceUnit,
185             final boolean standardUnit)
186     {
187         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
188                 standardUnit);
189         this.lengthUnit = referenceUnit.getLengthUnit();
190     }
191 
192     /**
193      * Build a user-defined LinearDensityUnit with a conversion factor to another LinearDensityUnit.
194      * @param name the long name of the unit
195      * @param abbreviation the abbreviation of the unit
196      * @param unitSystem the unit system, e.g. SI or Imperial
197      * @param referenceUnit the unit to convert to
198      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
199      */
200     public LinearDensityUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
201             final LinearDensityUnit referenceUnit, final double scaleFactorToReferenceUnit)
202     {
203         this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
204     }
205 
206     /**
207      * @return durationUnit
208      */
209     public final LengthUnit getLengthUnit()
210     {
211         return this.lengthUnit;
212     }
213 
214     /** {@inheritDoc} */
215     @Override
216     public final LinearDensityUnit getStandardUnit()
217     {
218         return PER_METER;
219     }
220 
221     /** {@inheritDoc} */
222     @Override
223     public final String getSICoefficientsString()
224     {
225         return "1/m";
226     }
227 
228 }