001/*
002 * Units of Measurement Implementation for Java SE
003 * Copyright (c) 2005-2017, Jean-Marie Dautelle, Werner Keil, V2COM.
004 *
005 * All rights reserved.
006 *
007 * Redistribution and use in source and binary forms, with or without modification,
008 * are permitted provided that the following conditions are met:
009 *
010 * 1. Redistributions of source code must retain the above copyright notice,
011 *    this list of conditions and the following disclaimer.
012 *
013 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
014 *    and the following disclaimer in the documentation and/or other materials provided with the distribution.
015 *
016 * 3. Neither the name of JSR-363 nor the names of its contributors may be used to endorse or promote products
017 *    derived from this software without specific prior written permission.
018 *
019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
021 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
023 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
026 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029 */
030package tec.uom.se.unit;
031
032import static tec.uom.se.AbstractUnit.ONE;
033import tec.uom.lib.common.function.Nameable;
034import tec.uom.se.AbstractSystemOfUnits;
035import tec.uom.se.AbstractUnit;
036import tec.uom.se.function.AddConverter;
037import tec.uom.se.function.PiMultiplierConverter;
038import tec.uom.se.function.RationalConverter;
039import tec.uom.se.quantity.QuantityDimension;
040
041import javax.measure.Quantity;
042import javax.measure.Unit;
043import javax.measure.quantity.Acceleration;
044import javax.measure.quantity.AmountOfSubstance;
045import javax.measure.quantity.Angle;
046import javax.measure.quantity.Area;
047import javax.measure.quantity.CatalyticActivity;
048import javax.measure.quantity.Dimensionless;
049import javax.measure.quantity.ElectricCapacitance;
050import javax.measure.quantity.ElectricCharge;
051import javax.measure.quantity.ElectricConductance;
052import javax.measure.quantity.ElectricCurrent;
053import javax.measure.quantity.ElectricInductance;
054import javax.measure.quantity.ElectricPotential;
055import javax.measure.quantity.ElectricResistance;
056import javax.measure.quantity.Energy;
057import javax.measure.quantity.Force;
058import javax.measure.quantity.Frequency;
059import javax.measure.quantity.Illuminance;
060import javax.measure.quantity.Length;
061import javax.measure.quantity.LuminousFlux;
062import javax.measure.quantity.LuminousIntensity;
063import javax.measure.quantity.MagneticFlux;
064import javax.measure.quantity.MagneticFluxDensity;
065import javax.measure.quantity.Mass;
066import javax.measure.quantity.Power;
067import javax.measure.quantity.Pressure;
068import javax.measure.quantity.RadiationDoseAbsorbed;
069import javax.measure.quantity.RadiationDoseEffective;
070import javax.measure.quantity.Radioactivity;
071import javax.measure.quantity.SolidAngle;
072import javax.measure.quantity.Speed;
073import javax.measure.quantity.Temperature;
074import javax.measure.quantity.Time;
075import javax.measure.quantity.Volume;
076import javax.measure.spi.SystemOfUnits;
077
078/**
079 * <p>
080 * This class defines commonly used units.
081 *
082 * @author <a href="mailto:units@catmedia.us">Werner Keil</a>
083 * @version 1.0.1, Jan 20, 2017
084 */
085public class Units extends AbstractSystemOfUnits implements Nameable {
086
087  protected Units() {
088  }
089
090  private static final Units INSTANCE = new Units();
091
092  public String getName() {
093    return Units.class.getSimpleName();
094  }
095
096  // //////////////
097  // BASE UNITS //
098  // //////////////
099
100  /**
101   * The SI base unit for electric current quantities (standard name <code>A</code>). The Ampere is that constant current which, if maintained in two
102   * straight parallel conductors of infinite length, of negligible circular cross-section, and placed 1 meter apart in vacuum, would produce between
103   * these conductors a force equal to 2 * 10-7 newton per meter of length. It is named after the French physicist Andre Ampere (1775-1836).
104   * 
105   * @implNote SI Base Unit
106   */
107  public static final BaseUnit<ElectricCurrent> AMPERE = addUnit(new BaseUnit<ElectricCurrent>("A", QuantityDimension.ELECTRIC_CURRENT),
108      ElectricCurrent.class);
109
110  /**
111   * The SI base unit for luminous intensity quantities (standard name <code>cd</code>). The candela is the luminous intensity, in a given direction,
112   * of a source that emits monochromatic radiation of frequency 540 * 1012 hertz and that has a radiant intensity in that direction of 1/683 watt per
113   * steradian
114   * 
115   * @see <a href="http://en.wikipedia.org/wiki/Candela"> Wikipedia: Candela</a>
116   *
117   * @implNote SI Base Unit
118   */
119  public static final BaseUnit<LuminousIntensity> CANDELA = addUnit(new BaseUnit<LuminousIntensity>("cd", QuantityDimension.LUMINOUS_INTENSITY),
120      LuminousIntensity.class);
121
122  /**
123   * The SI base unit for thermodynamic temperature quantities (standard name <code>K</code>). The kelvin is the 1/273.16th of the thermodynamic
124   * temperature of the triple point of water. It is named after the Scottish mathematician and physicist William Thomson 1st Lord Kelvin (1824-1907)
125   * 
126   * @implNote SI Base Unit
127   */
128  public static final BaseUnit<Temperature> KELVIN = addUnit(new BaseUnit<Temperature>("K", QuantityDimension.TEMPERATURE), Temperature.class);
129
130  /**
131   * The SI base unit for mass quantities (standard name <code>kg</code>). It is the only SI unit with a prefix as part of its name and symbol. The
132   * kilogram is equal to the mass of an international prototype in the form of a platinum-iridium cylinder kept at Sevres in France.
133   * 
134   * @see #GRAM
135   *
136   * @implNote SI Base Unit
137   */
138  public static final BaseUnit<Mass> KILOGRAM = addUnit(new BaseUnit<Mass>("kg", QuantityDimension.MASS), Mass.class);
139
140  /**
141   * The SI base unit for length quantities (standard name <code>m</code>). One metre was redefined in 1983 as the distance traveled by light in a
142   * vacuum in 1/299,792,458 of a second.
143   * 
144   * @implNote SI Base Unit
145   */
146  public static final Unit<Length> METRE = addUnit(new BaseUnit<>("m", QuantityDimension.LENGTH), Length.class);
147
148  /**
149   * The SI base unit for amount of substance quantities (standard name <code>mol</code>). The mole is the amount of substance of a system which
150   * contains as many elementary entities as there are atoms in 0.012 kilogram of carbon 12.
151   * 
152   * @implNote SI Base Unit
153   */
154  public static final Unit<AmountOfSubstance> MOLE = addUnit(new BaseUnit<>("mol", QuantityDimension.AMOUNT_OF_SUBSTANCE), AmountOfSubstance.class);
155
156  /**
157   * The SI base unit for duration quantities (standard name <code>s</code>). It is defined as the duration of 9,192,631,770 cycles of radiation
158   * corresponding to the transition between two hyperfine levels of the ground state of cesium (1967 Standard).
159   * 
160   * @implNote SI Base Unit
161   */
162  public static final Unit<Time> SECOND = addUnit(new BaseUnit<>("s", QuantityDimension.TIME), Time.class);
163
164  // //////////////////////////////
165  // SI DERIVED ALTERNATE UNITS //
166  // //////////////////////////////
167
168  /**
169   * The SI derived unit for mass quantities (standard name <code>g</code>). The base unit for mass quantity is {@link #KILOGRAM}.
170   */
171  public static final Unit<Mass> GRAM = addUnit(KILOGRAM.divide(1000));
172  // = new TransformedUnit(KILOGRAM, MetricPrefix.KILO.getConverter());
173
174  /**
175   * The SI unit for plane angle quantities (standard name <code>rad</code>). One radian is the angle between two radii of a circle such that the
176   * length of the arc between them is equal to the radius.
177   */
178  public static final Unit<Angle> RADIAN = addUnit(new AlternateUnit<>(ONE, "rad"), Angle.class);
179
180  /**
181   * The SI unit for solid angle quantities (standard name <code>sr</code>). One steradian is the solid angle subtended at the center of a sphere by
182   * an area on the surface of the sphere that is equal to the radius squared. The total solid angle of a sphere is 4*Pi steradians.
183   */
184  public static final AlternateUnit<SolidAngle> STERADIAN = addUnit(new AlternateUnit<SolidAngle>(ONE, "sr"), SolidAngle.class);
185
186  /**
187   * The SI unit for frequency (standard name <code>Hz</code>). A unit of frequency equal to one cycle per second. After Heinrich Rudolf Hertz
188   * (1857-1894), German physicist who was the first to produce radio waves artificially.
189   */
190  public static final AlternateUnit<Frequency> HERTZ = addUnit(new AlternateUnit<Frequency>(ONE.divide(SECOND), "Hz"), Frequency.class);
191
192  /**
193   * The SI unit for force (standard name <code>N</code>). One newton is the force required to give a mass of 1 kilogram an Force of 1 metre per
194   * second per second. It is named after the English mathematician and physicist Sir Isaac Newton (1642-1727).
195   */
196  public static final AlternateUnit<Force> NEWTON = addUnit(new AlternateUnit<Force>(METRE.multiply(KILOGRAM).divide(SECOND.pow(2)), "N"),
197      Force.class);
198
199  /**
200   * The SI unit for pressure, stress (standard name <code>Pa</code>). One pascal is equal to one newton per square meter. It is named after the
201   * French philosopher and mathematician Blaise Pascal (1623-1662).
202   */
203  @SuppressWarnings({ "unchecked", "rawtypes" })
204  public static final AlternateUnit<Pressure> PASCAL = addUnit(new AlternateUnit(NEWTON.divide(METRE.pow(2)), "Pa"), Pressure.class);
205
206  /**
207   * The SI unit for energy, work, quantity of heat (<code>J</code>). One joule is the amount of work done when an applied force of 1 newton moves
208   * through a distance of 1 metre in the direction of the force. It is named after the English physicist James Prescott Joule (1818-1889).
209   */
210  public static final AlternateUnit<Energy> JOULE = addUnit(new AlternateUnit<Energy>(NEWTON.multiply(METRE), "J"), Energy.class);
211
212  /**
213   * The SI unit for power, radiant, flux (standard name <code>W</code>). One watt is equal to one joule per second. It is named after the British
214   * scientist James Watt (1736-1819).
215   */
216  public static final AlternateUnit<Power> WATT = addUnit(new AlternateUnit<Power>(JOULE.divide(SECOND), "W"), Power.class);
217
218  /**
219   * The SI unit for electric charge, quantity of electricity (standard name <code>C</code>). One Coulomb is equal to the quantity of charge
220   * transferred in one second by a steady current of one ampere. It is named after the French physicist Charles Augustin de Coulomb (1736-1806).
221   */
222  public static final AlternateUnit<ElectricCharge> COULOMB = addUnit(new AlternateUnit<ElectricCharge>(SECOND.multiply(AMPERE), "C"),
223      ElectricCharge.class);
224
225  /**
226   * The SI unit for electric potential difference, electromotive force (standard name <code>V</code>). One Volt is equal to the difference of
227   * electric potential between two points on a conducting wire carrying a constant current of one ampere when the power dissipated between the points
228   * is one watt. It is named after the Italian physicist Count Alessandro Volta (1745-1827).
229   */
230  public static final AlternateUnit<ElectricPotential> VOLT = addUnit(new AlternateUnit<ElectricPotential>(WATT.divide(AMPERE), "V"),
231      ElectricPotential.class);
232
233  /**
234   * The SI unit for capacitance (standard name <code>F</code>). One Farad is equal to the capacitance of a capacitor having an equal and opposite
235   * charge of 1 coulomb on each plate and a potential difference of 1 volt between the plates. It is named after the British physicist and chemist
236   * Michael Faraday (1791-1867).
237   */
238  public static final AlternateUnit<ElectricCapacitance> FARAD = addUnit(new AlternateUnit<ElectricCapacitance>(COULOMB.divide(VOLT), "F"),
239      ElectricCapacitance.class);
240
241  /**
242   * The SI unit for electric resistance (standard name <code>Ohm</code>). One Ohm is equal to the resistance of a conductor in which a current of one
243   * ampere is produced by a potential of one volt across its terminals. It is named after the German physicist Georg Simon Ohm (1789-1854).
244   */
245  public static final AlternateUnit<ElectricResistance> OHM = addUnit(new AlternateUnit<ElectricResistance>(VOLT.divide(AMPERE), "Ω"),
246      ElectricResistance.class);
247
248  /**
249   * The SI unit for electric conductance (standard name <code>S</code>). One Siemens is equal to one ampere per volt. It is named after the German
250   * engineer Ernst Werner von Siemens (1816-1892).
251   */
252  public static final AlternateUnit<ElectricConductance> SIEMENS = addUnit(new AlternateUnit<ElectricConductance>(AMPERE.divide(VOLT), "S"),
253      ElectricConductance.class);
254
255  /**
256   * The SI unit for magnetic flux (standard name <code>Wb</code>). One Weber is equal to the magnetic flux that in linking a circuit of one turn
257   * produces in it an electromotive force of one volt as it is uniformly reduced to zero within one second. It is named after the German physicist
258   * Wilhelm Eduard Weber (1804-1891).
259   */
260  public static final AlternateUnit<MagneticFlux> WEBER = addUnit(new AlternateUnit<MagneticFlux>(VOLT.multiply(SECOND), "Wb"), MagneticFlux.class);
261
262  /**
263   * The alternate unit for magnetic flux density (standard name <code>T</code>). One Tesla is equal equal to one weber per square metre. It is named
264   * after the Serbian-born American electrical engineer and physicist Nikola Tesla (1856-1943).
265   */
266  public static final AlternateUnit<MagneticFluxDensity> TESLA = addUnit(new AlternateUnit<MagneticFluxDensity>(WEBER.divide(METRE.pow(2)), "T"),
267      MagneticFluxDensity.class);
268
269  /**
270   * The alternate unit for inductance (standard name <code>H</code>). One Henry is equal to the inductance for which an induced electromotive force
271   * of one volt is produced when the current is varied at the rate of one ampere per second. It is named after the American physicist Joseph Henry
272   * (1791-1878).
273   */
274  public static final AlternateUnit<ElectricInductance> HENRY = addUnit(new AlternateUnit<ElectricInductance>(WEBER.divide(AMPERE), "H"),
275      ElectricInductance.class);
276
277  /**
278   * The SI unit for Celsius temperature (standard name <code>Cel</code>). This is a unit of temperature such as the freezing point of water (at one
279   * atmosphere of pressure) is 0 Cel, while the boiling point is 100 Cel.
280   */
281  @SuppressWarnings({ "rawtypes", "unchecked" })
282  public static final TransformedUnit<Temperature> CELSIUS = addUnit(new TransformedUnit(KELVIN, new AddConverter(273.15)));
283  // Not mapping to Temperature since temperature is mapped to Kelvin.
284
285  /**
286   * The SI unit for luminous flux (standard name <code>lm</code>). One Lumen is equal to the amount of light given out through a solid angle by a
287   * source of one candela intensity radiating equally in all directions.
288   */
289  public static final AlternateUnit<LuminousFlux> LUMEN = addUnit(new AlternateUnit<LuminousFlux>(CANDELA.multiply(STERADIAN), "lm"),
290      LuminousFlux.class);
291
292  /**
293   * The SI unit for illuminance (standard name <code>lx</code>). One Lux is equal to one lumen per square metre.
294   */
295  public static final AlternateUnit<Illuminance> LUX = addUnit(new AlternateUnit<Illuminance>(LUMEN.divide(METRE.pow(2)), "lx"), Illuminance.class);
296
297  /**
298   * The SI unit for activity of a radionuclide (standard name <code>Bq</code> ). One becquerel is the radiation caused by one disintegration per
299   * second. It is named after the French physicist, Antoine-Henri Becquerel (1852-1908).
300   */
301  public static final AlternateUnit<Radioactivity> BECQUEREL = addUnit(new AlternateUnit<Radioactivity>(ONE.divide(SECOND), "Bq"),
302      Radioactivity.class);
303
304  /**
305   * The SI unit for absorbed dose, specific energy (imparted), kerma (standard name <code>Gy</code>). One gray is equal to the dose of one joule of
306   * energy absorbed per one kilogram of matter. It is named after the British physician L. H. Gray (1905-1965).
307   */
308  public static final AlternateUnit<RadiationDoseAbsorbed> GRAY = addUnit(new AlternateUnit<RadiationDoseAbsorbed>(JOULE.divide(KILOGRAM), "Gy"),
309      RadiationDoseAbsorbed.class);
310
311  /**
312   * The SI unit for dose equivalent (standard name <code>Sv</code>). One Sievert is equal is equal to the actual dose, in grays, multiplied by a
313   * "quality factor" which is larger for more dangerous forms of radiation. It is named after the Swedish physicist Rolf Sievert (1898-1966).
314   */
315  public static final AlternateUnit<RadiationDoseEffective> SIEVERT = addUnit(
316      new AlternateUnit<RadiationDoseEffective>(JOULE.divide(KILOGRAM), "Sv"), RadiationDoseEffective.class);
317
318  /**
319   * The SI unit for catalytic activity (standard name <code>kat</code>).
320   */
321  public static final AlternateUnit<CatalyticActivity> KATAL = addUnit(new AlternateUnit<CatalyticActivity>(MOLE.divide(SECOND), "kat"),
322      CatalyticActivity.class);
323
324  // ////////////////////////////
325  // SI DERIVED PRODUCT UNITS //
326  // ////////////////////////////
327
328  /**
329   * The SI unit for velocity quantities (standard name <code>m/s</code>).
330   */
331  public static final Unit<Speed> METRE_PER_SECOND = addUnit(new ProductUnit<>(METRE.divide(SECOND)), Speed.class);
332
333  /**
334   * Alias for METRE_PER_SECOND
335   * 
336   * @deprecated use METRE_PER_SECOND
337   */
338  static final Unit<Speed> METRES_PER_SECOND = METRE_PER_SECOND;
339
340  /**
341   * The SI unit for acceleration quantities (standard name <code>m/s2</code> ).
342   */
343  public static final Unit<Acceleration> METRE_PER_SQUARE_SECOND = addUnit(new ProductUnit<>(METRE_PER_SECOND.divide(SECOND)), Acceleration.class);
344
345  /**
346   * Alias for METRE_PER_SQUARE_SECOND
347   * 
348   * @deprecated use METRE_PER_SQUARE_SECOND
349   */
350  static final Unit<Acceleration> METRES_PER_SQUARE_SECOND = METRE_PER_SQUARE_SECOND;
351
352  /**
353   * The SI unit for area quantities (standard name <code>m2</code>).
354   */
355  public static final Unit<Area> SQUARE_METRE = addUnit(new ProductUnit<>(METRE.multiply(METRE)), Area.class);
356
357  /**
358   * The SI unit for volume quantities (standard name <code>m3</code>).
359   */
360  public static final ProductUnit<Volume> CUBIC_METRE = addUnit(new ProductUnit<Volume>(SQUARE_METRE.multiply(METRE)), Volume.class);
361
362  /**
363   * A unit of velocity expressing the number of international {@link #KILOMETRE kilometres} per {@link #HOUR hour} (abbreviation <code>km/h</code>).
364   */
365  public static final Unit<Speed> KILOMETRE_PER_HOUR = addUnit(METRES_PER_SECOND.multiply(0.277778d)).asType(Speed.class);
366
367  /**
368   * Alias for KILOMETRE_PER_HOUR
369   * 
370   * @deprecated use KILOMETRE_PER_HOUR
371   */
372  static final Unit<Speed> KILOMETRES_PER_HOUR = KILOMETRE_PER_HOUR;
373
374  // ///////////////////////////////////////////////////////////////
375  // CommonUnits outside the SI that are accepted for use with the Units. //
376  // ///////////////////////////////////////////////////////////////
377
378  /**
379   * A dimensionless unit accepted for use with SI units (standard name <code>%</code>).
380   */
381  public static final TransformedUnit<Dimensionless> PERCENT = addUnit(new TransformedUnit<>(ONE, new RationalConverter(1, 100)));
382
383  // ////////
384  // Time //
385  // ////////
386  /**
387   * A time unit accepted for use with SI units (standard name <code>min</code>).
388   */
389  public static final Unit<Time> MINUTE = addUnit(new TransformedUnit<>("min", SECOND, new RationalConverter(60, 1)));
390
391  /**
392   * A time unit accepted for use with SI units (standard name <code>h</code> ).
393   */
394  public static final Unit<Time> HOUR = addUnit(new TransformedUnit<>("h", SECOND, new RationalConverter(60 * 60, 1)));
395
396  /**
397   * A time unit accepted for use with SI units (standard name <code>d</code> ).
398   */
399  public static final Unit<Time> DAY = addUnit(new TransformedUnit<>("d", SECOND, new RationalConverter(24 * 60 * 60, 1)), Time.class);
400
401  /**
402   * A unit of duration equal to 7 {@link #DAY} (standard name <code>week</code>).
403   */
404  public static final Unit<Time> WEEK = addUnit(DAY.multiply(7));
405
406  /**
407   * A time unit accepted for use with SI units (standard name <code>y</code> ).
408   */
409  public static final Unit<Time> YEAR = addUnit(Units.DAY.multiply(365.2525));
410
411  /**
412   * An angle unit accepted for use with SI units (standard name <code>deg</code>).
413   * 
414   * @deprecated Use from SI
415   */
416  public static final Unit<Angle> DEGREE_ANGLE = addUnit(new TransformedUnit<>(RADIAN, new PiMultiplierConverter().concatenate(new RationalConverter(
417      1, 180))));
418
419  /**
420   * An angle unit accepted for use with SI units (standard name <code>'</code>).
421   * 
422   * @deprecated Use from SI
423   */
424  public static final Unit<Angle> MINUTE_ANGLE = addUnit(new TransformedUnit<>(RADIAN, new PiMultiplierConverter().concatenate(new RationalConverter(
425      1, 180 * 60))));
426
427  /**
428   * An angle unit accepted for use with SI units (standard name <code>''</code>).
429   * 
430   * @deprecated Use from SI
431   */
432  public static final Unit<Angle> SECOND_ANGLE = addUnit(new TransformedUnit<>(RADIAN, new PiMultiplierConverter().concatenate(new RationalConverter(
433      1, 180 * 60 * 60))));
434
435  /**
436   * A volume unit accepted for use with SI units (standard name <code>l</code>).
437   * 
438   * @see <a href="https://en.wikipedia.org/wiki/Litre"> Wikipedia: Litre</a>
439   */
440  public static final Unit<Volume> LITRE = AbstractSystemOfUnits.Helper.addUnit(INSTANCE.units, new TransformedUnit<Volume>(CUBIC_METRE,
441      new RationalConverter(1, 1000)), "Litre", "l");
442
443  /**
444   * Returns the unique instance of this class.
445   * 
446   * @return the Units instance.
447   */
448  public static SystemOfUnits getInstance() {
449    return INSTANCE;
450  }
451
452  static {
453    // have to add AbstractUnit.ONE as Dimensionless, too
454    addUnit(AbstractUnit.ONE);
455    INSTANCE.quantityToUnit.put(Dimensionless.class, AbstractUnit.ONE);
456  }
457
458  /**
459   * Adds a new unit not mapped to any specified quantity type.
460   *
461   * @param unit
462   *          the unit being added.
463   * @return <code>unit</code>.
464   */
465  private static <U extends Unit<?>> U addUnit(U unit) {
466    INSTANCE.units.add(unit);
467    return unit;
468  }
469
470  /**
471   * Adds a new unit and maps it to the specified quantity type.
472   *
473   * @param unit
474   *          the unit being added.
475   * @param type
476   *          the quantity type.
477   * @return <code>unit</code>.
478   */
479  private static <U extends AbstractUnit<?>> U addUnit(U unit, Class<? extends Quantity<?>> type) {
480    INSTANCE.units.add(unit);
481    INSTANCE.quantityToUnit.put(type, unit);
482    return unit;
483  }
484}