1 package org.opentrafficsim.core.unit;
2
3 import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_DERIVED;
4
5 import org.opentrafficsim.core.unit.unitsystem.UnitSystem;
6
7 /**
8 * Objects per unit of distance.
9 * <p>
10 * Copyright (c) 2013-2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights
11 * reserved. <br>
12 * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
13 * <p>
14 * @version 11 nov. 2014 <br>
15 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
16 */
17 public class LinearDensityUnit extends Unit<LinearDensityUnit>
18 {
19 /** */
20 private static final long serialVersionUID = 20141111L;
21
22 /** the actual length unit, e.g. meter. */
23 private final LengthUnit lengthUnit;
24
25 /** The SI unit for objects per unit of distance is 1/meter. */
26 public static final LinearDensityUnit SI;
27
28 /** 1/meter. */
29 public static final LinearDensityUnit PER_METER;
30
31 /** 1/kilometer. */
32 public static final LinearDensityUnit PER_KILOMETER;
33
34 /** 1/millimeter. */
35 public static final LinearDensityUnit PER_MILLIMETER;
36
37 static
38 {
39 SI = new LinearDensityUnit(LengthUnit.METER, "LinearDensityUnit.per_meter", "LinearDensityUnit./m", SI_DERIVED);
40 PER_METER = SI;
41 PER_KILOMETER =
42 new LinearDensityUnit("LinearDensityUnit.per_kilometer", "LinearDensityUnit./km", SI_DERIVED,
43 PER_METER, 0.001);
44 PER_MILLIMETER =
45 new LinearDensityUnit("LinearDensityUnit.per_millimeter", "LinearDensityUnit./mm", SI_DERIVED,
46 PER_METER, 1000);
47 }
48
49 /**
50 * Define frequency unit based on time. You can define unit like "per second" (Hertz) here.
51 * @param lengthUnit the unit of length for the linear density unit, e.g., meter
52 * @param nameKey the key to the locale file for the long name of the unit
53 * @param abbreviationKey the key to the locale file for the abbreviation of the unit
54 * @param unitSystem the unit system, e.g. SI or Imperial
55 */
56 public LinearDensityUnit(final LengthUnit lengthUnit, final String nameKey, final String abbreviationKey,
57 final UnitSystem unitSystem)
58 {
59 super(nameKey, abbreviationKey, unitSystem, PER_METER, 1.0 / lengthUnit.getConversionFactorToStandardUnit(),
60 true);
61 this.lengthUnit = lengthUnit;
62 }
63
64 /**
65 * Build a unit with a conversion factor to another unit.
66 * @param nameKey the key to the locale file for the long name of the unit
67 * @param abbreviationKey the key to the locale file for the abbreviation of the unit
68 * @param unitSystem the unit system, e.g. SI or Imperial
69 * @param referenceUnit the unit to convert to
70 * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given
71 * reference unit
72 */
73 public LinearDensityUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
74 final LinearDensityUnit referenceUnit, final double conversionFactorToReferenceUnit)
75 {
76 super(nameKey, abbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit, true);
77 this.lengthUnit = referenceUnit.getLengthUnit();
78 }
79
80 /**
81 * @return timeUnit
82 */
83 public final LengthUnit getLengthUnit()
84 {
85 return this.lengthUnit;
86 }
87
88 /** {@inheritDoc} */
89 @Override
90 public final LinearDensityUnit getStandardUnit()
91 {
92 return PER_METER;
93 }
94
95 /** {@inheritDoc} */
96 @Override
97 public final String getSICoefficientsString()
98 {
99 return "s-1";
100 }
101
102 }