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.OTHER;
6   import static org.djunits.unit.unitsystem.UnitSystem.SI_ACCEPTED;
7   import static org.djunits.unit.unitsystem.UnitSystem.SI_BASE;
8   import static org.djunits.unit.unitsystem.UnitSystem.SI_DERIVED;
9   import static org.djunits.unit.unitsystem.UnitSystem.US_CUSTOMARY;
10  
11  import org.djunits.unit.unitsystem.UnitSystem;
12  
13  /**
14   * Standard mass units. Several conversion factors have been taken from
15   * <a href="http://en.wikipedia.org/wiki/Conversion_of_units">http://en.wikipedia.org/wiki/Conversion_of_units</a>.
16   * <p>
17   * Copyright (c) 2015-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
18   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
19   * <p>
20   * $LastChangedDate: 2019-03-02 19:06:46 +0100 (Sat, 02 Mar 2019) $, @version $Revision: 342 $, by $Author: averbraeck $,
21   * initial version May 15, 2014 <br>
22   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
23   */
24  public class MassUnit extends LinearUnit<MassUnit>
25  {
26      /** */
27      private static final long serialVersionUID = 20140607L;
28  
29      /** The SI unit for mass is kilogram. */
30      public static final MassUnit SI;
31  
32      /** kilogram. */
33      public static final MassUnit KILOGRAM;
34  
35      /** femtogram. */
36      public static final MassUnit FEMTOGRAM;
37  
38      /** picogram. */
39      public static final MassUnit PICOGRAM;
40  
41      /** nanogram. */
42      public static final MassUnit NANOGRAM;
43  
44      /** microgram. */
45      public static final MassUnit MICROGRAM;
46  
47      /** milligram. */
48      public static final MassUnit MILLIGRAM;
49  
50      /** gram. */
51      public static final MassUnit GRAM;
52  
53      /** megagram. */
54      public static final MassUnit MEGAGRAM;
55  
56      /** gigagram. */
57      public static final MassUnit GIGAGRAM;
58  
59      /** teragram. */
60      public static final MassUnit TERAGRAM;
61  
62      /** petagram. */
63      public static final MassUnit PETAGRAM;
64  
65      /** pound. */
66      public static final MassUnit POUND;
67  
68      /** pound. */
69      public static final MassUnit OUNCE;
70  
71      /** long ton = 2240 lb. */
72      public static final MassUnit TON_LONG;
73  
74      /** short ton = 2000 lb. */
75      public static final MassUnit TON_SHORT;
76  
77      /** metric ton = 1000 kg. */
78      public static final MassUnit TON_METRIC;
79  
80      /** metric ton = 1000 kg. */
81      public static final MassUnit TONNE;
82  
83      /** dalton. */
84      public static final MassUnit DALTON;
85  
86      /** microelectronvolt. */
87      public static final MassUnit MICROELECTRONVOLT;
88  
89      /** millielectronvolt. */
90      public static final MassUnit MILLIELECTRONVOLT;
91  
92      /** electronvolt = 1.782661907E-36 kg. See http://physics.nist.gov/cuu/Constants/Table/allascii.txt. */
93      public static final MassUnit ELECTRONVOLT;
94  
95      /** kiloelectronvolt. */
96      public static final MassUnit KILOELECTRONVOLT;
97  
98      /** megaelectronvolt. */
99      public static final MassUnit MEGAELECTRONVOLT;
100 
101     /** gigaelectronvolt. */
102     public static final MassUnit GIGAELECTRONVOLT;
103 
104     /** teraelectronvolt. */
105     public static final MassUnit TERAELECTRONVOLT;
106 
107     /** petaelectronvolt. */
108     public static final MassUnit PETAELECTRONVOLT;
109 
110     /** exaelectronvolt. */
111     public static final MassUnit EXAELECTRONVOLT;
112 
113     static
114     {
115         SI = new MassUnit("MassUnit.kg", SI_BASE);
116         KILOGRAM = SI;
117         GRAM = new MassUnit("MassUnit.g", SI_BASE, KILOGRAM, 0.001);
118         FEMTOGRAM = new MassUnit("MassUnit.fg", SI_DERIVED, GRAM, 1.0E-15);
119         PICOGRAM = new MassUnit("MassUnit.pg", SI_DERIVED, GRAM, 1.0E-12);
120         NANOGRAM = new MassUnit("MassUnit.ng", SI_DERIVED, GRAM, 1.0E-9);
121         MICROGRAM = new MassUnit("MassUnit.mug", SI_DERIVED, GRAM, 1.0E-6);
122         MILLIGRAM = new MassUnit("MassUnit.mg", SI_DERIVED, GRAM, 0.001);
123         MEGAGRAM = new MassUnit("MassUnit.Mg", SI_DERIVED, GRAM, 1.0E6);
124         GIGAGRAM = new MassUnit("MassUnit.Gg", SI_DERIVED, GRAM, 1.0E9);
125         TERAGRAM = new MassUnit("MassUnit.Tg", SI_DERIVED, GRAM, 1.0E12);
126         PETAGRAM = new MassUnit("MassUnit.Pg", SI_DERIVED, GRAM, 1.0E15);
127         POUND = new MassUnit("MassUnit.lb", IMPERIAL, KILOGRAM, 0.45359237);
128         OUNCE = new MassUnit("MassUnit.oz", IMPERIAL, POUND, 1.0 / 16.0);
129         TON_LONG = new MassUnit("MassUnit.long_tn", IMPERIAL, POUND, 2240.0);
130         TON_SHORT = new MassUnit("MassUnit.sh_tn", US_CUSTOMARY, POUND, 2000.0);
131         TON_METRIC = new MassUnit("MassUnit.t", SI_ACCEPTED, KILOGRAM, 1000.0);
132         TONNE = new MassUnit("MassUnit.t_(mts)", MTS, KILOGRAM, 1000.0);
133         DALTON = new MassUnit("MassUnit.Da", SI_ACCEPTED, KILOGRAM, 1.6605388628E-27);
134         ELECTRONVOLT = new MassUnit("MassUnit.eV", OTHER, KILOGRAM, 1.782661907E-36);
135         MICROELECTRONVOLT = new MassUnit("MassUnit.mueV", OTHER, ELECTRONVOLT, 1.0E-6);
136         MILLIELECTRONVOLT = new MassUnit("MassUnit.meV", OTHER, ELECTRONVOLT, 1.0E-3);
137         KILOELECTRONVOLT = new MassUnit("MassUnit.keV", OTHER, ELECTRONVOLT, 1.0E3);
138         MEGAELECTRONVOLT = new MassUnit("MassUnit.MeV", OTHER, ELECTRONVOLT, 1.0E6);
139         GIGAELECTRONVOLT = new MassUnit("MassUnit.GeV", OTHER, ELECTRONVOLT, 1.0E9);
140         TERAELECTRONVOLT = new MassUnit("MassUnit.TeV", OTHER, ELECTRONVOLT, 1.0E12);
141         PETAELECTRONVOLT = new MassUnit("MassUnit.PeV", OTHER, ELECTRONVOLT, 1.0E15);
142         EXAELECTRONVOLT = new MassUnit("MassUnit.EeV", OTHER, ELECTRONVOLT, 1.0E18);
143     }
144 
145     /**
146      * Build a standard MassUnit.
147      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
148      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
149      */
150     private MassUnit(final String abbreviationKey, final UnitSystem unitSystem)
151     {
152         super(abbreviationKey, unitSystem);
153     }
154 
155     /**
156      * Build a MassUnit with a conversion factor to another MassUnit.
157      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
158      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
159      * @param referenceUnit MassUnit; the unit to convert to
160      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
161      *            unit
162      */
163     private MassUnit(final String abbreviationKey, final UnitSystem unitSystem, final MassUnit referenceUnit,
164             final double scaleFactorToReferenceUnit)
165     {
166         super(abbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
167     }
168 
169     /**
170      * Build a user-defined MassUnit with a conversion factor to another MassUnit.
171      * @param name String; the long name of the unit
172      * @param abbreviation String; the abbreviation of the unit
173      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
174      * @param referenceUnit MassUnit; the unit to convert to
175      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
176      *            unit
177      */
178     public MassUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final MassUnit referenceUnit,
179             final double scaleFactorToReferenceUnit)
180     {
181         super(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
182     }
183 
184     /** {@inheritDoc} */
185     @Override
186     public final MassUnit getStandardUnit()
187     {
188         return KILOGRAM;
189     }
190 
191     /** {@inheritDoc} */
192     @Override
193     public final String getSICoefficientsString()
194     {
195         return "kg";
196     }
197 
198 }