1 9 package javax.measure.units; 10 11 import java.util.Collections ; 12 import java.util.HashSet ; 13 import java.util.Set ; 14 15 import javax.measure.converters.LogConverter; 16 import javax.measure.converters.RationalConverter; 17 import javax.measure.quantities.*; 18 19 import static javax.measure.units.SI.*; 20 21 32 public final class NonSI { 33 34 37 private static HashSet <Unit<?>> INSTANCES = new HashSet <Unit<?>>(); 38 39 42 private static final int STANDARD_GRAVITY_DIVIDEND = 980665; 43 private static final int STANDARD_GRAVITY_DIVISOR = 100000; 44 45 48 private static final int INTERNATIONAL_FOOT_DIVIDEND = 3048; 49 private static final int INTERNATIONAL_FOOT_DIViSOR = 10000; 50 51 54 private static final int AVOIRDUPOIS_POUND_DIVIDEND = 45359237; 55 private static final int AVOIRDUPOIS_POUND_DIVISOR = 100000000; 56 57 60 private static final double AVOGADRO_CONSTANT = 6.02214199e23; 62 65 private static final double ELEMENTARY_CHARGE = 1.602176462e-19; 67 70 private NonSI() { 71 } 72 73 77 81 public static final Unit<Dimensionless> PERCENT = nonSI(Unit.ONE.divide(100)); 82 83 87 public static final Unit<Dimensionless> DECIBEL = nonSI(Unit.ONE 88 .transform(new LogConverter(10).inverse().concatenate( 89 new RationalConverter(1, 10)))); 90 91 95 99 public static final Unit<Acceleration> G = nonSI(METER_PER_SQUARE_SECOND 100 .times(STANDARD_GRAVITY_DIVIDEND).divide(STANDARD_GRAVITY_DIVISOR)); 101 102 106 110 public static final Unit<AmountOfSubstance> ATOM = nonSI(MOLE 111 .divide(AVOGADRO_CONSTANT)); 112 113 117 121 public static final Unit<Angle> REVOLUTION = nonSI(RADIAN.times(2.0 * Math.PI)); 122 123 127 public static final Unit<Angle> DEGREE_ANGLE = nonSI(REVOLUTION.divide(360)); 128 129 133 public static final Unit<Angle> MINUTE_ANGLE = nonSI(DEGREE_ANGLE.divide(60)); 134 135 139 public static final Unit<Angle> SECOND_ANGLE = nonSI(MINUTE_ANGLE.divide(60)); 140 141 145 public static final Unit<Angle> CENTIRADIAN = nonSI(RADIAN.divide(100)); 146 147 151 public static final Unit<Angle> GRADE = nonSI(REVOLUTION.divide(400)); 152 153 157 161 public static final Unit<Area> ARE = nonSI(SQUARE_METER.times(100)); 162 163 167 public static final Unit<Area> HECTARE = nonSI(ARE.times(100)); 169 173 177 public static final Unit<DataAmount> BYTE = nonSI(BIT.times(8)); 178 179 182 public static final Unit<DataAmount> OCTET = BYTE; 183 184 188 192 public static final Unit<Duration> MINUTE = nonSI(SI.SECOND.times(60)); 193 194 198 public static final Unit<Duration> HOUR = nonSI(MINUTE.times(60)); 199 200 204 public static final Unit<Duration> DAY = nonSI(HOUR.times(24)); 205 206 210 public static final Unit<Duration> WEEK = nonSI(DAY.times(7)); 211 212 216 public static final Unit<Duration> YEAR = nonSI(SECOND.times(31556952)); 217 218 222 public static final Unit<Duration> MONTH = nonSI(YEAR.divide(12)); 223 224 230 public static final Unit<Duration> DAY_SIDEREAL = nonSI(SECOND.times(86164.09)); 231 232 237 public static final Unit<Duration> YEAR_SIDEREAL = nonSI(SECOND 238 .times(31558149.54)); 239 240 244 public static final Unit<Duration> YEAR_CALENDAR = nonSI(DAY.times(365)); 245 246 250 254 public static final Unit<ElectricCharge> E = nonSI(COULOMB 255 .times(ELEMENTARY_CHARGE)); 256 257 262 public static final Unit<ElectricCharge> FARADAY = nonSI(COULOMB 263 .times(ELEMENTARY_CHARGE * AVOGADRO_CONSTANT)); 265 270 public static final Unit<ElectricCharge> FRANKLIN = nonSI(COULOMB 271 .times(3.3356e-10)); 272 273 277 282 public static final Unit<ElectricCurrent> GILBERT = nonSI(SI.AMPERE 283 .times(10.0 / (4.0 * Math.PI))); 284 285 289 293 public static final Unit<Energy> ERG = nonSI(JOULE.divide(10000000)); 294 295 299 public static final Unit<Energy> ELECTRON_VOLT = nonSI(JOULE 300 .times(ELEMENTARY_CHARGE)); 301 302 306 310 public static final Unit<Illuminance> LAMBERT = nonSI(LUX.times(10000)); 311 312 316 320 public static final Unit<Length> FOOT = nonSI(METER.times(INTERNATIONAL_FOOT_DIVIDEND).divide(INTERNATIONAL_FOOT_DIViSOR)); 321 322 327 public static final Unit<Length> FOOT_SURVEY_US = nonSI(METER 328 .times(1200).divide(3937)); 329 330 334 public static final Unit<Length> YARD = nonSI(FOOT.times(3)); 335 336 340 public static final Unit<Length> INCH = nonSI(FOOT.divide(12)); 341 342 346 public static final Unit<Length> MILE = nonSI(METER.times(1609344).divide(1000)); 347 348 352 public static final Unit<Length> NAUTICAL_MILE = nonSI(METER.times(1852)); 353 354 358 public static final Unit<Length> ANGSTROM = nonSI(METER.divide(10000000000L)); 359 360 364 public static final Unit<Length> ASTRONOMICAL_UNIT = nonSI(METER 365 .times(149597870691.0)); 366 367 371 public static final Unit<Length> LIGHT_YEAR = nonSI(METER.times(9.460528405e15)); 372 373 380 public static final Unit<Length> PARSEC = nonSI(METER.times(30856770e9)); 381 382 387 public static final Unit<Length> POINT = nonSI(INCH.times(13837).divide(1000000)); 388 389 395 public static final Unit<Length> PIXEL = nonSI(INCH.divide(72)); 396 397 400 public static final Unit<Length> COMPUTER_POINT = PIXEL; 401 402 406 410 public static final Unit<MagneticFlux> MAXWELL = nonSI(WEBER.divide(100000000)); 411 412 416 420 public static final Unit<MagneticFluxDensity> GAUSS = nonSI(TESLA.divide(10000)); 421 422 426 430 public static final Unit<Mass> ATOMIC_MASS = nonSI(KILOGRAM 431 .times(1e-3 / AVOGADRO_CONSTANT)); 432 433 437 public static final Unit<Mass> ELECTRON_MASS = nonSI(KILOGRAM 438 .times(9.10938188e-31)); 439 440 444 public static final Unit<Mass> POUND = nonSI(KILOGRAM.times(AVOIRDUPOIS_POUND_DIVIDEND).divide(AVOIRDUPOIS_POUND_DIVISOR)); 445 446 450 public static final Unit<Mass> OUNCE = nonSI(POUND.divide(16)); 451 452 456 public static final Unit<Mass> TON_US = nonSI(POUND.times(2000)); 457 458 462 public static final Unit<Mass> TON_UK = nonSI(POUND.times(2240)); 463 464 468 public static final Unit<Mass> METRIC_TON = nonSI(KILOGRAM.times(1000)); 469 470 474 478 public static final Unit<Force> DYNE = nonSI(NEWTON.divide(100000)); 479 480 484 public static final Unit<Force> KILOGRAM_FORCE = nonSI(NEWTON 485 .times(STANDARD_GRAVITY_DIVIDEND).divide(STANDARD_GRAVITY_DIVISOR)); 486 487 491 public static final Unit<Force> POUND_FORCE = nonSI(NEWTON 492 .times(1L * AVOIRDUPOIS_POUND_DIVIDEND * STANDARD_GRAVITY_DIVIDEND).divide( 493 1L * AVOIRDUPOIS_POUND_DIVISOR * STANDARD_GRAVITY_DIVISOR)); 494 495 499 504 public static final Unit<Power> HORSEPOWER = nonSI(WATT.times(735.499)); 505 506 510 514 public static final Unit<Pressure> ATMOSPHERE = nonSI(PASCAL.times(101325)); 515 516 520 public static final Unit<Pressure> BAR = nonSI(PASCAL.times(100000)); 521 522 527 public static final Unit<Pressure> MILLIMETER_OF_MERCURY =nonSI(PASCAL 528 .times(133.322)); 529 530 535 public static final Unit<Pressure> INCH_OF_MERCURY = nonSI(PASCAL.times(3386.388)); 536 537 541 545 public static final Unit<RadiationDoseAbsorbed> RAD = nonSI(GRAY.divide(100)); 546 547 551 public static final Unit<RadiationDoseEffective> REM = nonSI(SIEVERT.divide(100)); 552 553 557 561 public static final Unit<RadioactiveActivity> CURIE = nonSI(BECQUEREL 562 .times(37000000000L)); 563 564 568 public static final Unit<RadioactiveActivity> RUTHERFORD = nonSI(SI.BECQUEREL 569 .times(1000000)); 570 571 575 579 public static final Unit<SolidAngle> SPHERE = nonSI(STERADIAN 580 .times(4.0 * Math.PI)); 581 582 586 590 public static final Unit<Temperature> RANKINE = nonSI(KELVIN.times(5).divide(9)); 591 592 597 public static final Unit<Temperature> FAHRENHEIT = nonSI(RANKINE.plus(459.67)); 598 599 603 607 public static final Unit<Velocity> KNOT 608 = nonSI(NAUTICAL_MILE.divide(HOUR).sameTypeAs(METER_PER_SECOND)); 609 610 614 public static final Unit<Velocity> MACH = nonSI(METER_PER_SECOND.times(331.6)); 615 616 620 public static final Unit<Velocity> C = nonSI(METER_PER_SECOND.times(299792458)); 621 622 626 630 public static final Unit<Volume> LITER = nonSI(CUBIC_METER.divide(1000)); 631 632 635 public static final Unit<Volume> CUBIC_INCH = nonSI( 636 INCH.pow(3).sameTypeAs(SI.CUBIC_METER)); 637 638 643 public static final Unit<Volume> GALLON_LIQUID_US = nonSI(CUBIC_INCH.times(231)); 644 645 649 public static final Unit<Volume> OUNCE_LIQUID_US = nonSI(GALLON_LIQUID_US 650 .divide(128)); 651 652 656 public static final Unit<Volume> GALLON_DRY_US = nonSI(CUBIC_INCH.times(2688025).divide(10000)); 657 658 662 public static final Unit<Volume> GALLON_UK = nonSI(LITER.times(454609).divide(100000)); 663 664 668 public static final Unit<Volume> OUNCE_LIQUID_UK = nonSI(GALLON_UK.divide(160)); 669 670 674 678 @SuppressWarnings ("unchecked") 679 public static final Unit<DynamicViscosity> 680 POISE = nonSI((Unit<DynamicViscosity>) GRAM.divide(CENTI(METER).times(SECOND))); 681 682 686 @SuppressWarnings ("unchecked") 687 public static final Unit<KinematicViscosity> 688 STOKE = nonSI((Unit<KinematicViscosity>) CENTI(METER).pow(2).divide(SECOND)); 689 690 691 695 699 public static final Unit<?> ROENTGEN = nonSI(COULOMB.divide(KILOGRAM).times(2.58e-4)); 700 701 702 706 711 public static Set <Unit<?>> units() { 712 return Collections.unmodifiableSet(INSTANCES); 713 } 714 715 721 private static <U extends Unit> U nonSI(U unit) { 722 INSTANCES.add(unit); 723 return unit; 724 } 725 726 727 } | Popular Tags |