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.MTS;
5   import static org.djunits.unit.unitsystem.UnitSystem.SI_ACCEPTED;
6   import static org.djunits.unit.unitsystem.UnitSystem.SI_BASE;
7   import static org.djunits.unit.unitsystem.UnitSystem.US_CUSTOMARY;
8   
9   import org.djunits.unit.unitsystem.UnitSystem;
10  
11  /**
12   * Standard mass units. Several conversion factors have been taken from <a
13   * href="http://en.wikipedia.org/wiki/Conversion_of_units">http://en.wikipedia.org/wiki/Conversion_of_units</a>.
14   * <p>
15   * Copyright (c) 2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
17   * <p>
18   * $LastChangedDate: 2015-10-04 20:48:33 +0200 (Sun, 04 Oct 2015) $, @version $Revision: 87 $, by $Author: averbraeck $, initial
19   * version May 15, 2014 <br>
20   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
21   */
22  public class MassUnit extends Unit<MassUnit>
23  {
24      /** */
25      private static final long serialVersionUID = 20140607L;
26  
27      /** The SI unit for mass is kilogram. */
28      public static final MassUnit SI;
29  
30      /** kilogram. */
31      public static final MassUnit KILOGRAM;
32  
33      /** gram. */
34      public static final MassUnit GRAM;
35  
36      /** pound. */
37      public static final MassUnit POUND;
38  
39      /** pound. */
40      public static final MassUnit OUNCE;
41  
42      /** long ton = 2240 lb. */
43      public static final MassUnit TON_LONG;
44  
45      /** short ton = 2000 lb. */
46      public static final MassUnit TON_SHORT;
47  
48      /** metric ton = 1000 kg. */
49      public static final MassUnit TON_METRIC;
50  
51      /** metric ton = 1000 kg. */
52      public static final MassUnit TONNE;
53  
54      /** dalton. */
55      public static final MassUnit DALTON;
56  
57      static
58      {
59          SI = new MassUnit("MassUnit.kilogram", "MassUnit.kg", SI_BASE);
60          KILOGRAM = SI;
61          GRAM = new MassUnit("MassUnit.gram", "MassUnit.g", SI_BASE, KILOGRAM, 0.001, true);
62          POUND = new MassUnit("MassUnit.pound", "MassUnit.lb", IMPERIAL, KILOGRAM, 0.45359237, true);
63          OUNCE = new MassUnit("MassUnit.ounce", "MassUnit.oz", IMPERIAL, POUND, 1.0 / 16.0, true);
64          TON_LONG = new MassUnit("MassUnit.long_ton", "MassUnit.long_tn", IMPERIAL, POUND, 2240.0, true);
65          TON_SHORT = new MassUnit("MassUnit.short_ton", "MassUnit.sh_tn", US_CUSTOMARY, POUND, 2000.0, true);
66          TON_METRIC = new MassUnit("MassUnit.metric_ton", "MassUnit.t", SI_ACCEPTED, KILOGRAM, 1000.0, true);
67          TONNE = new MassUnit("MassUnit.tonne_(mts)", "MassUnit.t_(mts)", MTS, KILOGRAM, 1000.0, true);
68          DALTON = new MassUnit("MassUnit.dalton", "MassUnit.Da", SI_ACCEPTED, KILOGRAM, 1.6605388628E-27, true);
69      }
70  
71      /**
72       * Build a standard MassUnit.
73       * @param nameKey the key to the locale file for the long name of the unit
74       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
75       * @param unitSystem the unit system, e.g. SI or Imperial
76       */
77      private MassUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem)
78      {
79          super(nameKey, abbreviationKey, unitSystem, true);
80      }
81  
82      /**
83       * Build a MassUnit with a conversion factor to another MassUnit.
84       * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
85       * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
86       *            otherwise the abbreviation itself
87       * @param unitSystem the unit system, e.g. SI or Imperial
88       * @param referenceUnit the unit to convert to
89       * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
90       * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
91       */
92      private MassUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey,
93          final UnitSystem unitSystem, final MassUnit referenceUnit, final double conversionFactorToReferenceUnit,
94          final boolean standardUnit)
95      {
96          super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit,
97              standardUnit);
98      }
99  
100     /**
101      * Build a user-defined MassUnit with a conversion factor to another MassUnit.
102      * @param name the long name of the unit
103      * @param abbreviation the abbreviation of the unit
104      * @param unitSystem the unit system, e.g. SI or Imperial
105      * @param referenceUnit the unit to convert to
106      * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
107      */
108     public MassUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
109         final MassUnit referenceUnit, final double conversionFactorToReferenceUnit)
110     {
111         this(name, abbreviation, unitSystem, referenceUnit, conversionFactorToReferenceUnit, false);
112     }
113 
114     /** {@inheritDoc} */
115     @Override
116     public final MassUnit getStandardUnit()
117     {
118         return KILOGRAM;
119     }
120 
121     /** {@inheritDoc} */
122     @Override
123     public final String getSICoefficientsString()
124     {
125         return "kg";
126     }
127 
128 }