001/*
002 * Units of Measurement Reference Implementation
003 * Copyright (c) 2005-2021, Jean-Marie Dautelle, Werner Keil, Otavio Santana.
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-385, Indriya nor the names of their 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 tech.units.indriya.unit;
031
032import static tech.units.indriya.AbstractUnit.ONE;
033
034import javax.measure.Quantity;
035import javax.measure.Unit;
036import javax.measure.quantity.Acceleration;
037import javax.measure.quantity.AmountOfSubstance;
038import javax.measure.quantity.Angle;
039import javax.measure.quantity.Area;
040import javax.measure.quantity.CatalyticActivity;
041import javax.measure.quantity.Dimensionless;
042import javax.measure.quantity.ElectricCapacitance;
043import javax.measure.quantity.ElectricCharge;
044import javax.measure.quantity.ElectricConductance;
045import javax.measure.quantity.ElectricCurrent;
046import javax.measure.quantity.ElectricInductance;
047import javax.measure.quantity.ElectricPotential;
048import javax.measure.quantity.ElectricResistance;
049import javax.measure.quantity.Energy;
050import javax.measure.quantity.Force;
051import javax.measure.quantity.Frequency;
052import javax.measure.quantity.Illuminance;
053import javax.measure.quantity.Length;
054import javax.measure.quantity.LuminousFlux;
055import javax.measure.quantity.LuminousIntensity;
056import javax.measure.quantity.MagneticFlux;
057import javax.measure.quantity.MagneticFluxDensity;
058import javax.measure.quantity.Mass;
059import javax.measure.quantity.Power;
060import javax.measure.quantity.Pressure;
061import javax.measure.quantity.RadiationDoseAbsorbed;
062import javax.measure.quantity.RadiationDoseEffective;
063import javax.measure.quantity.Radioactivity;
064import javax.measure.quantity.SolidAngle;
065import javax.measure.quantity.Speed;
066import javax.measure.quantity.Temperature;
067import javax.measure.quantity.Time;
068import javax.measure.quantity.Volume;
069import tech.units.indriya.AbstractSystemOfUnits;
070import tech.units.indriya.AbstractUnit;
071import tech.units.indriya.function.AddConverter;
072import tech.units.indriya.function.MultiplyConverter;
073import tech.units.indriya.function.RationalNumber;
074
075/**
076 * <p>
077 * This class defines common units.
078 *
079 * @author <a href="mailto:werner@units.tech">Werner Keil</a>
080 * @author <a href="mailto:thodoris.bais@gmail.com">Thodoris Bais</a>
081 * @version 2.3.1, April 21, 2020
082 * @since 1.0
083 * @see <a href="https://usma.org/detailed-list-of-metric-system-units-symbols-and-prefixes">USMA: Detailed list of metric system units, symbols, and prefixes</a>
084 */
085public class Units extends AbstractSystemOfUnits {
086
087        /** Constructor may only be called by subclasses */
088        protected Units() {
089        }
090
091        /** Singleton instance */
092        private static final Units INSTANCE = new Units();
093
094        /*
095         * (non-Javadoc)
096         * 
097         * @see SystemOfUnits#getName()
098         */
099        @Override
100        public String getName() {
101                return Units.class.getSimpleName();
102        }
103
104        // //////////////
105        // BASE UNITS //
106        // //////////////
107
108        /**
109         * The ampere, symbol A, is the SI unit of electric current. It is defined by
110         * taking the fixed numerical value of the elementary charge e to be 1.602 176
111         * 634 × 10⁻¹⁹ when expressed in the unit C, which is equal to A s, where the
112         * second is defined in terms of ∆νCs.
113         *
114         * This definition implies the exact relation e = 1.602 176 634 × 10⁻¹⁹ A s.
115         * Inverting this relation gives an exact expression for the unit ampere in
116         * terms of the defining constants e and ∆νCs:
117         *
118         * 1 A = (e / 1.602 176 634 × 10⁻¹⁹) s⁻¹
119         *
120     * <dl>
121     * <dt><span class="strong">Implementation Note:</span></dt><dd>SI Base Unit</dd>
122     * </dl>
123         */
124        public static final Unit<ElectricCurrent> AMPERE = addUnit(
125                        new BaseUnit<ElectricCurrent>("A", "Ampere", UnitDimension.ELECTRIC_CURRENT), ElectricCurrent.class);
126
127        /**
128         * The candela, symbol cd, is the SI unit of luminous intensity in a given
129         * direction. It is defined by taking the fixed numerical value of the luminous
130         * efficacy of monochromatic radiation of frequency 540 × 10¹² Hz, Kcd, to be
131         * 683 when expressed in the unit lm W−1, which is equal to cd sr W⁻¹, or cd sr
132         * kg⁻¹ m⁻² s³, where the kilogram, metre and second are defined in terms of h,
133         * c and ∆νCs.
134         *
135         * This definition implies the exact relation Kcd = 683 cd sr kg⁻¹ m⁻² s³ for
136         * monochromatic radiation of frequency ν = 540 × 10¹² Hz. Inverting this
137         * relation gives an exact expression for the candela in terms of the defining
138         * constants Kcd, h and ∆νCs:
139         *
140         * 1 cd = (Kcd / 683) kg m² s⁻³ sr⁻¹
141         *
142     * <dl>
143     * <dt><span class="strong">Implementation Note:</span></dt><dd>SI Base Unit</dd>
144     * </dl>
145     * @see <a href="http://en.wikipedia.org/wiki/Candela"> Wikipedia: Candela</a>
146         */
147        public static final Unit<LuminousIntensity> CANDELA = addUnit(
148                        new BaseUnit<LuminousIntensity>("cd", "Candela", UnitDimension.LUMINOUS_INTENSITY),
149                        LuminousIntensity.class);
150
151        /**
152         * The kelvin, symbol K, is the SI unit of thermodynamic temperature. It is
153         * defined by taking the fixed numerical value of the Boltzmann constant k to be
154         * 1.380 649 × 10−²³ when expressed in the unit J K⁻¹, which is equal to kg m²
155         * s⁻² K⁻¹, where the kilogram, metre and second are defined in terms of h, c
156         * and ∆νCs.
157         *
158         * This definition implies the exact relation k = 1.380 649 × 10⁻²³ kg m² s⁻²
159         * K⁻¹. Inverting this relation gives an exact expression for the kelvin in
160         * terms of the defining constants k, h and ∆νCs:
161         *
162         * 1 K = (1.380 649 / k) × 10⁻²³ kg m² s⁻²
163         *
164         * <dl>
165     * <dt><span class="strong">Implementation Note:</span></dt><dd>SI Base Unit</dd>
166     * </dl>
167         * @see #JOULE
168         */
169        public static final Unit<Temperature> KELVIN = addUnit(
170                        new BaseUnit<Temperature>("K", "Kelvin", UnitDimension.TEMPERATURE), Temperature.class);
171
172        /**
173         * The kilogram, symbol kg, is the SI unit of mass. It is defined by taking the
174         * fixed numerical value of the Planck constant h to be 6.626 070 15 × 10⁻³⁴
175         * when expressed in the unit J s, which is equal to kg m² s−1, where the metre
176         * and the second are defined in terms of c and ∆νCs.
177         *
178         * This definition implies the exact relation h = 6.626 070 15 × 10−34 kg m²
179         * s⁻¹. Inverting this relation gives an exact expression for the kilogram in
180         * terms of the three defining constants h, ∆νCs and c:
181         *
182         * 1 kg = (h / 6.626 070 15 × 10⁻³⁴) m⁻² s
183         *
184         * <dl>
185     * <dt><span class="strong">Implementation Note:</span></dt><dd>SI Base Unit</dd>
186     * </dl>
187         * @see <a href="https://en.wikipedia.org/wiki/Kilogram">Wikipedia: Kilogram</a>
188         * @see #GRAM
189         * @see #METRE
190         * @see #SECOND
191         */
192        public static final Unit<Mass> KILOGRAM = addUnit(new BaseUnit<Mass>("kg", "Kilogram", UnitDimension.MASS), Mass.class);
193
194        /**
195         * The metre, symbol m, is the SI unit of length. It is defined by taking the
196         * fixed numerical value of the speed of light in vacuum c to be 299 792 458
197         * when expressed in the unit m s⁻¹, where the second is defined in terms of the
198         * caesium frequency ∆νCs.
199         *
200         * This definition implies the exact relation c = 299 792 458 m s⁻¹. Inverting
201         * this relation gives an exact expression for the metre in terms of the
202         * defining constants c and ∆νCs:
203         *
204         * 1 m = (c / 299 792 458)s = 9 192 631 770 c / 299 792 458 ∆νCs ≈ 30.663 319 c
205         * / ∆νCs
206         *
207     * <dl>
208     * <dt><span class="strong">Implementation Note:</span></dt><dd>SI Base Unit</dd>
209     * </dl>
210         */
211        public static final Unit<Length> METRE = addUnit(new BaseUnit<>("m", "Metre", UnitDimension.LENGTH), Length.class);
212
213        /**
214         * The mole, symbol mol, is the SI unit of amount of substance. One mole
215         * contains exactly 6.022 140 76 × 10²³ elementary entities. This number is the
216         * fixed numerical value of the Avogadro constant, NA, when expressed in the
217         * unit mol⁻¹ and is called the Avogadro number.
218         *
219         * The amount of substance, symbol n, of a system is a measure of the number of
220         * specified elementary entities. An elementary entity may be an atom, a
221         * molecule, an ion, an electron, any other particle or specified group of
222         * particles. This definition implies the exact relation Nₐ = 6.022 140 76 ×
223         * 10²³ mol⁻¹.
224         *
225         * Inverting this relation gives an exact expression for the mole in terms of
226         * the defining constant NA:
227         *
228         * 1 mol = 6.02214076 × 10²³ / Nₐ
229         *
230     * <dl>
231     * <dt><span class="strong">Implementation Note:</span></dt><dd>SI Base Unit</dd>
232     * </dl>
233         */
234        public static final Unit<AmountOfSubstance> MOLE = addUnit(new BaseUnit<>("mol", "Mole", UnitDimension.AMOUNT_OF_SUBSTANCE),
235                        AmountOfSubstance.class);
236
237        /**
238         * The second, symbol s, is the SI unit of time. It is defined by taking the
239         * fixed numerical value of the caesium frequency ∆νCs, the unperturbed
240         * ground-state hyperfine transition frequency of the caesium 133 atom, to be 9
241         * 192 631 770 when expressed in the unit Hz, which is equal to s⁻¹.
242         *
243         * This definition implies the exact relation ∆νCs = 9 192 631 770 Hz. Inverting
244         * this relation gives an expression for the unit second in terms of the
245         * defining constant ∆νCs:
246         *
247         * 1 Hz = ∆νCs / 9 192 631 770 or 1 s = 9 192 631 770 / ∆νCs
248         *
249     * <dl>
250     * <dt><span class="strong">Implementation Note:</span></dt><dd>SI Base Unit</dd>
251     * </dl>
252         */
253        public static final Unit<Time> SECOND = addUnit(new BaseUnit<>("s", "Second", UnitDimension.TIME), Time.class);
254
255        // //////////////////////////////
256        // SI DERIVED ALTERNATE UNITS //
257        // //////////////////////////////
258
259        /**
260         * The SI derived unit for mass quantities (standard name <code>g</code>). The
261         * base unit for mass quantity is {@link #KILOGRAM}.
262         */
263        public static final Unit<Mass> GRAM = addUnit(KILOGRAM.divide(1000));
264        // = new TransformedUnit(KILOGRAM, MetricPrefix.KILO.getConverter());
265
266        /**
267         * The SI unit for plane angle quantities (standard name <code>rad</code>). One
268         * radian is the angle between two radii of a circle such that the length of the
269         * arc between them is equal to the radius.
270         */
271        public static final Unit<Angle> RADIAN = addUnit(AlternateUnit.of(ONE, "rad", "Radian"), Angle.class);
272
273        /**
274         * The SI unit for solid angle quantities (standard name <code>sr</code>). One
275         * steradian is the solid angle subtended at the center of a sphere by an area
276         * on the surface of the sphere that is equal to the radius squared. The total
277         * solid angle of a sphere is 4*Pi steradians.
278         */
279        public static final Unit<SolidAngle> STERADIAN = addUnit(new AlternateUnit<>(ONE, "sr", "Steradian"), SolidAngle.class);
280
281        /**
282         * The SI unit for frequency (standard name <code>Hz</code>). A unit of
283         * frequency equal to one cycle per second. After Heinrich Rudolf Hertz
284         * (1857-1894), German physicist who was the first to produce radio waves
285         * artificially.
286         */
287        public static final Unit<Frequency> HERTZ = addUnit(new AlternateUnit<Frequency>(ONE.divide(SECOND), "Hz", "Hertz"),
288                        Frequency.class);
289
290        /**
291         * The SI unit for force (standard name <code>N</code>). One newton is the force
292         * required to give a mass of 1 kilogram an Force of 1 metre per second per
293         * second. It is named after the English mathematician and physicist Sir Isaac
294         * Newton (1642-1727).
295         */
296        public static final Unit<Force> NEWTON = addUnit(
297                        new AlternateUnit<Force>(METRE.multiply(KILOGRAM).divide(SECOND.pow(2)), "N", "Newton"), Force.class);
298
299        /**
300         * The SI unit for pressure, stress (standard name <code>Pa</code>). One pascal
301         * is equal to one newton per square meter. It is named after the French
302         * philosopher and mathematician Blaise Pascal (1623-1662).
303         */
304        @SuppressWarnings({ "unchecked", "rawtypes" })
305        public static final Unit<Pressure> PASCAL = addUnit(new AlternateUnit(NEWTON.divide(METRE.pow(2)), "Pa", "Pascal"),
306                        Pressure.class);
307
308        /**
309         * The SI unit for energy, work, quantity of heat (<code>J</code>). One joule is
310         * the amount of work done when an applied force of 1 newton moves through a
311         * distance of 1 metre in the direction of the force. It is named after the
312         * English physicist James Prescott Joule (1818-1889).
313         */
314        public static final Unit<Energy> JOULE = addUnit(new AlternateUnit<Energy>(NEWTON.multiply(METRE), "J", "Joule"),
315                        Energy.class);
316
317        /**
318         * The SI unit for power, radiant, flux (standard name <code>W</code>). One watt
319         * is equal to one joule per second. It is named after the British scientist
320         * James Watt (1736-1819).
321         */
322        public static final Unit<Power> WATT = addUnit(new AlternateUnit<Power>(JOULE.divide(SECOND), "W", "Watt"), Power.class);
323
324        /**
325         * The SI unit for electric charge, quantity of electricity (standard name
326         * <code>C</code>). One Coulomb is equal to the quantity of charge transferred
327         * in one second by a steady current of one ampere. It is named after the French
328         * physicist Charles Augustin de Coulomb (1736-1806).
329         */
330        public static final Unit<ElectricCharge> COULOMB = addUnit(
331                        new AlternateUnit<ElectricCharge>(SECOND.multiply(AMPERE), "C", "Coulomb"), ElectricCharge.class);
332
333        /**
334         * The SI unit for electric potential difference, electromotive force (standard
335         * name <code>V</code>). One Volt is equal to the difference of electric
336         * potential between two points on a conducting wire carrying a constant current
337         * of one ampere when the power dissipated between the points is one watt. It is
338         * named after the Italian physicist Count Alessandro Volta (1745-1827).
339         */
340        public static final Unit<ElectricPotential> VOLT = addUnit(
341                        new AlternateUnit<ElectricPotential>(WATT.divide(AMPERE), "V", "Volt"), ElectricPotential.class);
342
343        /**
344         * The SI unit for capacitance (standard name <code>F</code>). One Farad is
345         * equal to the capacitance of a capacitor having an equal and opposite charge
346         * of 1 coulomb on each plate and a potential difference of 1 volt between the
347         * plates. It is named after the British physicist and chemist Michael Faraday
348         * (1791-1867).
349         */
350        public static final Unit<ElectricCapacitance> FARAD = addUnit(
351                        new AlternateUnit<ElectricCapacitance>(COULOMB.divide(VOLT), "F", "Farad"), ElectricCapacitance.class);
352
353        /**
354         * The SI unit for electric resistance (standard name <code>Ohm</code>). One Ohm
355         * is equal to the resistance of a conductor in which a current of one ampere is
356         * produced by a potential of one volt across its terminals. It is named after
357         * the German physicist Georg Simon Ohm (1789-1854).
358         */
359        public static final Unit<ElectricResistance> OHM = addUnit(
360                        new AlternateUnit<ElectricResistance>(VOLT.divide(AMPERE), "Ω", "Ohm"), ElectricResistance.class);
361
362        /**
363         * The SI unit for electric conductance (standard name <code>S</code>). One
364         * Siemens is equal to one ampere per volt. It is named after the German
365         * engineer Ernst Werner von Siemens (1816-1892).
366         */
367        public static final Unit<ElectricConductance> SIEMENS = addUnit(
368                        new AlternateUnit<ElectricConductance>(AMPERE.divide(VOLT), "S", "Siemens"), ElectricConductance.class);
369
370        /**
371         * The SI unit for magnetic flux (standard name <code>Wb</code>). One Weber is
372         * equal to the magnetic flux that in linking a circuit of one turn produces in
373         * it an electromotive force of one volt as it is uniformly reduced to zero
374         * within one second. It is named after the German physicist Wilhelm Eduard
375         * Weber (1804-1891).
376         */
377        public static final Unit<MagneticFlux> WEBER = addUnit(new AlternateUnit<MagneticFlux>(VOLT.multiply(SECOND), "Wb", "Weber"),
378                        MagneticFlux.class);
379
380        /**
381         * The alternate unit for magnetic flux density (standard name <code>T</code>).
382         * One Tesla is equal equal to one weber per square metre. It is named after the
383         * Serbian-born American electrical engineer and physicist Nikola Tesla
384         * (1856-1943).
385         */
386        public static final Unit<MagneticFluxDensity> TESLA = addUnit(
387                        new AlternateUnit<MagneticFluxDensity>(WEBER.divide(METRE.pow(2)), "T", "Tesla"), MagneticFluxDensity.class);
388
389        /**
390         * The alternate unit for inductance (standard name <code>H</code>). One Henry
391         * is equal to the inductance for which an induced electromotive force of one
392         * volt is produced when the current is varied at the rate of one ampere per
393         * second. It is named after the American physicist Joseph Henry (1791-1878).
394         */
395        public static final Unit<ElectricInductance> HENRY = addUnit(
396                        new AlternateUnit<ElectricInductance>(WEBER.divide(AMPERE), "H", "Henry"), ElectricInductance.class);
397
398        /**
399         * The SI unit for Celsius temperature (standard name <code>°C</code>). This is
400         * a unit of temperature such as the freezing point of water (at one atmosphere
401         * of pressure) is 0 °C, while the boiling point is 100 °C.
402         */
403        @SuppressWarnings({ "rawtypes", "unchecked" })
404        public static final Unit<Temperature> CELSIUS = AbstractSystemOfUnits.Helper.addUnit(INSTANCE.units, 
405                        new TransformedUnit(KELVIN, new AddConverter(273.15)), "Celsius", "\u2103");
406        // Not mapping to Temperature since temperature is mapped to Kelvin.
407
408        /**
409         * The SI unit for luminous flux (standard name <code>lm</code>). One Lumen is
410         * equal to the amount of light given out through a solid angle by a source of
411         * one candela intensity radiating equally in all directions.
412         */
413        public static final Unit<LuminousFlux> LUMEN = addUnit(
414                        new AlternateUnit<LuminousFlux>(CANDELA.multiply(STERADIAN), "lm", "Lumen"), LuminousFlux.class);
415
416        /**
417         * The SI unit for illuminance (standard name <code>lx</code>). One Lux is equal
418         * to one lumen per square metre.
419         */
420        public static final Unit<Illuminance> LUX = addUnit(
421                        new AlternateUnit<Illuminance>(LUMEN.divide(METRE.pow(2)), "lx", "Lux"), Illuminance.class);
422
423        /**
424         * The SI unit for activity of a radionuclide (standard name <code>Bq</code> ).
425         * One becquerel is the radiation caused by one disintegration per second. It is
426         * named after the French physicist, Antoine-Henri Becquerel (1852-1908).
427         */
428        public static final Unit<Radioactivity> BECQUEREL = addUnit(
429                        new AlternateUnit<Radioactivity>(ONE.divide(SECOND), "Bq", "Becquerel"), Radioactivity.class);
430
431        /**
432         * The SI unit for absorbed dose, specific energy (imparted), kerma (standard
433         * name <code>Gy</code>). One gray is equal to the dose of one joule of energy
434         * absorbed per one kilogram of matter. It is named after the British physician
435         * L. H. Gray (1905-1965).
436         */
437        public static final Unit<RadiationDoseAbsorbed> GRAY = addUnit(
438                        new AlternateUnit<RadiationDoseAbsorbed>(JOULE.divide(KILOGRAM), "Gy", "Gray"), RadiationDoseAbsorbed.class);
439
440        /**
441         * The SI unit for dose equivalent (standard name <code>Sv</code>). One Sievert
442         * is equal is equal to the actual dose, in grays, multiplied by a "quality
443         * factor" which is larger for more dangerous forms of radiation. It is named
444         * after the Swedish physicist Rolf Sievert (1898-1966).
445         */
446        public static final Unit<RadiationDoseEffective> SIEVERT = addUnit(
447                        new AlternateUnit<RadiationDoseEffective>(JOULE.divide(KILOGRAM), "Sv", "Sievert"), RadiationDoseEffective.class);
448
449        /**
450         * The SI unit for catalytic activity (standard name <code>kat</code>).
451         */
452        public static final Unit<CatalyticActivity> KATAL = addUnit(
453                        new AlternateUnit<CatalyticActivity>(MOLE.divide(SECOND), "kat", "Katal"), CatalyticActivity.class);
454
455        //////////////////////////////
456        // SI DERIVED PRODUCT UNITS //
457        //////////////////////////////
458
459        /**
460         * The SI unit for velocity quantities (standard name <code>m/s</code>).
461         */
462        public static final Unit<Speed> METRE_PER_SECOND = addUnit(new ProductUnit<>(METRE.divide(SECOND)), Speed.class);
463
464        /**
465         * The SI unit for acceleration quantities (standard name <code>m/s2</code> ).
466         */
467        public static final Unit<Acceleration> METRE_PER_SQUARE_SECOND = addUnit(
468                        new ProductUnit<>(METRE_PER_SECOND.divide(SECOND)), Acceleration.class);
469
470        /**
471         * The SI unit for area quantities (standard name <code>m2</code>).
472         */
473        public static final Unit<Area> SQUARE_METRE = addUnit(new ProductUnit<>(METRE.multiply(METRE)), Area.class);
474
475        /**
476         * The SI unit for volume quantities (standard name <code>m3</code>).
477         */
478        public static final Unit<Volume> CUBIC_METRE = addUnit(new ProductUnit<Volume>(SQUARE_METRE.multiply(METRE)),
479                        Volume.class);
480
481        /**
482         * A unit of velocity expressing the number of international {@link #KILOMETRE
483         * kilometres} per {@link #HOUR hour} (abbreviation <code>km/h</code>).
484         * 
485         * @see <a href="https://en.wikipedia.org/wiki/Kilometres_per_hour"> Wikipedia: Kilometres per hour</a>
486         */
487        public static final Unit<Speed> KILOMETRE_PER_HOUR = addUnit(METRE_PER_SECOND.multiply(RationalNumber.of(5, 18)))
488                        .asType(Speed.class);
489
490        /////////////////////////////////////////////////////////////////
491        // Common Units outside the SI that are accepted for use with the SI. //
492        /////////////////////////////////////////////////////////////////
493
494        /**
495         * A dimensionless unit accepted for use with SI units (standard name
496         * <code>%</code>).
497         */
498        public static final Unit<Dimensionless> PERCENT = addUnit(
499                        new TransformedUnit<>("%", "Percent", ONE, MultiplyConverter.ofRational(1, 100)));
500
501        //////////
502        // Time //
503        //////////
504        /**
505         * A time unit accepted for use with SI units (standard name <code>min</code>).
506         */
507        public static final Unit<Time> MINUTE = addUnit(
508                        new TransformedUnit<>("min", "Minute", SECOND, SECOND, MultiplyConverter.ofRational(60, 1)));
509
510        /**
511         * A time unit accepted for use with SI units (standard name <code>h</code> ).
512         */
513        public static final Unit<Time> HOUR = addUnit(
514                        new TransformedUnit<>("h", "Hour", SECOND, SECOND, MultiplyConverter.ofRational(60 * 60, 1)));
515
516        /**
517         * A time unit accepted for use with SI units (standard name <code>d</code> ).
518         */
519        public static final Unit<Time> DAY = addUnit(
520                        new TransformedUnit<>("d", "Day", SECOND, SECOND, MultiplyConverter.ofRational(24 * 60 * 60, 1)));
521
522        /**
523         * A unit of duration equal to 7 {@link #DAY} (standard name <code>wk</code>).
524         */
525        public static final Unit<Time> WEEK = AbstractSystemOfUnits.Helper.addUnit(INSTANCE.units, 
526                        DAY.multiply(7), "Week", "wk");
527
528        /**
529         * A time unit accepted for use with SI units (standard name <code>y</code> ).
530         */
531        public static final Unit<Time> YEAR = AbstractSystemOfUnits.Helper.addUnit(INSTANCE.units,
532                        Units.DAY.multiply(365.2425), "Year", "y");
533
534        /**
535         * A unit of duration equal to 1/12 {@link #YEAR} (standard name <code>mo</code>).
536         * @since 2.3
537         */
538        public static final Unit<Time> MONTH = AbstractSystemOfUnits.Helper.addUnit(INSTANCE.units, 
539                        YEAR.divide(12), "Month", "mo");
540        
541        /**
542         * A volume unit accepted for use with SI units (standard name <code>l</code>).
543         *
544         * @see <a href="https://en.wikipedia.org/wiki/Litre"> Wikipedia: Litre</a>
545         */
546        public static final Unit<Volume> LITRE = AbstractSystemOfUnits.Helper.addUnit(INSTANCE.units,
547                        new TransformedUnit<Volume>(CUBIC_METRE, MultiplyConverter.ofRational(1, 1000)), "Litre", "l");
548
549        /**
550         * Returns the unique instance of this class.
551         *
552         * @return the Units instance.
553         */
554        public static Units getInstance() {
555                return INSTANCE;
556        }
557
558        static {
559                // have to add AbstractUnit.ONE as Dimensionless, too
560                addUnit(ONE);
561                INSTANCE.quantityToUnit.put(Dimensionless.class, ONE);
562        }
563
564        /**
565         * Adds a new unit not mapped to any specified quantity type.
566         *
567         * @param unit the unit being added.
568         * @return <code>unit</code>.
569         */
570        private static <U extends Unit<?>> U addUnit(U unit) {
571                INSTANCE.units.add(unit);
572                return unit;
573        }
574
575        /**
576         * Adds a new unit and maps it to the specified quantity type.
577         *
578         * @param unit the unit being added.
579         * @param type the quantity type.
580         * @return <code>unit</code>.
581         */
582        private static <U extends AbstractUnit<?>> U addUnit(U unit, Class<? extends Quantity<?>> type) {
583                INSTANCE.units.add(unit);
584                INSTANCE.quantityToUnit.put(type, unit);
585                return unit;
586        }
587}