View Javadoc
1   package org.opentrafficsim.core.unit;
2   
3   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.IMPERIAL;
4   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.MTS;
5   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_ACCEPTED;
6   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_BASE;
7   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.US_CUSTOMARY;
8   
9   import org.opentrafficsim.core.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) 2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
17   * <p>
18   * @version May 15, 2014 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   */
21  public class MassUnit extends Unit<MassUnit>
22  {
23      /** */
24      private static final long serialVersionUID = 20140607L;
25  
26      /** The SI unit for mass is kilogram. */
27      public static final MassUnit SI;
28  
29      /** kilogram. */
30      public static final MassUnit KILOGRAM;
31  
32      /** gram. */
33      public static final MassUnit GRAM;
34  
35      /** pound. */
36      public static final MassUnit POUND;
37  
38      /** pound. */
39      public static final MassUnit OUNCE;
40  
41      /** long ton = 2240 lb. */
42      public static final MassUnit TON_LONG;
43  
44      /** short ton = 2000 lb. */
45      public static final MassUnit TON_SHORT;
46  
47      /** metric ton = 1000 kg. */
48      public static final MassUnit TON_METRIC;
49  
50      /** metric ton = 1000 kg. */
51      public static final MassUnit TONNE;
52  
53      /** electronvolt via E=mc^2. */
54      public static final MassUnit ELECTRONVOLT;
55  
56      /** dalton. */
57      public static final MassUnit DALTON;
58  
59      static
60      {
61          SI = new MassUnit("MassUnit.kilogram", "MassUnit.kg", SI_BASE);
62          KILOGRAM = SI;
63          GRAM = new MassUnit("MassUnit.gram", "MassUnit.g", SI_BASE, KILOGRAM, 0.001);
64          POUND = new MassUnit("MassUnit.pound", "MassUnit.lb", IMPERIAL, KILOGRAM, 0.45359237);
65          OUNCE = new MassUnit("MassUnit.ounce", "MassUnit.oz", IMPERIAL, POUND, 1.0 / 16.0);
66          TON_LONG = new MassUnit("MassUnit.long_ton", "MassUnit.long_tn", IMPERIAL, POUND, 2240.0);
67          TON_SHORT = new MassUnit("MassUnit.short_ton", "MassUnit.sh_tn", US_CUSTOMARY, POUND, 2000.0);
68          TON_METRIC = new MassUnit("MassUnit.metric_ton", "MassUnit.t", SI_ACCEPTED, KILOGRAM, 1000.0);
69          TONNE = new MassUnit("MassUnit.tonne_(mts)", "MassUnit.t_(mts)", MTS, KILOGRAM, 1000.0);
70          ELECTRONVOLT = new MassUnit("MassUnit.electronvolt", "MassUnit.eV", SI_ACCEPTED, KILOGRAM, 1.78266184539E-36);
71          DALTON = new MassUnit("MassUnit.dalton", "MassUnit.Da", SI_ACCEPTED, KILOGRAM, 1.6605388628E-27);
72      }
73  
74      /**
75       * Build a standard unit.
76       * @param nameKey the key to the locale file for the long name of the unit
77       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
78       * @param unitSystem the unit system, e.g. SI or Imperial
79       */
80      public MassUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem)
81      {
82          super(nameKey, abbreviationKey, unitSystem, true);
83      }
84  
85      /**
86       * Build a unit with a conversion factor to another unit.
87       * @param nameKey the key to the locale file for the long name of the unit
88       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
89       * @param unitSystem the unit system, e.g. SI or Imperial
90       * @param referenceUnit the unit to convert to
91       * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given
92       *            reference unit
93       */
94      public MassUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
95              final MassUnit referenceUnit, final double conversionFactorToReferenceUnit)
96      {
97          super(nameKey, abbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit, true);
98      }
99  
100     /** {@inheritDoc} */
101     @Override
102     public final MassUnit getStandardUnit()
103     {
104         return KILOGRAM;
105     }
106 
107     /** {@inheritDoc} */
108     @Override
109     public final String getSICoefficientsString()
110     {
111         return "kg";
112     }
113 
114 }