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