LinearDensityUnit.java

package org.djunits.unit;

import static org.djunits.unit.unitsystem.UnitSystem.IMPERIAL;
import static org.djunits.unit.unitsystem.UnitSystem.OTHER;
import static org.djunits.unit.unitsystem.UnitSystem.SI_DERIVED;

import org.djunits.unit.unitsystem.UnitSystem;

/**
 * Objects per unit of distance.
 * <p>
 * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
 * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
 * <p>
 * $LastChangedDate: 2019-01-18 00:35:01 +0100 (Fri, 18 Jan 2019) $, @version $Revision: 324 $, by $Author: averbraeck $,
 * initial version 11 nov. 2014 <br>
 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
 */
public class LinearDensityUnit extends LinearUnit<LinearDensityUnit>
{
    /** */
    private static final long serialVersionUID = 20141111L;

    /** the actual length unit, e.g. meter. */
    private final LengthUnit lengthUnit;

    /** The SI unit for objects per unit of distance is 1/meter. */
    public static final LinearDensityUnit SI;

    /** 1/am. */
    public static final LinearDensityUnit PER_ATTOMETER;

    /** 1/fm. */
    public static final LinearDensityUnit PER_FEMTOMETER;

    /** 1/pm. */
    public static final LinearDensityUnit PER_PICOMETER;

    /** 1/nm. */
    public static final LinearDensityUnit PER_NANOMETER;

    /** 1/&#181;m. */
    public static final LinearDensityUnit PER_MICROMETER;

    /** 1/meter. */
    public static final LinearDensityUnit PER_METER;

    /** 1/millimeter. */
    public static final LinearDensityUnit PER_MILLIMETER;

    /** 1/centimeter. */
    public static final LinearDensityUnit PER_CENTIMETER;

    /** 1/decimeter. */
    public static final LinearDensityUnit PER_DECIMETER;

    /** 1/decameter. */
    public static final LinearDensityUnit PER_DEKAMETER;

    /** 1/hectometer. */
    public static final LinearDensityUnit PER_HECTOMETER;

    /** 1/kilometer. */
    public static final LinearDensityUnit PER_KILOMETER;

    /** 1/megameter. */
    public static final LinearDensityUnit PER_MEGAMETER;

    /** 1/foot (international) = 0.3048 m = 1/3 yd = 12 inches. */
    public static final LinearDensityUnit PER_FOOT;

    /** 1/inch (international) = 2.54 cm = 1/36 yd = 1/12 ft. */
    public static final LinearDensityUnit PER_INCH;

    /** 1/mile (international) = 5280 ft = 1760 yd. */
    public static final LinearDensityUnit PER_MILE;

    /** 1/nautical mile (international) = 1852 m. */
    public static final LinearDensityUnit PER_NAUTICAL_MILE;

    /** 1/yard (international) = 0.9144 m = 3 ft = 36 in. */
    public static final LinearDensityUnit PER_YARD;

    /** 1/Astronomical Unit. */
    public static final LinearDensityUnit PER_ASTRONOMICAL_UNIT;

    /** 1/Lightyear. */
    public static final LinearDensityUnit PER_LIGHTYEAR;

    /** 1/Parsec. */
    public static final LinearDensityUnit PER_PARSEC;

    /** 1/Angstrom. */
    public static final LinearDensityUnit PER_ANGSTROM;

