001/* 002 * International System of Units (SI) 003 * Copyright (c) 2005-2018, Jean-Marie Dautelle, Werner Keil and others. 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, Units of Measurement nor the names of their contributors may be used to 017 * endorse or promote products 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 si.uom; 031 032import static tec.uom.se.unit.MetricPrefix.CENTI; 033import static tec.uom.se.unit.MetricPrefix.FEMTO; 034import static tec.uom.se.unit.MetricPrefix.MEGA; 035import static tec.uom.se.unit.Units.*; 036 037import javax.measure.Unit; 038import javax.measure.quantity.*; 039 040import si.uom.quantity.DynamicViscosity; 041import si.uom.quantity.IonizingRadiation; 042import si.uom.quantity.KinematicViscosity; 043import si.uom.quantity.Luminance; 044import si.uom.quantity.MagneticFieldStrength; 045import tec.uom.se.AbstractSystemOfUnits; 046import tec.uom.se.AbstractUnit; 047import tec.uom.se.format.SimpleUnitFormat; 048import tec.uom.se.function.MultiplyConverter; 049import tec.uom.se.function.PiMultiplierConverter; 050import tec.uom.se.function.RationalConverter; 051import tec.uom.se.unit.ProductUnit; 052import tec.uom.se.unit.TransformedUnit; 053import tec.uom.se.unit.Units; 054 055/** 056 * <p> 057 * This class contains units that are not part of the International System of 058 * Units, that is, they are outside the SI, but are important and widely used. 059 * </p> 060 * 061 * <p> 062 * This class is not intended to be implemented by clients. 063 * </p> 064 * 065 * @noimplement This class is not intended to be implemented by clients. 066 * @noextend This class is not intended to be extended by clients. 067 * 068 * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a> 069 * @author <a href="mailto:units@catmedia.us">Werner Keil</a> 070 * @version 1.1, $Date: 2018-05-20$ 071 */ 072public final class NonSI extends AbstractSystemOfUnits { 073 private static final String SYSTEM_NAME = "Non-SI Units"; 074 075 /** 076 * Holds the standard gravity constant: 9.80665 m/s² exact. 077 */ 078 private static final int STANDARD_GRAVITY_DIVIDEND = 980665; 079 080 private static final int STANDARD_GRAVITY_DIVISOR = 100000; 081 082 /** 083 * Holds the avoirdupois pound: 0.45359237 kg exact 084 */ 085 private static final int AVOIRDUPOIS_POUND_DIVIDEND = 45359237; 086 087 private static final int AVOIRDUPOIS_POUND_DIVISOR = 100000000; 088 089 /** 090 * Holds the Avogadro constant. 091 */ 092 private static final double AVOGADRO_CONSTANT = 6.02214199e23; // (1/mol). 093 094 /** 095 * Holds the electric charge of one electron. 096 */ 097 private static final double ELEMENTARY_CHARGE = 1.602176462e-19; // (C). 098 099 private static final NonSI INSTANCE = new NonSI(); 100 101 ///////////////////////////////////////////////////////////////// 102 // Units outside the SI that are accepted for use with the SI. // 103 ///////////////////////////////////////////////////////////////// 104 105 /** 106 * An angle unit accepted for use with SI units (standard name 107 * <code>deg</code>). 108 */ 109 public static final Unit<Angle> DEGREE_ANGLE = addUnit( 110 new TransformedUnit<Angle>(RADIAN, new PiMultiplierConverter().concatenate(new RationalConverter(1, 180))), 111 "Degree Angle", "deg"); 112 113 /** 114 * An angle unit accepted for use with SI units (standard name <code>'</code>). 115 */ 116 public static final Unit<Angle> MINUTE_ANGLE = addUnit(new TransformedUnit<Angle>(RADIAN, 117 new PiMultiplierConverter().concatenate(new RationalConverter(1, 180 * 60))), "Minute Angle", "'"); 118 119 /** 120 * An angle unit accepted for use with SI units (standard name <code>''</code>). 121 */ 122 public static final Unit<Angle> SECOND_ANGLE = addUnit( 123 new TransformedUnit<Angle>(RADIAN, 124 new PiMultiplierConverter().concatenate(new RationalConverter(1, 180 * 60 * 60))), 125 "Second Angle", "''"); 126 127 /** 128 * A mass unit accepted for use with SI units (standard name <code>t</code>). 129 */ 130 public static final Unit<Mass> TONNE = AbstractSystemOfUnits.Helper.addUnit(INSTANCE.units, 131 new TransformedUnit<Mass>(KILOGRAM, new RationalConverter(1000, 1)), "Tonne", "t"); 132 133 /** 134 * An energy unit accepted for use with SI units (standard name 135 * <code>eV</code>). The electronvolt is the kinetic energy acquired by an 136 * electron passing through a potential difference of 1 V in vacuum. The value 137 * must be obtained by experiment, and is therefore not known exactly. 138 */ 139 public static final Unit<Energy> ELECTRON_VOLT = addUnit( 140 new TransformedUnit<Energy>(JOULE, new MultiplyConverter(1.602176487E-19)), "Electron Volt", "eV"); 141 // CODATA 2006 - http://physics.nist.gov/cuu/Constants/codata.pdf 142 143 /** 144 * A mass unit accepted for use with SI units (standard name <code>u</code>). 145 * The unified atomic mass unit is equal to 1/12 of the mass of an unbound atom 146 * of the nuclide 12C, at rest and in its ground state. The value must be 147 * obtained by experiment, and is therefore not known exactly. 148 */ 149 public static final Unit<Mass> UNIFIED_ATOMIC_MASS = addUnit( 150 new TransformedUnit<Mass>(KILOGRAM, new MultiplyConverter(1.660538782E-27)), "Unified atomic mass", "u", 151 true); 152 // CODATA 2006 - http://physics.nist.gov/cuu/Constants/codata.pdf 153 154 /** 155 * A length unit accepted for use with SI units (standard name <code>UA</code>). 156 * The astronomical unit is a unit of length. Its value is such that, when used 157 * to describe the motion of bodies in the solar system, the heliocentric 158 * gravitation constant is (0.017 202 098 95)2 ua3·d-2. The value must be 159 * obtained by experiment, and is therefore not known exactly. 160 */ 161 public static final Unit<Length> ASTRONOMICAL_UNIT = addUnit( 162 new TransformedUnit<Length>(METRE, new MultiplyConverter(149597871000.0)), "Astronomical Unit", "UA"); 163 // Best estimate source: http://maia.usno.navy.mil/NSFA/CBE.html 164 165 /** 166 * An angle unit accepted for use with SI units (standard name <code>ha</code>). 167 */ 168 public static final Unit<Area> HECTARE = addUnit( 169 new TransformedUnit<Area>(SQUARE_METRE, new RationalConverter(10000, 1)), "Hectare", "ha"); 170 171 /////////////////// 172 // Dimensionless // 173 /////////////////// 174 /** 175 * A dimensionless unit equals to <code>pi</code> (standard name 176 * <code>Ï€</code>). 177 */ 178 public static final Unit<Dimensionless> PI = addUnit(AbstractUnit.ONE.multiply(StrictMath.PI)); 179 180 ///////////////////////// 181 // Amount of substance // 182 ///////////////////////// 183 /** 184 * A unit of amount of substance equals to one atom (standard name 185 * <code>atom</code>). 186 */ 187 public static final Unit<AmountOfSubstance> ATOM = addUnit(MOLE.divide(AVOGADRO_CONSTANT)); 188 189 //////////// 190 // Length // 191 //////////// 192 193 /** 194 * A unit of length equal to <code>1E-10 m</code> (standard name 195 * <code>Å</code>). 196 * 197 * @see <a href="https://en.wikipedia.org/wiki/%C3%85ngstr%C3%B6m"> Wikipedia: 198 * Ångström</a> 199 */ 200 public static final Unit<Length> ANGSTROM = addUnit(METRE.divide(10000000000L), "\u00C5ngstr\u00F6m", "\u00C5"); 201 202 /** 203 * A unit of length equal to the distance that light travels in one year through 204 * a vacuum (standard name <code>ly</code>). 205 */ 206 public static final Unit<Length> LIGHT_YEAR = addUnit(METRE.multiply(9.460528405e15), "Light year", "ly"); 207 208 /** 209 * A unit of length equal to the distance at which a star would appear to shift 210 * its position by one arcsecond over the course the time (about 3 months) in 211 * which the Earth moves a distance of {@link #ASTRONOMICAL_UNIT} in the 212 * direction perpendicular to the direction to the star (standard name 213 * <code>pc</code>). 214 */ 215 public static final Unit<Length> PARSEC = addUnit(METRE.multiply(30856770e9)); 216 217 /** 218 * A unit of length equal to <code>1852.0 m</code> (standard name 219 * <code>nmi</code>). 220 */ 221 public static final Unit<Length> NAUTICAL_MILE = addUnit(METRE.multiply(1852), "Nautical mile", "nmi"); 222 223 //////////// 224 // Area // 225 //////////// 226 227 /** 228 * A barn (symbol: <code>b</code>) is a unit of area equal to 10<sup>−28</sup> 229 * <code>m2</code> (100 <code>fm2</code>) 230 */ 231 public static final Unit<Area> BARN = addUnit(new ProductUnit<Area>(FEMTO(METRE).pow(2)).multiply(100)); 232 233 ////////////// 234 // Time // 235 ////////////// 236 237 /** 238 * A unit of duration equal to the time required for a complete rotation of the 239 * earth in reference to any star or to the vernal equinox at the meridian, 240 * equal to 23 hours, 56 minutes, 4.09 seconds (standard name 241 * <code>day_sidereal</code>). 242 */ 243 public static final Unit<Time> DAY_SIDEREAL = addUnit(SECOND.multiply(86164.09)); 244 245 /** 246 * A unit of duration equal to 365 {@link #DAY} (standard name 247 * <code>year</code>). 248 */ 249 public static final Unit<Time> YEAR_CALENDAR = addUnit(Units.DAY.multiply(365)); 250 251 /** 252 * A unit of duration equal to one complete revolution of the earth about the 253 * sun, relative to the fixed stars, or 365 days, 6 hours, 9 minutes, 9.54 254 * seconds (standard name <code>year_sidereal</code>). 255 */ 256 public static final Unit<Time> YEAR_SIDEREAL = addUnit(SECOND.multiply(31558149.54)); 257 258 /** 259 * The Julian year, as used in astronomy and other sciences, is a time unit 260 * defined as exactly 365.25 days. This is the normal meaning of the unit "year" 261 * (symbol "a" from the Latin annus, annata) used in various scientific 262 * contexts. 263 */ 264 public static final Unit<Time> YEAR_JULIEN = addUnit(SECOND.multiply(31557600)); 265 266 ////////// 267 // Mass // 268 ////////// 269 /** 270 * A unit of mass equal to 1/12 the mass of the carbon-12 atom (standard name 271 * <code>u</code>). 272 */ 273 protected static final Unit<Mass> ATOMIC_MASS = addUnit(KILOGRAM.multiply(1e-3 / AVOGADRO_CONSTANT)); 274 275 /** 276 * A unit of mass equal to the mass of the electron (standard name 277 * <code>me</code>). 278 */ 279 protected static final Unit<Mass> ELECTRON_MASS = addUnit(KILOGRAM.multiply(9.10938188e-31)); 280 281 /** 282 * A unit of mass equal to <code>453.59237 grams</code> (avoirdupois pound, 283 * standard name <code>lb</code>). 284 */ 285 protected static final Unit<Mass> POUND = addUnit( 286 KILOGRAM.multiply(AVOIRDUPOIS_POUND_DIVIDEND).divide(AVOIRDUPOIS_POUND_DIVISOR)); 287 288 ///////////////////// 289 // Electric charge // 290 ///////////////////// 291 /** 292 * A unit of electric charge equal to the charge on one electron (standard name 293 * <code>e</code>). 294 */ 295 protected static final Unit<ElectricCharge> E = addUnit(COULOMB.multiply(ELEMENTARY_CHARGE)); 296 297 /** 298 * A unit of electric charge equal to equal to the product of Avogadro's number 299 * (see {@link SI#MOLE}) and the charge (1 e) on a single electron (standard 300 * name <code>Fd</code>). 301 */ 302 protected static final Unit<ElectricCharge> FARADAY = addUnit( 303 COULOMB.multiply(ELEMENTARY_CHARGE * AVOGADRO_CONSTANT)); // e/mol 304 305 /** 306 * A unit of electric charge which exerts a force of one dyne on an equal charge 307 * at a distance of one centimeter (standard name <code>Fr</code>). 308 */ 309 protected static final Unit<ElectricCharge> FRANKLIN = addUnit(COULOMB.multiply(3.3356e-10)); 310 311 ///////////////// 312 // Temperature // 313 ///////////////// 314 /** 315 * A unit of temperature equal to <code>5/9 °K</code> (standard name 316 * <code>°R</code>). 317 */ 318 protected static final Unit<Temperature> RANKINE = addUnit(KELVIN.multiply(5).divide(9)); 319 320 /////////// 321 // Angle // 322 /////////// 323 324 /** 325 * A unit of angle equal to a full circle or <code>2<i>π</i> 326 * {@link SI#RADIAN}</code> (standard name <code>rev</code>). 327 */ 328 public static final Unit<Angle> REVOLUTION = addUnit(RADIAN.multiply(2).multiply(Math.PI).asType(Angle.class)); 329 /** 330 * An angle unit accepted for use with SI units (standard name 331 * <code>rev</code>). 332 */ 333 // public static final Unit<Angle> REVOLUTION = addUnit( 334 // new TransformedUnit<Angle>(RADIAN, new 335 // PiMultiplierConverter().concatenate(new RationalConverter(2, 1)))); 336 337 // //////////// 338 // Velocity // 339 // //////////// 340 /** 341 * A unit of velocity relative to the speed of light (standard name 342 * <code>c</code>). 343 */ 344 protected static final Unit<Speed> C = addUnit(METRE_PER_SECOND.multiply(299792458)); 345 346 /** 347 * A unit of velocity expressing the number of {@link #NAUTICAL_MILE nautical 348 * miles} per {@link #HOUR hour} (abbreviation <code>kn</code>). 349 */ 350 public static final Unit<Speed> KNOT = addUnit(NAUTICAL_MILE.divide(HOUR).asType(Speed.class), "Knot", "kn"); 351 352 // //////////////// 353 // Acceleration // 354 // //////////////// 355 /** 356 * A unit of acceleration equal to the gravity at the earth's surface (standard 357 * name <code>grav</code>). 358 */ 359 protected static final Unit<Acceleration> G = addUnit( 360 METRE_PER_SQUARE_SECOND.multiply(STANDARD_GRAVITY_DIVIDEND).divide(STANDARD_GRAVITY_DIVISOR)); 361 362 /** 363 * A unit of acceleration equal to <code>1 cm s<sup>2</sup></code> (standard 364 * name <code>Gal</code>). 365 */ 366 public static final Unit<Acceleration> GAL = addUnit( 367 new ProductUnit<Acceleration>(CENTI(METRE).divide(SECOND.pow(2)))); 368 369 ////////// 370 // Area // 371 ////////// 372 /** 373 * A unit of area equal to <code>100 m²</code> (standard name <code>a</code> ). 374 */ 375 protected static final Unit<Area> ARE = addUnit(SQUARE_METRE.multiply(100)); 376 377 ////////////////////// 378 // Electric current // 379 ////////////////////// 380 /** 381 * A unit of electric charge equal to the centimeter-gram-second electromagnetic 382 * unit of magnetomotive force, equal to <code>10/4 383 * πampere-turn</code> (standard name <code>Gi</code>). 384 */ 385 protected static final Unit<ElectricCurrent> GILBERT = addUnit( 386 AMPERE.multiply(10).divide(4).multiply(PI).asType(ElectricCurrent.class)); 387 388 //////////// 389 // Energy // 390 //////////// 391 /** 392 * A unit of energy equal to <code>1E-7 J</code> (standard name 393 * <code>erg</code>). 394 */ 395 public static final Unit<Energy> ERG = addUnit(JOULE.divide(10000000)); 396 397 ///////////////// 398 // Luminance // 399 ///////////////// 400 public static final Unit<Luminance> STILB = addUnit( 401 new ProductUnit<Luminance>(CANDELA.divide(CENTI(METRE).pow(2)))); 402 403 /** 404 * A unit of luminance equal to <code>1E4 Lx</code> (standard name 405 * <code>La</code>). 406 */ 407 protected static final Unit<Luminance> LAMBERT = addUnit(new ProductUnit<Luminance>(STILB.divide(PI))); 408 409 /** 410 * A unit of illuminance equal to <code>1E4 Lx</code> (standard name 411 * <code>ph</code>). 412 */ 413 public static final Unit<Illuminance> PHOT = addUnit(LUX.divide(1E4), "Phot", "ph"); 414 415 /////////////////// 416 // Magnetic Flux // 417 /////////////////// 418 /** 419 * A unit of magnetic flux equal <code>1E-8 Wb</code> (standard name 420 * <code>Mx</code>). 421 */ 422 public static final Unit<MagneticFlux> MAXWELL = addUnit(WEBER.divide(100000000)); 423 424 /////////////////////////// 425 // Magnetic Flux Density // 426 /////////////////////////// 427 /** 428 * A unit of magnetic flux density equal <code>1000 A/m</code> (standard name 429 * <code>G</code>). 430 */ 431 public static final Unit<MagneticFluxDensity> GAUSS = addUnit(TESLA.divide(10000)); 432 433 /** 434 * A unit of magnetic field strength equal <code>(10<sup>3</sup>/4pi) A m–1</code> (standard name 435 * <code>Oe</code>). 436 */ 437 public static final Unit<MagneticFieldStrength> OERSTED = addUnit( 438 new ProductUnit<MagneticFieldStrength>(SI.AMPERE_PER_METRE.multiply(250).divide(PI)), "Ørsted", "Oe", true); 439 440 /////////// 441 // Force // 442 /////////// 443 /** 444 * A unit of force equal to <code>1E-5 N</code> (standard name 445 * <code>dyn</code>). 446 */ 447 public static final Unit<Force> DYNE = addUnit(NEWTON.divide(100000), "Dyne", "dyn", true); 448 449 /** 450 * A unit of force equal to <code>9.80665 N</code> (standard name 451 * <code>kgf</code>). 452 */ 453 protected static final Unit<Force> KILOGRAM_FORCE = addUnit( 454 NEWTON.multiply(STANDARD_GRAVITY_DIVIDEND).divide(STANDARD_GRAVITY_DIVISOR)); 455 456 /** 457 * A unit of force equal to <code>{@link #POUND}·{@link #G}</code> (standard 458 * name <code>lbf</code>). 459 */ 460 protected static final Unit<Force> POUND_FORCE = addUnit( 461 NEWTON.multiply(1L * AVOIRDUPOIS_POUND_DIVIDEND * STANDARD_GRAVITY_DIVIDEND) 462 .divide(1L * AVOIRDUPOIS_POUND_DIVISOR * STANDARD_GRAVITY_DIVISOR)); 463 464 // ///////// 465 // Power // 466 // ///////// 467 /** 468 * A unit of power equal to the power required to raise a mass of 75 kilograms 469 * at a velocity of 1 meter per second (metric, standard name <code>hp</code>). 470 */ 471 protected static final Unit<Power> HORSEPOWER = addUnit(WATT.multiply(735.499)); 472 473 ////////////// 474 // Pressure // 475 ////////////// 476 477 /** 478 * A unit of pressure equal to <code>100 kPa</code> (standard name 479 * <code>bar</code>). 480 */ 481 public static final Unit<Pressure> BAR = addUnit(PASCAL.multiply(100000)); 482 483 /** 484 * A unit of pressure equal to the pressure exerted at the Earth's surface by a 485 * column of mercury 1 millimeter high (standard name <code>mmHg</code> ). 486 */ 487 public static final Unit<Pressure> MILLIMETRE_OF_MERCURY = addUnit(PASCAL.multiply(133.322)); 488 489 /** 490 * A unit of pressure equal to the pressure exerted at the Earth's surface by a 491 * column of mercury 1 inch high (standard name <code>inHg</code>). 492 */ 493 public static final Unit<Pressure> INCH_OF_MERCURY = addUnit(PASCAL.multiply(3386.388)); 494 495 // /////////////////////////// 496 // Radiation dose absorbed // 497 // /////////////////////////// 498 /** 499 * A unit of radiation dose absorbed equal to a dose of 0.01 joule of energy per 500 * kilogram of mass (J/kg) (standard name <code>rd</code>). 501 */ 502 public static final Unit<RadiationDoseAbsorbed> RAD = addUnit(GRAY.divide(100)); 503 504 /** 505 * A unit of radiation dose effective equal to <code>0.01 Sv</code> (standard 506 * name <code>rem</code>). 507 */ 508 public static final Unit<RadiationDoseEffective> REM = addUnit(SIEVERT.divide(100)); 509 510 // //////////////////////// 511 // Radioactive activity // 512 // //////////////////////// 513 /** 514 * A unit of radioctive activity equal to the activity of a gram of radium 515 * (standard name <code>Ci</code>). 516 */ 517 protected static final Unit<Radioactivity> CURIE = addUnit(BECQUEREL.multiply(37000000000L)); 518 519 /** 520 * A unit of radioctive activity equal to 1 million radioactive disintegrations 521 * per second (standard name <code>Rd</code>). 522 */ 523 protected static final Unit<Radioactivity> RUTHERFORD = addUnit(BECQUEREL.multiply(1000000)); 524 525 ///////////////// 526 // Solid angle // 527 ///////////////// 528 /** 529 * A unit of solid angle equal to <code>4 <i>π</i> steradians</code> 530 * (standard name <code>sphere</code>). 531 */ 532 protected static final Unit<SolidAngle> SPHERE = addUnit( 533 STERADIAN.multiply(4).multiply(PI).asType(SolidAngle.class)); 534 535 /////////////// 536 // Viscosity // 537 /////////////// 538 /** 539 * A unit of dynamic viscosity equal to <code>1 g/(cm·s)</code> (cgs unit). 540 */ 541 public static final Unit<DynamicViscosity> POISE = addUnit(GRAM.divide(CENTI(METRE).multiply(SECOND))) 542 .asType(DynamicViscosity.class); 543 544 /** 545 * A unit of kinematic viscosity equal to <code>1 cm²/s</code> (cgs unit). 546 */ 547 public static final Unit<KinematicViscosity> STOKES = addUnit(CENTI(METRE).pow(2).divide(SECOND)) 548 .asType(KinematicViscosity.class); 549 550 /////////////// 551 // Frequency // 552 /////////////// 553 /** 554 * A unit used to measure the frequency (rate) at which an imaging device 555 * produces unique consecutive images (standard name <code>fps</code>). 556 */ 557 protected static final Unit<Frequency> FRAMES_PER_SECOND = addUnit(AbstractUnit.ONE.divide(SECOND)) 558 .asType(Frequency.class); 559 560 //////////// 561 // Others // 562 //////////// 563 564 /** 565 * A unit used to measure the ionizing ability of radiation (standard name 566 * <code>R</code>). 567 * 568 * @see <a href="https://en.wikipedia.org/wiki/Roentgen_(unit)"> Wikipedia: 569 * Roentgen</a> 570 */ 571 @SuppressWarnings("unchecked") 572 public static final Unit<IonizingRadiation> ROENTGEN = (Unit<IonizingRadiation>) addUnit( 573 COULOMB.divide(KILOGRAM).multiply(2.58e-4), "Roentgen", "R", true); 574 575 ///////////////////// 576 // Collection View // 577 ///////////////////// 578 579 /** 580 * Default constructor (prevents this class from being instantiated). 581 */ 582 private NonSI() { // Singleton 583 } 584 585 /** 586 * Returns the unique instance of this class. 587 * 588 * @return the NonSI instance. 589 */ 590 public static NonSI getInstance() { 591 return INSTANCE; 592 } 593 594 public String getName() { 595 return SYSTEM_NAME; 596 } 597 598 /** 599 * Adds a new unit not mapped to any specified quantity type. 600 * 601 * @param unit 602 * the unit being added. 603 * @return <code>unit</code>. 604 */ 605 private static <U extends Unit<?>> U addUnit(U unit) { 606 INSTANCE.units.add(unit); 607 return unit; 608 } 609 610 /** 611 * Adds a new unit and maps it to the specified quantity type. 612 * 613 * @param unit 614 * the unit being added. 615 * @param type 616 * the quantity type. 617 * @return <code>unit</code>. 618 */ 619 // private static <U extends AbstractUnit<?>> U addUnit(U unit, Class<? extends 620 // Quantity<?>> type) { 621 // INSTANCE.units.add(unit); 622 // INSTANCE.quantityToUnit.put(type, unit); 623 // return unit; 624 // } 625 626 /** 627 * Adds a new unit not mapped to any specified quantity type and puts a text as 628 * symbol or label. 629 * 630 * @param unit 631 * the unit being added. 632 * @param name 633 * the string to use as name 634 * @param text 635 * the string to use as label or symbol 636 * @param isLabel 637 * if the string should be used as a label or not 638 * @return <code>unit</code>. 639 */ 640 private static <U extends Unit<?>> U addUnit(U unit, String name, String text, boolean isLabel) { 641 if (isLabel) { 642 SimpleUnitFormat.getInstance().label(unit, text); 643 } 644 if (name != null && unit instanceof AbstractUnit) { 645 return Helper.addUnit(INSTANCE.units, unit, name); 646 } else { 647 INSTANCE.units.add(unit); 648 } 649 return unit; 650 } 651 652 /** 653 * Adds a new unit not mapped to any specified quantity type and puts a text as 654 * symbol or label. 655 * 656 * @param unit 657 * the unit being added. 658 * @param name 659 * the string to use as name 660 * @param text 661 * the string to use as label 662 * @return <code>unit</code>. 663 */ 664 private static <U extends Unit<?>> U addUnit(U unit, String name, String text) { 665 return addUnit(unit, name, text, true); 666 } 667 668 // ////////////////////////////////////////////////////////////////////////// 669 // Label adjustments for Non-SI 670 static { 671 SimpleUnitFormat.getInstance().label(TONNE, "t"); 672 SimpleUnitFormat.getInstance().label(MEGA(TONNE), "Mt"); 673 } 674}