001/* 002 * Unit Systems 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 systems.uom.unicode; 031 032import static tec.uom.se.unit.MetricPrefix.*; 033import static tec.uom.se.unit.Units.CUBIC_METRE; 034import static tec.uom.se.unit.Units.METRE; 035import static tec.uom.se.unit.Units.SQUARE_METRE; 036import static tec.uom.se.AbstractUnit.ONE; 037import systems.uom.quantity.Information; 038import systems.uom.quantity.InformationRate; 039import systems.uom.quantity.Resolution; 040import tec.uom.se.*; 041import tec.uom.se.format.SimpleUnitFormat; 042import tec.uom.se.function.PiMultiplierConverter; 043import tec.uom.se.function.RationalConverter; 044import tec.uom.se.unit.AlternateUnit; 045import tec.uom.se.unit.ProductUnit; 046import tec.uom.se.unit.TransformedUnit; 047import tec.uom.se.unit.Units; 048 049import javax.measure.Quantity; 050import javax.measure.Unit; 051import javax.measure.quantity.*; 052 053/** 054 * <p> 055 * This class contains SI and Non-SI units as defined in the 056 * <a href="http//cldr.unicode.org/">Unicode CLDR Project</a>. 057 * </p> 058 * 059 * <p> 060 * Compatibility with {@link SI} units has been given priority over strict 061 * adherence to the standard. We have attempted to note every place where the 062 * definitions in this class deviate from the CLDR standard, but such notes are 063 * likely to be incomplete. 064 * </p> 065 * 066 * @noextend This class is not intended to be extended by clients. 067 * 068 * @author <a href="mailto:units@catmedia.us">Werner Keil</a> 069 * @see <a href="http://cldr.unicode.org">Unicode CLDR</a> 070 * @version 0.5.3, $Date: 2017-03-05 $ 071 */ 072public final class CLDR extends AbstractSystemOfUnits { 073 074 /** 075 * The singleton instance. 076 */ 077 private static final CLDR INSTANCE = new CLDR(); 078 079 /** 080 * Default constructor (prevents this class from being instantiated). 081 */ 082 private CLDR() { 083 } 084 085 /** 086 * Returns the singleton instance of this class. 087 * 088 * @return the CLDR system instance. 089 */ 090 public static CLDR getInstance() { 091 return INSTANCE; 092 } 093 094 //////////// 095 // Length // 096 //////////// 097 /** 098 * US name for {@link Units#METRE}. 099 */ 100 public static final Unit<Length> METER = METRE; 101 102 /** 103 * A unit of length equal to <code>0.3048 m</code> (standard name 104 * <code>ft</code>). 105 */ 106 public static final Unit<Length> FOOT = addUnit(METER.multiply(3048).divide(10000)); 107 108 /** 109 * A unit of length equal to <code>1200/3937 m</code> (standard name 110 * <code>foot_survey_us</code>). See also: 111 * <a href="http://www.sizes.com/units/foot.htm">foot</a> 112 */ 113 public static final Unit<Length> FOOT_SURVEY = addUnit(METER.multiply(1200).divide(3937)); 114 115 /** 116 * A unit of length equal to <code>0.9144 m</code> (standard name 117 * <code>yd</code>). 118 */ 119 public static final Unit<Length> YARD = addUnit(FOOT.multiply(3)); 120 121 /** 122 * A unit of length equal to <code>0.0254 m</code> (standard name 123 * <code>in</code>). 124 */ 125 public static final Unit<Length> INCH = addUnit(FOOT.divide(12)); 126 127 /** 128 * A unit of length equal to <code>1609.344 m</code> (standard name 129 * <code>mi</code>). 130 */ 131 public static final Unit<Length> MILE = addUnit(METER.multiply(1609344).divide(1000)); 132 133 /** 134 * A unit of length equal to the average distance from the center of the 135 * Earth to the center of the Sun (standard name <code>ua</code>). 136 */ 137 public static final Unit<Length> ASTRONOMICAL_UNIT = addUnit(METRE.multiply(149597870691.0)); 138 139 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 140 public static final Unit<Time> SECOND = addUnit(Units.SECOND); 141 142 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 143 public static final Unit<Angle> RADIAN = addUnit(Units.RADIAN); 144 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 145 public static final Unit<Temperature> KELVIN = addUnit(Units.KELVIN); 146 147 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 148 public static final Unit<LuminousIntensity> CANDELA = addUnit(Units.CANDELA); 149 150 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 151 public static final Unit<Dimensionless> PI = addUnit(ONE.transform(new PiMultiplierConverter())); 152 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 153 public static final Unit<Dimensionless> PERCENT = addUnit(ONE.divide(100), "Percent", "%"); 154 155 //////////////////// 156 // SI UNITS: CLDR // 157 //////////////////// 158 /** 159 * We deviate slightly from the standard here, to maintain compatibility 160 * with the existing SI units. In CLDR, the mole is no longer a base unit, 161 * but is defined as <code>Unit.ONE.multiply(6.0221367E23)</code>. 162 */ 163 public static final Unit<AmountOfSubstance> MOLE = addUnit(Units.MOLE); 164 /** 165 * We deviate slightly from the standard here, to maintain compatibility 166 * with the existing SI units. In CLDR, the steradian is defined as 167 * <code>RADIAN.pow(2)</code>. 168 */ 169 public static final Unit<SolidAngle> STERADIAN = addUnit(Units.STERADIAN); 170 171 public static final Unit<Frequency> HERTZ = addUnit(Units.HERTZ); 172 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 173 public static final Unit<Force> NEWTON = addUnit(Units.NEWTON); 174 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 175 public static final Unit<Pressure> PASCAL = addUnit(Units.PASCAL); 176 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 177 public static final Unit<Energy> JOULE = addUnit(Units.JOULE); 178 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 179 public static final Unit<Power> WATT = addUnit(Units.WATT); 180 /** 181 * We deviate slightly from the standard here, to maintain compatability 182 * with the existing SI units. In CLDR, the ampere is defined as 183 * <code>COULOMB.divide(SECOND)</code>. 184 */ 185 public static final Unit<ElectricCurrent> AMPERE = addUnit(Units.AMPERE); 186 187 /** 188 * We deviate slightly from the standard here, to maintain compatibility 189 * with the existing SI units. In CLDR, the volt is defined as 190 * <code>JOULE.divide(COULOMB)</code>. 191 */ 192 public static final Unit<ElectricPotential> VOLT = addUnit(Units.VOLT); 193 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 194 public static final Unit<ElectricCapacitance> FARAD = addUnit(Units.FARAD); 195 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 196 public static final Unit<ElectricResistance> OHM = addUnit(Units.OHM); 197 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 198 public static final Unit<ElectricConductance> SIEMENS = addUnit(Units.SIEMENS); 199 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 200 public static final Unit<MagneticFlux> WEBER = addUnit(Units.WEBER); 201 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 202 public static final Unit<Temperature> CELSIUS = addUnit(Units.CELSIUS); 203 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 204 public static final Unit<MagneticFluxDensity> TESLA = addUnit(Units.TESLA); 205 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 206 public static final Unit<ElectricInductance> HENRY = addUnit(Units.HENRY); 207 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 208 public static final Unit<LuminousFlux> LUMEN = addUnit(Units.LUMEN); 209 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 210 public static final Unit<Illuminance> LUX = addUnit(Units.LUX); 211 212 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 213 public static final Unit<RadiationDoseAbsorbed> GRAY = addUnit(Units.GRAY); 214 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 215 public static final Unit<RadiationDoseEffective> SIEVERT = addUnit(Units.SIEVERT); 216 217 ///////////////////////////////////////////////////////////////// 218 // Units outside the SI that are accepted for use with the SI. // 219 ///////////////////////////////////////////////////////////////// 220 221 /** 222 * An angle unit accepted for use with SI units (standard name 223 * <code>deg/code>). 224 */ 225 static final Unit<Angle> DEGREE_ANGLE = new TransformedUnit<Angle>(RADIAN, 226 new PiMultiplierConverter().concatenate(new RationalConverter(1, 180))); 227 228 /** 229 * An angle unit accepted for use with SI units (standard name 230 * <code>'/code>). 231 */ 232 static final Unit<Angle> MINUTE_ANGLE = new TransformedUnit<Angle>(RADIAN, 233 new PiMultiplierConverter().concatenate(new RationalConverter(1, 180 * 60))); 234 235 /** 236 * An angle unit accepted for use with SI units (standard name 237 * <code>''</code>). 238 */ 239 static final Unit<Angle> SECOND_ANGLE = new TransformedUnit<Angle>(RADIAN, 240 new PiMultiplierConverter().concatenate(new RationalConverter(1, 180 * 60 * 60))); 241 242 /** 243 * We deviate slightly from the standard here, to maintain compatibility 244 * with the existing NonSI units. In CLDR, the degree is defined as 245 * <code>PI.multiply(RADIAN.divide(180))</code>. 246 */ 247 public static final Unit<Angle> DEGREE = addUnit(DEGREE_ANGLE); 248 249 public static final Unit<Angle> ARC_MINUTE = addUnit(MINUTE_ANGLE); 250 251 public static final Unit<Angle> ARC_SECOND = addUnit(SECOND_ANGLE); 252 253 ////////// 254 // Area // 255 ////////// 256 /** 257 * A unit of area (standard name <code>sft</code> ). 258 */ 259 public static final Unit<Area> SQUARE_FOOT = addUnit(new ProductUnit<Area>((AbstractUnit<?>) FOOT.multiply(FOOT)), 260 "Square Foot", "sft"); 261 262 /** 263 * A unit of area equal to <code>100 m²</code> (standard name <code>a</code> 264 * ). 265 */ 266 private static final Unit<Area> ARE = addUnit(SQUARE_METRE.multiply(100)); 267 268 /** 269 * A unit of area equal to <code>100 {@link #ARE}</code> (standard name 270 * <code>ha</code>). 271 */ 272 public static final Unit<Area> HECTARE = addUnit(ARE.multiply(100), "Hectare", "ha"); 273 274 /** 275 * The acre is a unit of area used in the imperial and U.S. customary 276 * systems. It is equivalent to <code>43,560 square feet</code>. An acre is 277 * about 40% of a <code>HECTARE</code> – slightly smaller than an American 278 * football field. (standard name <code>ac</code> ). 279 * 280 * @see <a href="http://en.wikipedia.org/wiki/Acre">Wikipedia: Acre</a> 281 */ 282 public static final Unit<Area> ACRE = addUnit(SQUARE_FOOT.multiply(43560)); 283 284 //////////// 285 // Volume // 286 //////////// 287 /** 288 * A unit of volume equal to one cubic decimeter (default label 289 * <code>L</code>, also recognized <code>µL, mL, cL, dL</code>). 290 */ 291 public static final Unit<Volume> LITER = new TransformedUnit<Volume>(CUBIC_METRE, new RationalConverter(1, 1000)); 292 // private static final Unit<Volume> LITRE = addUnit(Units.LITRE); 293 294 /** 295 * A unit of volume equal to one cubic inch (<code>in³</code>). 296 */ 297 public static final Unit<Volume> CUBIC_INCH = addUnit(INCH.pow(3).asType(Volume.class)); 298 299 /** 300 * The cubic foot is an imperial and US customary (non-metric) unit of 301 * volume, used in the United States, Canada, and the United Kingdom. It is 302 * defined as the volume of a cube with sides of one foot (0.3048 m) in 303 * length. Its volume is 28.3168 liters or about 1⁄35 of a cubic meter. ( 304 * <code>ft³</code>). 305 */ 306 public static final Unit<Volume> CUBIC_FOOT = addUnit(CUBIC_INCH.multiply(1728).asType(Volume.class)); 307 308 /** 309 * An acre-foot is a unit of volume commonly used in the United States in 310 * reference to large-scale water resources, such as reservoirs, aqueducts, 311 * canals, sewer flow capacity, irrigation water, and river flows. 312 */ 313 public static final Unit<Volume> ACRE_FOOT = addUnit(CUBIC_FOOT.multiply(43560)); 314 315 /** 316 * Constant for unit of volume: bushel 317 */ 318 public static final Unit<Volume> BUSHEL = addUnit(CUBIC_INCH.multiply(215042).divide(100)); 319 320 ////////// 321 // Time // 322 ////////// 323 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 324 public static final Unit<Time> MINUTE = addUnit(Units.MINUTE); 325 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 326 public static final Unit<Time> HOUR = addUnit(Units.HOUR); 327 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 328 public static final Unit<Time> DAY = addUnit(Units.DAY); 329 330 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 331 static final Unit<Time> YEAR_JULIAN = addUnit(Units.DAY.multiply(365.25)); 332 333 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 334 public static final Unit<Time> YEAR = addUnit(Units.DAY.multiply(365.25)); 335 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 336 337 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 338 public static final Unit<Time> MONTH = addUnit(YEAR_JULIAN.divide(12)); 339 340 /** Constant for unit of time: century */ 341 public static final Unit<Time> CENTURY = addUnit(YEAR.multiply(100)); 342 343 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 344 private static final Unit<Pressure> BAR = addUnit(Units.PASCAL.multiply(100000)); 345 public static final Unit<Mass> GRAM = addUnit(Units.GRAM); 346 347 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 348 public static final Unit<Mass> TONNE = addUnit(Units.KILOGRAM.multiply(1000)); 349 350 /////////////////// 351 // NATURAL UNITS // 352 /////////////////// 353 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 354 static final Unit<Speed> C = addUnit(Units.METRE_PER_SECOND.multiply(299792458)); 355 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 356 // public static final Unit<Action> PLANCK = addUnit(SI.JOULE_SECOND 357 // .multiply(6.6260755E-24)); // FIXME get rid of JXQ import (where 358 // from??) */ 359 360 private static final Unit<Acceleration> ACCELLERATION_OF_FREEFALL = addUnit( 361 Units.METRE_PER_SQUARE_SECOND.multiply(9.80665)); 362 363 //////////// 364 // Length // 365 //////////// 366 /** 367 * A unit of length equal to the distance that light travels in one year 368 * through a vacuum (standard name <code>ly</code>). 369 */ 370 public static final Unit<Length> LIGHT_YEAR = addUnit(new ProductUnit<Length>(C.multiply(YEAR_JULIAN))); 371 /** 372 * A unit of length equal to the distance that light travels in one year 373 * through a vacuum (standard name <code>ly</code>). 374 */ 375 // static final Unit<Length> LIGHT_YEAR = addUnit(METRE 376 // .multiply(9.460528405e15)); 377 378 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 379 static final Unit<Length> INCH_INTERNATIONAL = addUnit(CENTI(METRE).multiply(254).divide(100)); 380 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 381 static final Unit<Length> FOOT_INTERNATIONAL = addUnit(INCH_INTERNATIONAL.multiply(12)); 382 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 383 public static final Unit<Length> NAUTICAL_MILE = addUnit(METRE.multiply(1852)); 384 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 385 public static final Unit<Speed> KNOT = addUnit(new ProductUnit<Speed>(NAUTICAL_MILE.divide(HOUR))); 386 387 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 388 private static final Unit<Mass> GRAIN = addUnit(MILLI(GRAM).multiply(6479891).divide(100000)); 389 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 390 static final Unit<Mass> POUND = addUnit(GRAIN.multiply(7000)); 391 392 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 393 public static final Unit<Mass> CARAT = addUnit(GRAM.divide(5)); 394 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 395 private static final Unit<Dimensionless> CARAT_GOLD = addUnit(ONE.divide(24)); 396 397 private static final Unit<Force> POUND_FORCE = addUnit( 398 POUND.multiply(ACCELLERATION_OF_FREEFALL).asType(Force.class)); 399 400 /** 401 * A unit of length equal to the distance at which a star would appear to 402 * shift its position by one arcsecond over the course the time (about 3 403 * months) in which the Earth moves a distance of {@link #ASTRONOMICAL_UNIT} 404 * in the direction perpendicular to the direction to the star (standard 405 * name <code>pc</code>). 406 * 407 * @stable ICU 54. 408 */ 409 public static final Unit<Length> PARSEC = addUnit(METRE.multiply(30856770e9)); 410 411 /** 412 * A unit of length equal to <code>1/72 {@link #INCH}</code> (standard name 413 * <code>pixel</code>). It is the American point rounded to an even 1/72 414 * inch. 415 * 416 * @see #POINT 417 * @deprecated Does not seem to be in CLDR 418 */ 419 static final Unit<Length> PIXEL = addUnit(INCH.divide(72)); 420 421 /** 422 * Equivalent {@link #PIXEL} 423 * 424 * @deprecated Does not seem to be in CLDR 425 */ 426 static final Unit<Length> COMPUTER_POINT = PIXEL; 427 428 /** 429 * Pixel per inch describe the resolution for any output device (monitor, 430 * printer) that deals with outputting digital raster images. 431 * 432 * @see #INCH 433 * @see #PIXEL 434 */ 435 static final Unit<Resolution> PIXEL_PER_INCH = addUnit(PIXEL.divide(INCH).asType(Resolution.class)); 436 437 /////////////////////////////// 438 // TYPESETTER'S LENGTH UNITS // 439 /////////////////////////////// 440 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 441 static final Unit<Length> LINE = addUnit(INCH_INTERNATIONAL.divide(12)); 442 /** 443 * A unit of length equal to <code>0.013837 {@link #INCH}</code> exactly 444 * (standard name <code>pt</code>). 445 * 446 * @see #PIXEL 447 */ 448 static final Unit<Length> POINT = LINE.divide(6); 449 // static final Unit<Length> POINT = addUnit(INCH.multiply(13837) 450 // .divide(1000000)); 451 452 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 453 static final Unit<Length> PICA = POINT.multiply(12); 454 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 455 static final Unit<Length> POINT_PRINTER = INCH_INTERNATIONAL.multiply(13837).divide(1000000); 456 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 457 static final Unit<Length> PICA_PRINTER = POINT_PRINTER.multiply(12); 458 459 ////////////////////////////// 460 // OTHER LEGACY UNITS: CLDR // 461 ////////////////////////////// 462 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 463 public static final Unit<Temperature> FAHRENHEIT = addUnit(KELVIN.multiply(5).divide(9).shift(459.67)); 464 465 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 466 private static final Unit<Energy> CALORIE_THERMOCHEMICAL = addUnit(JOULE.multiply(4184).divide(1000)); 467 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 468 public static final Unit<Energy> CALORIE = addUnit(CALORIE_THERMOCHEMICAL); 469 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 470// private static final Unit<Energy> CALORIE_FOOD = addUnit(KILO(CALORIE_THERMOCHEMICAL)); 471 472 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 473 public static final Unit<Power> HORSEPOWER = addUnit( 474 new ProductUnit<Power>(FOOT_INTERNATIONAL.multiply(POUND_FORCE).divide(SECOND))); 475 476 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 477 public static final Unit<Pressure> POUND_PER_SQUARE_INCH = addUnit( 478 new ProductUnit<Pressure>(POUND_FORCE.divide(INCH_INTERNATIONAL.pow(2)))); 479 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 480 public static final Unit<Angle> CIRCLE = addUnit(new ProductUnit<Angle>(PI.multiply(RADIAN.multiply(2)))); 481 482 /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */ 483 public static final Unit<SolidAngle> SPHERE = addUnit( 484 new ProductUnit<SolidAngle>(PI.multiply(STERADIAN.multiply(4)))); 485 486 /** 487 * The unit for binary information (standard name <code>bit</code>). 488 */ 489 public static final Unit<Information> BIT = addUnit(new AlternateUnit<Information>(ONE, "bit"), "Bit", "bit", 490 Information.class); 491 492 /** 493 * A unit of data amount equal to <code>8 {@link #BIT}</code> (BinarY 494 * TErm, standard name <code>byte</code>). 495 */ 496 public static final Unit<Information> BYTE = addUnit(BIT.multiply(8), "Byte", "byte"); 497 498 /** 499 * The unit for binary information rate (standard name <code>bit/s</code>). 500 */ 501 static final ProductUnit<InformationRate> BITS_PER_SECOND = addUnit( 502 new ProductUnit<InformationRate>(BIT.divide(SECOND)), InformationRate.class); 503 504 /** 505 * Equivalent {@link #BYTE} 506 */ 507 static final Unit<Information> OCTET = BYTE; 508 509 // /////////////////// 510 // Collection View // 511 // /////////////////// 512 513 @Override 514 public String getName() { 515 return "Unicode CLDR"; 516 } 517 518 /** 519 * Adds a new unit not mapped to any specified quantity type. 520 * 521 * @param unit 522 * the unit being added. 523 * @return <code>unit</code>. 524 */ 525 private static <U extends Unit<?>> U addUnit(U unit) { 526 INSTANCE.units.add(unit); 527 return unit; 528 } 529 530 /** 531 * Adds a new unit and maps it to the specified quantity type. 532 * 533 * @param unit 534 * the unit being added. 535 * @param type 536 * the quantity type. 537 * @return <code>unit</code>. 538 */ 539 private static <U extends AbstractUnit<?>> U addUnit(U unit, Class<? extends Quantity<?>> type) { 540 INSTANCE.units.add(unit); 541 INSTANCE.quantityToUnit.put(type, unit); 542 return unit; 543 } 544 545 /** 546 * Adds a new unit not mapped to any specified quantity type and puts a text 547 * as symbol or label. 548 * 549 * @param unit 550 * the unit being added. 551 * @param name 552 * the string to use as name 553 * @param text 554 * the string to use as label or symbol 555 * @param isLabel 556 * if the string should be used as a label or not 557 * @return <code>unit</code>. 558 */ 559 private static <U extends Unit<?>> U addUnit(U unit, String name, String text, boolean isLabel) { 560 if (isLabel) { 561 SimpleUnitFormat.getInstance().label(unit, text); 562 } 563 if (name != null && unit instanceof AbstractUnit) { 564 return Helper.addUnit(INSTANCE.units, unit, name); 565 } else { 566 INSTANCE.units.add(unit); 567 } 568 return unit; 569 } 570 571 /** 572 * Adds a new unit not mapped to any specified quantity type and puts a text 573 * as symbol or label. 574 * 575 * @param unit 576 * the unit being added. 577 * @param name 578 * the string to use as name 579 * @param text 580 * the string to use as label or symbol 581 * @param isLabel 582 * if the string should be used as a label or not 583 * @return <code>unit</code>. 584 */ 585 private static <U extends Unit<?>> U addUnit(U unit, String name, String text) { 586 return addUnit(unit, name, text, true); 587 } 588 589 /** 590 * Adds a new unit and maps it to the specified quantity type. 591 * 592 * @param unit 593 * the unit being added. 594 * @param type 595 * the quantity type. 596 * @return <code>unit</code>. 597 */ 598 private static <U extends AbstractUnit<?>> U addUnit(U unit, String name, String text, 599 Class<? extends Quantity<?>> type) { 600 INSTANCE.quantityToUnit.put(type, unit); 601 return addUnit(unit, name, text); 602 } 603 604 // ////////////////////////////////////////////////////////////////////////// 605 // Label adjustments for CLDR system 606 static { 607 SimpleUnitFormat.getInstance().alias(BYTE, "B"); 608 SimpleUnitFormat.getInstance().label(CARAT_GOLD, "kt"); 609 SimpleUnitFormat.getInstance().label(CARAT, "ct"); 610 SimpleUnitFormat.getInstance().label(POUND, "lb"); 611 SimpleUnitFormat.getInstance().label(BAR, "b"); 612 SimpleUnitFormat.getInstance().label(PARSEC, "pc"); 613 SimpleUnitFormat.getInstance().label(SQUARE_FOOT, "sft"); 614 } 615}