    static
    {
        SI = new LinearDensityUnit(LengthUnit.METER, "LinearDensityUnit.per_meter", "LinearDensityUnit./m", SI_DERIVED, true);
        PER_METER = SI;
        PER_ATTOMETER = new LinearDensityUnit("LinearDensityUnit.per_attometer", "LinearDensityUnit./am", SI_DERIVED, PER_METER,
                1.0E18, true);
        PER_FEMTOMETER = new LinearDensityUnit("LinearDensityUnit.per_femtometer", "LinearDensityUnit./fm", SI_DERIVED,
                PER_METER, 1.0E15, true);
        PER_PICOMETER = new LinearDensityUnit("LinearDensityUnit.per_picometer", "LinearDensityUnit./pm", SI_DERIVED, PER_METER,
                1.0E12, true);
        PER_NANOMETER = new LinearDensityUnit("LinearDensityUnit.per_nanometer", "LinearDensityUnit./nm", SI_DERIVED, PER_METER,
                1.0E9, true);
        PER_MICROMETER = new LinearDensityUnit("LinearDensityUnit.per_micrometer", "LinearDensityUnit./mum", SI_DERIVED,
                PER_METER, 1.0E6, true);
        PER_MILLIMETER = new LinearDensityUnit("LinearDensityUnit.per_millimeter", "LinearDensityUnit./mm", SI_DERIVED,
                PER_METER, 1000.0, true);
        PER_CENTIMETER = new LinearDensityUnit("LinearDensityUnit.per_centimeter", "LinearDensityUnit./cm", SI_DERIVED,
                PER_METER, 100.0, true);
        PER_DECIMETER = new LinearDensityUnit("LinearDensityUnit.per_decimeter", "LinearDensityUnit./dm", SI_DERIVED, PER_METER,
                10.0, true);
        PER_DEKAMETER = new LinearDensityUnit("LinearDensityUnit.per_dekameter", "LinearDensityUnit./dam", SI_DERIVED,
                PER_METER, 0.1, true);
        PER_HECTOMETER = new LinearDensityUnit("LinearDensityUnit.per_hectometer", "LinearDensityUnit./hm", SI_DERIVED,
                PER_METER, 0.01, true);
        PER_KILOMETER = new LinearDensityUnit("LinearDensityUnit.per_kilometer", "LinearDensityUnit./km", SI_DERIVED, PER_METER,
                0.001, true);
        PER_MEGAMETER = new LinearDensityUnit("LinearDensityUnit.per_megameter", "LinearDensityUnit./Mm", SI_DERIVED, PER_METER,
                1.0E-6, true);
        PER_FOOT = new LinearDensityUnit("LinearDensityUnit.per_foot", "LinearDensityUnit./ft", IMPERIAL, PER_METER,
                1.0 / 0.3048, true);
        PER_INCH = new LinearDensityUnit("LinearDensityUnit.per_inch", "LinearDensityUnit./in", IMPERIAL, PER_FOOT, 12.0, true);
        PER_MILE = new LinearDensityUnit("LinearDensityUnit.per_mile", "LinearDensityUnit./mi", IMPERIAL, PER_FOOT,
                1.0 / 5280.0, true);
        PER_NAUTICAL_MILE = new LinearDensityUnit("LinearDensityUnit.per_nauticalMile", "LinearDensityUnit./NM", IMPERIAL,
                PER_METER, 1.0 / 1852.0, true);
        PER_YARD = new LinearDensityUnit("LinearDensityUnit.per_yard", "LinearDensityUnit./yd", IMPERIAL, PER_FOOT, 1.0 / 3.0,
                true);
        PER_ASTRONOMICAL_UNIT = new LinearDensityUnit("LinearDensityUnit.per_astronomicalUnit", "LinearDensityUnit./AU", OTHER,
                PER_METER, 1.0 / 149597870700.0, true);
        PER_LIGHTYEAR = new LinearDensityUnit("LinearDensityUnit.per_lightyear", "LinearDensityUnit./ly", OTHER, PER_METER,
                1.0 / 9460730472580800.0, true);
        PER_PARSEC = new LinearDensityUnit("LinearDensityUnit.per_parsec", "LinearDensityUnit./pc", OTHER, PER_LIGHTYEAR,
                Math.PI / 648000.0, true);
        PER_ANGSTROM = new LinearDensityUnit("LinearDensityUnit.per_angstrom", "LinearDensityUnit./A", OTHER, PER_METER,
                1.0 / 1E-10, true);
    }

    /**
     * Define a LinearDensityUnit based on length. You can define unit like "per meter" here.
     * @param lengthUnit LengthUnit; the unit of length for the linear density unit, e.g., meter
     * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
     *            name itself
     * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
     *            unit, otherwise the abbreviation itself
     * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
     * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
     *            unit
     */
    private LinearDensityUnit(final LengthUnit lengthUnit, final String nameOrNameKey,
            final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
    {
        super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, PER_METER, 1.0 / lengthUnit.getScaleFactor(),
                standardUnit);
        this.lengthUnit = lengthUnit;
    }

    /**
     * Define a user-defined LinearDensityUnit based on length. You can define unit like "per furlong" here.
     * @param lengthUnit LengthUnit; the unit of length for the linear density unit, e.g., meter
     * @param name String; the long name of the unit
     * @param abbreviation String; the abbreviation of the unit
     * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
     */
    public LinearDensityUnit(final LengthUnit lengthUnit, final String name, final String abbreviation,
            final UnitSystem unitSystem)
    {
        this(lengthUnit, name, abbreviation, unitSystem, false);
    }

    /**
     * Build a LinearDensityUnit with a conversion factor to another LinearDensityUnit.
     * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
     *            name itself
     * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
     *            unit, otherwise the abbreviation itself
     * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
     * @param referenceUnit LinearDensityUnit; the unit to convert to
     * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
     *            unit
     * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
     *            unit
     */
    private LinearDensityUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey,
            final UnitSystem unitSystem, final LinearDensityUnit referenceUnit, final double scaleFactorToReferenceUnit,
            final boolean standardUnit)
    {
        super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
                standardUnit);
        this.lengthUnit = referenceUnit.getLengthUnit();
    }

    /**
     * Build a user-defined LinearDensityUnit with a conversion factor to another LinearDensityUnit.
     * @param name String; the long name of the unit
     * @param abbreviation String; the abbreviation of the unit
     * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
     * @param referenceUnit LinearDensityUnit; the unit to convert to
     * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
     *            unit
     */
    public LinearDensityUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
            final LinearDensityUnit referenceUnit, final double scaleFactorToReferenceUnit)
    {
        this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
    }

    /**
     * @return durationUnit
     */
    public final LengthUnit getLengthUnit()
    {
        return this.lengthUnit;
    }

    /** {@inheritDoc} */
    @Override
    public final LinearDensityUnit getStandardUnit()
    {
        return PER_METER;
    }

    /** {@inheritDoc} */
    @Override
    public final String getSICoefficientsString()
    {
        return "1/m";
    }

}