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-2018 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: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, 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.kilogram", "MassUnit.kg", SI_BASE);
116         KILOGRAM = SI;
117         GRAM = new MassUnit("MassUnit.gram", "MassUnit.g", SI_BASE, KILOGRAM, 0.001, true);
118         FEMTOGRAM = new MassUnit("MassUnit.femtogram", "MassUnit.fg", SI_DERIVED, GRAM, 1.0E-15, true);
119         PICOGRAM = new MassUnit("MassUnit.picogram", "MassUnit.pg", SI_DERIVED, GRAM, 1.0E-12, true);
120         NANOGRAM = new MassUnit("MassUnit.nanogram", "MassUnit.ng", SI_DERIVED, GRAM, 1.0E-9, true);
121         MICROGRAM = new MassUnit("MassUnit.microgram", "MassUnit.mug", SI_DERIVED, GRAM, 1.0E-6, true);
122         MILLIGRAM = new MassUnit("MassUnit.milligram", "MassUnit.mg", SI_DERIVED, GRAM, 0.001, true);
123         MEGAGRAM = new MassUnit("MassUnit.megagram", "MassUnit.Mg", SI_DERIVED, GRAM, 1.0E6, true);
124         GIGAGRAM = new MassUnit("MassUnit.gigagram", "MassUnit.Gg", SI_DERIVED, GRAM, 1.0E9, true);
125         TERAGRAM = new MassUnit("MassUnit.teragram", "MassUnit.Tg", SI_DERIVED, GRAM, 1.0E12, true);
126         PETAGRAM = new MassUnit("MassUnit.petagram", "MassUnit.Pg", SI_DERIVED, GRAM, 1.0E15, true);
127         POUND = new MassUnit("MassUnit.pound", "MassUnit.lb", IMPERIAL, KILOGRAM, 0.45359237, true);
128         OUNCE = new MassUnit("MassUnit.ounce", "MassUnit.oz", IMPERIAL, POUND, 1.0 / 16.0, true);
129         TON_LONG = new MassUnit("MassUnit.long_ton", "MassUnit.long_tn", IMPERIAL, POUND, 2240.0, true);
130         TON_SHORT = new MassUnit("MassUnit.short_ton", "MassUnit.sh_tn", US_CUSTOMARY, POUND, 2000.0, true);
131         TON_METRIC = new MassUnit("MassUnit.metric_ton", "MassUnit.t", SI_ACCEPTED, KILOGRAM, 1000.0, true);
132         TONNE = new MassUnit("MassUnit.tonne_(mts)", "MassUnit.t_(mts)", MTS, KILOGRAM, 1000.0, true);
133         DALTON = new MassUnit("MassUnit.dalton", "MassUnit.Da", SI_ACCEPTED, KILOGRAM, 1.6605388628E-27, true);
134         ELECTRONVOLT = new MassUnit("MassUnit.electronvolt", "MassUnit.eV", OTHER, KILOGRAM, 1.782661907E-36, true);
135         MICROELECTRONVOLT = new MassUnit("MassUnit.microelectronvolt", "MassUnit.mueV", OTHER, ELECTRONVOLT, 1.0E-6, true);
136         MILLIELECTRONVOLT = new MassUnit("MassUnit.millielectronvolt", "MassUnit.meV", OTHER, ELECTRONVOLT, 1.0E-3, true);
137         KILOELECTRONVOLT = new MassUnit("MassUnit.kiloelectronvolt", "MassUnit.keV", OTHER, ELECTRONVOLT, 1.0E3, true);
138         MEGAELECTRONVOLT = new MassUnit("MassUnit.megaelectronvolt", "MassUnit.MeV", OTHER, ELECTRONVOLT, 1.0E6, true);
139         GIGAELECTRONVOLT = new MassUnit("MassUnit.gigaelectronvolt", "MassUnit.GeV", OTHER, ELECTRONVOLT, 1.0E9, true);
140         TERAELECTRONVOLT = new MassUnit("MassUnit.teraelectronvolt", "MassUnit.TeV", OTHER, ELECTRONVOLT, 1.0E12, true);
141         PETAELECTRONVOLT = new MassUnit("MassUnit.petaelectronvolt", "MassUnit.PeV", OTHER, ELECTRONVOLT, 1.0E15, true);
142         EXAELECTRONVOLT = new MassUnit("MassUnit.exaelectronvolt", "MassUnit.EeV", OTHER, ELECTRONVOLT, 1.0E18, true);
143     }
144 
145     /**
146      * Build a standard MassUnit.
147      * @param nameKey the key to the locale file for the long name of the unit
148      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
149      * @param unitSystem the unit system, e.g. SI or Imperial
150      */
151     private MassUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem)
152     {
153         super(nameKey, abbreviationKey, unitSystem, true);
154     }
155 
156     /**
157      * Build a MassUnit with a conversion factor to another MassUnit.
158      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
159      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
160      *            otherwise the abbreviation itself
161      * @param unitSystem the unit system, e.g. SI or Imperial
162      * @param referenceUnit the unit to convert to
163      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
164      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
165      */
166     private MassUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
167             final MassUnit referenceUnit, final double scaleFactorToReferenceUnit, final boolean standardUnit)
168     {
169         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
170                 standardUnit);
171     }
172 
173     /**
174      * Build a user-defined MassUnit with a conversion factor to another MassUnit.
175      * @param name the long name of the unit
176      * @param abbreviation the abbreviation of the unit
177      * @param unitSystem the unit system, e.g. SI or Imperial
178      * @param referenceUnit the unit to convert to
179      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
180      */
181     public MassUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final MassUnit referenceUnit,
182             final double scaleFactorToReferenceUnit)
183     {
184         this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
185     }
186 
187     /** {@inheritDoc} */
188     @Override
189     public final MassUnit getStandardUnit()
190     {
191         return KILOGRAM;
192     }
193 
194     /** {@inheritDoc} */
195     @Override
196     public final String getSICoefficientsString()
197     {
198         return "kg";
199     }
200 
201 }