1/* GENERATED SOURCE. DO NOT MODIFY. */ 2// © 2016 and later: Unicode, Inc. and others. 3// License & terms of use: http://www.unicode.org/copyright.html#License 4/* 5 ******************************************************************************* 6 * Copyright (C) 2004-2016, Google Inc, International Business Machines 7 * Corporation and others. All Rights Reserved. 8 ******************************************************************************* 9 */ 10package android.icu.util; 11 12import java.io.Externalizable; 13import java.io.IOException; 14import java.io.ObjectInput; 15import java.io.ObjectOutput; 16import java.io.ObjectStreamException; 17import java.io.Serializable; 18import java.util.Collections; 19import java.util.HashMap; 20import java.util.HashSet; 21import java.util.Map; 22import java.util.Set; 23 24import android.icu.impl.ICUData; 25import android.icu.impl.ICUResourceBundle; 26import android.icu.impl.Pair; 27import android.icu.impl.UResource; 28import android.icu.text.UnicodeSet; 29 30/** 31 * A unit such as length, mass, volume, currency, etc. A unit is 32 * coupled with a numeric amount to produce a Measure. MeasureUnit objects are immutable. 33 * All subclasses must guarantee that. (However, subclassing is discouraged.) 34 35 * 36 * @see android.icu.util.Measure 37 * @author Alan Liu 38 */ 39public class MeasureUnit implements Serializable { 40 private static final long serialVersionUID = -1839973855554750484L; 41 42 // Cache of MeasureUnits. 43 // All access to the cache or cacheIsPopulated flag must be synchronized on class MeasureUnit, 44 // i.e. from synchronized static methods. Beware of non-static methods. 45 private static final Map<String, Map<String,MeasureUnit>> cache 46 = new HashMap<String, Map<String,MeasureUnit>>(); 47 private static boolean cacheIsPopulated = false; 48 49 /** 50 * @deprecated This API is ICU internal only. 51 * @hide original deprecated declaration 52 * @hide draft / provisional / internal are hidden on Android 53 */ 54 @Deprecated 55 protected final String type; 56 57 /** 58 * @deprecated This API is ICU internal only. 59 * @hide original deprecated declaration 60 * @hide draft / provisional / internal are hidden on Android 61 */ 62 @Deprecated 63 protected final String subType; 64 65 /** 66 * @deprecated This API is ICU internal only. 67 * @hide original deprecated declaration 68 * @hide draft / provisional / internal are hidden on Android 69 */ 70 @Deprecated 71 protected MeasureUnit(String type, String subType) { 72 this.type = type; 73 this.subType = subType; 74 } 75 76 /** 77 * Get the type, such as "length" 78 */ 79 public String getType() { 80 return type; 81 } 82 83 84 /** 85 * Get the subType, such as “foot”. 86 */ 87 public String getSubtype() { 88 return subType; 89 } 90 91 92 93 /** 94 * {@inheritDoc} 95 */ 96 @Override 97 public int hashCode() { 98 return 31 * type.hashCode() + subType.hashCode(); 99 } 100 101 /** 102 * {@inheritDoc} 103 */ 104 @Override 105 public boolean equals(Object rhs) { 106 if (rhs == this) { 107 return true; 108 } 109 if (!(rhs instanceof MeasureUnit)) { 110 return false; 111 } 112 MeasureUnit c = (MeasureUnit) rhs; 113 return type.equals(c.type) && subType.equals(c.subType); 114 } 115 116 /** 117 * {@inheritDoc} 118 */ 119 @Override 120 public String toString() { 121 return type + "-" + subType; 122 } 123 124 /** 125 * Get all of the available units' types. Returned set is unmodifiable. 126 */ 127 public synchronized static Set<String> getAvailableTypes() { 128 populateCache(); 129 return Collections.unmodifiableSet(cache.keySet()); 130 } 131 132 /** 133 * For the given type, return the available units. 134 * @param type the type 135 * @return the available units for type. Returned set is unmodifiable. 136 */ 137 public synchronized static Set<MeasureUnit> getAvailable(String type) { 138 populateCache(); 139 Map<String, MeasureUnit> units = cache.get(type); 140 // Train users not to modify returned set from the start giving us more 141 // flexibility for implementation. 142 return units == null ? Collections.<MeasureUnit>emptySet() 143 : Collections.unmodifiableSet(new HashSet<MeasureUnit>(units.values())); 144 } 145 146 /** 147 * Get all of the available units. Returned set is unmodifiable. 148 */ 149 public synchronized static Set<MeasureUnit> getAvailable() { 150 Set<MeasureUnit> result = new HashSet<MeasureUnit>(); 151 for (String type : new HashSet<String>(MeasureUnit.getAvailableTypes())) { 152 for (MeasureUnit unit : MeasureUnit.getAvailable(type)) { 153 result.add(unit); 154 } 155 } 156 // Train users not to modify returned set from the start giving us more 157 // flexibility for implementation. 158 return Collections.unmodifiableSet(result); 159 } 160 161 /** 162 * Create a MeasureUnit instance (creates a singleton instance). 163 * <p> 164 * Normally this method should not be used, since there will be no formatting data 165 * available for it, and it may not be returned by getAvailable(). 166 * However, for special purposes (such as CLDR tooling), it is available. 167 * 168 * @deprecated This API is ICU internal only. 169 * @hide original deprecated declaration 170 * @hide draft / provisional / internal are hidden on Android 171 */ 172 @Deprecated 173 public static MeasureUnit internalGetInstance(String type, String subType) { 174 if (type == null || subType == null) { 175 throw new NullPointerException("Type and subType must be non-null"); 176 } 177 if (!"currency".equals(type)) { 178 if (!ASCII.containsAll(type) || !ASCII_HYPHEN_DIGITS.containsAll(subType)) { 179 throw new IllegalArgumentException("The type or subType are invalid."); 180 } 181 } 182 Factory factory; 183 if ("currency".equals(type)) { 184 factory = CURRENCY_FACTORY; 185 } else if ("duration".equals(type)) { 186 factory = TIMEUNIT_FACTORY; 187 } else if ("none".equals(type)) { 188 factory = NOUNIT_FACTORY; 189 } else { 190 factory = UNIT_FACTORY; 191 } 192 return MeasureUnit.addUnit(type, subType, factory); 193 } 194 195 /** 196 * For ICU use only. 197 * @deprecated This API is ICU internal only. 198 * @hide original deprecated declaration 199 * @hide draft / provisional / internal are hidden on Android 200 */ 201 @Deprecated 202 public static MeasureUnit resolveUnitPerUnit(MeasureUnit unit, MeasureUnit perUnit) { 203 return unitPerUnitToSingleUnit.get(Pair.of(unit, perUnit)); 204 } 205 206 static final UnicodeSet ASCII = new UnicodeSet('a', 'z').freeze(); 207 static final UnicodeSet ASCII_HYPHEN_DIGITS = new UnicodeSet('-', '-', '0', '9', 'a', 'z').freeze(); 208 209 /** 210 * @deprecated This API is ICU internal only. 211 * @hide original deprecated declaration 212 * @hide draft / provisional / internal are hidden on Android 213 */ 214 @Deprecated 215 protected interface Factory { 216 /** 217 * @deprecated This API is ICU internal only. 218 * @hide original deprecated declaration 219 * @hide draft / provisional / internal are hidden on Android 220 */ 221 @Deprecated 222 MeasureUnit create(String type, String subType); 223 } 224 225 private static Factory UNIT_FACTORY = new Factory() { 226 @Override 227 public MeasureUnit create(String type, String subType) { 228 return new MeasureUnit(type, subType); 229 } 230 }; 231 232 static Factory CURRENCY_FACTORY = new Factory() { 233 @Override 234 public MeasureUnit create(String unusedType, String subType) { 235 return new Currency(subType); 236 } 237 }; 238 239 static Factory TIMEUNIT_FACTORY = new Factory() { 240 @Override 241 public MeasureUnit create(String type, String subType) { 242 return new TimeUnit(type, subType); 243 } 244 }; 245 246 static Factory NOUNIT_FACTORY = new Factory() { 247 @Override 248 public MeasureUnit create(String type, String subType) { 249 return new NoUnit(subType); 250 } 251 }; 252 253 /** 254 * Sink for enumerating the available measure units. 255 */ 256 private static final class MeasureUnitSink extends UResource.Sink { 257 @Override 258 public void put(UResource.Key key, UResource.Value value, boolean noFallback) { 259 UResource.Table unitTypesTable = value.getTable(); 260 for (int i2 = 0; unitTypesTable.getKeyAndValue(i2, key, value); ++i2) { 261 // Skip "compound" and "coordinate" since they are treated differently from the other units 262 if (key.contentEquals("compound") || key.contentEquals("coordinate")) { 263 continue; 264 } 265 266 String unitType = key.toString(); 267 UResource.Table unitNamesTable = value.getTable(); 268 for (int i3 = 0; unitNamesTable.getKeyAndValue(i3, key, value); ++i3) { 269 String unitName = key.toString(); 270 internalGetInstance(unitType, unitName); 271 } 272 } 273 } 274 } 275 276 /** 277 * Sink for enumerating the currency numeric codes. 278 */ 279 private static final class CurrencyNumericCodeSink extends UResource.Sink { 280 @Override 281 public void put(UResource.Key key, UResource.Value value, boolean noFallback) { 282 UResource.Table codesTable = value.getTable(); 283 for (int i1 = 0; codesTable.getKeyAndValue(i1, key, value); ++i1) { 284 internalGetInstance("currency", key.toString()); 285 } 286 } 287 } 288 289 /** 290 * Populate the MeasureUnit cache with all types from the data. 291 * Population is done lazily, in response to MeasureUnit.getAvailable() 292 * or other API that expects to see all of the MeasureUnits. 293 * 294 * <p>At static initialization time the MeasureUnits cache is populated 295 * with public static instances (G_FORCE, METER_PER_SECOND_SQUARED, etc.) only. 296 * Adding of others is deferred until later to avoid circular static init 297 * dependencies with classes Currency and TimeUnit. 298 * 299 * <p>Synchronization: this function must be called from static synchronized methods only. 300 * 301 * @hide draft / provisional / internal are hidden on Android 302 */ 303 static private void populateCache() { 304 if (cacheIsPopulated) { 305 return; 306 } 307 cacheIsPopulated = true; 308 309 /* Schema: 310 * 311 * units{ 312 * duration{ 313 * day{ 314 * one{"{0} ден"} 315 * other{"{0} дена"} 316 * } 317 */ 318 319 // Load the unit types. Use English, since we know that that is a superset. 320 ICUResourceBundle rb1 = (ICUResourceBundle) UResourceBundle.getBundleInstance( 321 ICUData.ICU_UNIT_BASE_NAME, 322 "en"); 323 rb1.getAllItemsWithFallback("units", new MeasureUnitSink()); 324 325 // Load the currencies 326 ICUResourceBundle rb2 = (ICUResourceBundle) UResourceBundle.getBundleInstance( 327 ICUData.ICU_BASE_NAME, 328 "currencyNumericCodes", 329 ICUResourceBundle.ICU_DATA_CLASS_LOADER); 330 rb2.getAllItemsWithFallback("codeMap", new CurrencyNumericCodeSink()); 331 } 332 333 /** 334 * @deprecated This API is ICU internal only. 335 * @hide original deprecated declaration 336 * @hide draft / provisional / internal are hidden on Android 337 */ 338 @Deprecated 339 protected synchronized static MeasureUnit addUnit(String type, String unitName, Factory factory) { 340 Map<String, MeasureUnit> tmp = cache.get(type); 341 if (tmp == null) { 342 cache.put(type, tmp = new HashMap<String, MeasureUnit>()); 343 } else { 344 // "intern" the type by setting to first item's type. 345 type = tmp.entrySet().iterator().next().getValue().type; 346 } 347 MeasureUnit unit = tmp.get(unitName); 348 if (unit == null) { 349 tmp.put(unitName, unit = factory.create(type, unitName)); 350 } 351 return unit; 352 } 353 354 355 /* 356 * Useful constants. Not necessarily complete: see {@link #getAvailable()}. 357 */ 358 359// All code between the "Start generated MeasureUnit constants" comment and 360// the "End generated MeasureUnit constants" comment is auto generated code 361// and must not be edited manually. For instructions on how to correctly 362// update this code, refer to: 363// http://site.icu-project.org/design/formatting/measureformat/updating-measure-unit 364// 365 // Start generated MeasureUnit constants 366 367 /** 368 * Constant for unit of acceleration: g-force 369 */ 370 public static final MeasureUnit G_FORCE = MeasureUnit.internalGetInstance("acceleration", "g-force"); 371 372 /** 373 * Constant for unit of acceleration: meter-per-second-squared 374 */ 375 public static final MeasureUnit METER_PER_SECOND_SQUARED = MeasureUnit.internalGetInstance("acceleration", "meter-per-second-squared"); 376 377 /** 378 * Constant for unit of angle: arc-minute 379 */ 380 public static final MeasureUnit ARC_MINUTE = MeasureUnit.internalGetInstance("angle", "arc-minute"); 381 382 /** 383 * Constant for unit of angle: arc-second 384 */ 385 public static final MeasureUnit ARC_SECOND = MeasureUnit.internalGetInstance("angle", "arc-second"); 386 387 /** 388 * Constant for unit of angle: degree 389 */ 390 public static final MeasureUnit DEGREE = MeasureUnit.internalGetInstance("angle", "degree"); 391 392 /** 393 * Constant for unit of angle: radian 394 */ 395 public static final MeasureUnit RADIAN = MeasureUnit.internalGetInstance("angle", "radian"); 396 397 /** 398 * Constant for unit of angle: revolution 399 */ 400 public static final MeasureUnit REVOLUTION_ANGLE = MeasureUnit.internalGetInstance("angle", "revolution"); 401 402 /** 403 * Constant for unit of area: acre 404 */ 405 public static final MeasureUnit ACRE = MeasureUnit.internalGetInstance("area", "acre"); 406 407 /** 408 * Constant for unit of area: hectare 409 */ 410 public static final MeasureUnit HECTARE = MeasureUnit.internalGetInstance("area", "hectare"); 411 412 /** 413 * Constant for unit of area: square-centimeter 414 */ 415 public static final MeasureUnit SQUARE_CENTIMETER = MeasureUnit.internalGetInstance("area", "square-centimeter"); 416 417 /** 418 * Constant for unit of area: square-foot 419 */ 420 public static final MeasureUnit SQUARE_FOOT = MeasureUnit.internalGetInstance("area", "square-foot"); 421 422 /** 423 * Constant for unit of area: square-inch 424 */ 425 public static final MeasureUnit SQUARE_INCH = MeasureUnit.internalGetInstance("area", "square-inch"); 426 427 /** 428 * Constant for unit of area: square-kilometer 429 */ 430 public static final MeasureUnit SQUARE_KILOMETER = MeasureUnit.internalGetInstance("area", "square-kilometer"); 431 432 /** 433 * Constant for unit of area: square-meter 434 */ 435 public static final MeasureUnit SQUARE_METER = MeasureUnit.internalGetInstance("area", "square-meter"); 436 437 /** 438 * Constant for unit of area: square-mile 439 */ 440 public static final MeasureUnit SQUARE_MILE = MeasureUnit.internalGetInstance("area", "square-mile"); 441 442 /** 443 * Constant for unit of area: square-yard 444 */ 445 public static final MeasureUnit SQUARE_YARD = MeasureUnit.internalGetInstance("area", "square-yard"); 446 447 /** 448 * Constant for unit of concentr: karat 449 */ 450 public static final MeasureUnit KARAT = MeasureUnit.internalGetInstance("concentr", "karat"); 451 452 /** 453 * Constant for unit of concentr: milligram-per-deciliter 454 */ 455 public static final MeasureUnit MILLIGRAM_PER_DECILITER = MeasureUnit.internalGetInstance("concentr", "milligram-per-deciliter"); 456 457 /** 458 * Constant for unit of concentr: millimole-per-liter 459 */ 460 public static final MeasureUnit MILLIMOLE_PER_LITER = MeasureUnit.internalGetInstance("concentr", "millimole-per-liter"); 461 462 /** 463 * Constant for unit of concentr: part-per-million 464 */ 465 public static final MeasureUnit PART_PER_MILLION = MeasureUnit.internalGetInstance("concentr", "part-per-million"); 466 467 /** 468 * Constant for unit of consumption: liter-per-100kilometers 469 */ 470 public static final MeasureUnit LITER_PER_100KILOMETERS = MeasureUnit.internalGetInstance("consumption", "liter-per-100kilometers"); 471 472 /** 473 * Constant for unit of consumption: liter-per-kilometer 474 */ 475 public static final MeasureUnit LITER_PER_KILOMETER = MeasureUnit.internalGetInstance("consumption", "liter-per-kilometer"); 476 477 /** 478 * Constant for unit of consumption: mile-per-gallon 479 */ 480 public static final MeasureUnit MILE_PER_GALLON = MeasureUnit.internalGetInstance("consumption", "mile-per-gallon"); 481 482 /** 483 * Constant for unit of consumption: mile-per-gallon-imperial 484 */ 485 public static final MeasureUnit MILE_PER_GALLON_IMPERIAL = MeasureUnit.internalGetInstance("consumption", "mile-per-gallon-imperial"); 486 487 /* 488 * at-draft ICU 58, withdrawn 489 * public static final MeasureUnit EAST = MeasureUnit.internalGetInstance("coordinate", "east"); 490 * public static final MeasureUnit NORTH = MeasureUnit.internalGetInstance("coordinate", "north"); 491 * public static final MeasureUnit SOUTH = MeasureUnit.internalGetInstance("coordinate", "south"); 492 * public static final MeasureUnit WEST = MeasureUnit.internalGetInstance("coordinate", "west"); 493 */ 494 495 /** 496 * Constant for unit of digital: bit 497 */ 498 public static final MeasureUnit BIT = MeasureUnit.internalGetInstance("digital", "bit"); 499 500 /** 501 * Constant for unit of digital: byte 502 */ 503 public static final MeasureUnit BYTE = MeasureUnit.internalGetInstance("digital", "byte"); 504 505 /** 506 * Constant for unit of digital: gigabit 507 */ 508 public static final MeasureUnit GIGABIT = MeasureUnit.internalGetInstance("digital", "gigabit"); 509 510 /** 511 * Constant for unit of digital: gigabyte 512 */ 513 public static final MeasureUnit GIGABYTE = MeasureUnit.internalGetInstance("digital", "gigabyte"); 514 515 /** 516 * Constant for unit of digital: kilobit 517 */ 518 public static final MeasureUnit KILOBIT = MeasureUnit.internalGetInstance("digital", "kilobit"); 519 520 /** 521 * Constant for unit of digital: kilobyte 522 */ 523 public static final MeasureUnit KILOBYTE = MeasureUnit.internalGetInstance("digital", "kilobyte"); 524 525 /** 526 * Constant for unit of digital: megabit 527 */ 528 public static final MeasureUnit MEGABIT = MeasureUnit.internalGetInstance("digital", "megabit"); 529 530 /** 531 * Constant for unit of digital: megabyte 532 */ 533 public static final MeasureUnit MEGABYTE = MeasureUnit.internalGetInstance("digital", "megabyte"); 534 535 /** 536 * Constant for unit of digital: terabit 537 */ 538 public static final MeasureUnit TERABIT = MeasureUnit.internalGetInstance("digital", "terabit"); 539 540 /** 541 * Constant for unit of digital: terabyte 542 */ 543 public static final MeasureUnit TERABYTE = MeasureUnit.internalGetInstance("digital", "terabyte"); 544 545 /** 546 * Constant for unit of duration: century 547 */ 548 public static final MeasureUnit CENTURY = MeasureUnit.internalGetInstance("duration", "century"); 549 550 /** 551 * Constant for unit of duration: day 552 */ 553 public static final TimeUnit DAY = (TimeUnit) MeasureUnit.internalGetInstance("duration", "day"); 554 555 /** 556 * Constant for unit of duration: hour 557 */ 558 public static final TimeUnit HOUR = (TimeUnit) MeasureUnit.internalGetInstance("duration", "hour"); 559 560 /** 561 * Constant for unit of duration: microsecond 562 */ 563 public static final MeasureUnit MICROSECOND = MeasureUnit.internalGetInstance("duration", "microsecond"); 564 565 /** 566 * Constant for unit of duration: millisecond 567 */ 568 public static final MeasureUnit MILLISECOND = MeasureUnit.internalGetInstance("duration", "millisecond"); 569 570 /** 571 * Constant for unit of duration: minute 572 */ 573 public static final TimeUnit MINUTE = (TimeUnit) MeasureUnit.internalGetInstance("duration", "minute"); 574 575 /** 576 * Constant for unit of duration: month 577 */ 578 public static final TimeUnit MONTH = (TimeUnit) MeasureUnit.internalGetInstance("duration", "month"); 579 580 /** 581 * Constant for unit of duration: nanosecond 582 */ 583 public static final MeasureUnit NANOSECOND = MeasureUnit.internalGetInstance("duration", "nanosecond"); 584 585 /** 586 * Constant for unit of duration: second 587 */ 588 public static final TimeUnit SECOND = (TimeUnit) MeasureUnit.internalGetInstance("duration", "second"); 589 590 /** 591 * Constant for unit of duration: week 592 */ 593 public static final TimeUnit WEEK = (TimeUnit) MeasureUnit.internalGetInstance("duration", "week"); 594 595 /** 596 * Constant for unit of duration: year 597 */ 598 public static final TimeUnit YEAR = (TimeUnit) MeasureUnit.internalGetInstance("duration", "year"); 599 600 /** 601 * Constant for unit of electric: ampere 602 */ 603 public static final MeasureUnit AMPERE = MeasureUnit.internalGetInstance("electric", "ampere"); 604 605 /** 606 * Constant for unit of electric: milliampere 607 */ 608 public static final MeasureUnit MILLIAMPERE = MeasureUnit.internalGetInstance("electric", "milliampere"); 609 610 /** 611 * Constant for unit of electric: ohm 612 */ 613 public static final MeasureUnit OHM = MeasureUnit.internalGetInstance("electric", "ohm"); 614 615 /** 616 * Constant for unit of electric: volt 617 */ 618 public static final MeasureUnit VOLT = MeasureUnit.internalGetInstance("electric", "volt"); 619 620 /** 621 * Constant for unit of energy: calorie 622 */ 623 public static final MeasureUnit CALORIE = MeasureUnit.internalGetInstance("energy", "calorie"); 624 625 /** 626 * Constant for unit of energy: foodcalorie 627 */ 628 public static final MeasureUnit FOODCALORIE = MeasureUnit.internalGetInstance("energy", "foodcalorie"); 629 630 /** 631 * Constant for unit of energy: joule 632 */ 633 public static final MeasureUnit JOULE = MeasureUnit.internalGetInstance("energy", "joule"); 634 635 /** 636 * Constant for unit of energy: kilocalorie 637 */ 638 public static final MeasureUnit KILOCALORIE = MeasureUnit.internalGetInstance("energy", "kilocalorie"); 639 640 /** 641 * Constant for unit of energy: kilojoule 642 */ 643 public static final MeasureUnit KILOJOULE = MeasureUnit.internalGetInstance("energy", "kilojoule"); 644 645 /** 646 * Constant for unit of energy: kilowatt-hour 647 */ 648 public static final MeasureUnit KILOWATT_HOUR = MeasureUnit.internalGetInstance("energy", "kilowatt-hour"); 649 650 /** 651 * Constant for unit of frequency: gigahertz 652 */ 653 public static final MeasureUnit GIGAHERTZ = MeasureUnit.internalGetInstance("frequency", "gigahertz"); 654 655 /** 656 * Constant for unit of frequency: hertz 657 */ 658 public static final MeasureUnit HERTZ = MeasureUnit.internalGetInstance("frequency", "hertz"); 659 660 /** 661 * Constant for unit of frequency: kilohertz 662 */ 663 public static final MeasureUnit KILOHERTZ = MeasureUnit.internalGetInstance("frequency", "kilohertz"); 664 665 /** 666 * Constant for unit of frequency: megahertz 667 */ 668 public static final MeasureUnit MEGAHERTZ = MeasureUnit.internalGetInstance("frequency", "megahertz"); 669 670 /** 671 * Constant for unit of length: astronomical-unit 672 */ 673 public static final MeasureUnit ASTRONOMICAL_UNIT = MeasureUnit.internalGetInstance("length", "astronomical-unit"); 674 675 /** 676 * Constant for unit of length: centimeter 677 */ 678 public static final MeasureUnit CENTIMETER = MeasureUnit.internalGetInstance("length", "centimeter"); 679 680 /** 681 * Constant for unit of length: decimeter 682 */ 683 public static final MeasureUnit DECIMETER = MeasureUnit.internalGetInstance("length", "decimeter"); 684 685 /** 686 * Constant for unit of length: fathom 687 */ 688 public static final MeasureUnit FATHOM = MeasureUnit.internalGetInstance("length", "fathom"); 689 690 /** 691 * Constant for unit of length: foot 692 */ 693 public static final MeasureUnit FOOT = MeasureUnit.internalGetInstance("length", "foot"); 694 695 /** 696 * Constant for unit of length: furlong 697 */ 698 public static final MeasureUnit FURLONG = MeasureUnit.internalGetInstance("length", "furlong"); 699 700 /** 701 * Constant for unit of length: inch 702 */ 703 public static final MeasureUnit INCH = MeasureUnit.internalGetInstance("length", "inch"); 704 705 /** 706 * Constant for unit of length: kilometer 707 */ 708 public static final MeasureUnit KILOMETER = MeasureUnit.internalGetInstance("length", "kilometer"); 709 710 /** 711 * Constant for unit of length: light-year 712 */ 713 public static final MeasureUnit LIGHT_YEAR = MeasureUnit.internalGetInstance("length", "light-year"); 714 715 /** 716 * Constant for unit of length: meter 717 */ 718 public static final MeasureUnit METER = MeasureUnit.internalGetInstance("length", "meter"); 719 720 /** 721 * Constant for unit of length: micrometer 722 */ 723 public static final MeasureUnit MICROMETER = MeasureUnit.internalGetInstance("length", "micrometer"); 724 725 /** 726 * Constant for unit of length: mile 727 */ 728 public static final MeasureUnit MILE = MeasureUnit.internalGetInstance("length", "mile"); 729 730 /** 731 * Constant for unit of length: mile-scandinavian 732 */ 733 public static final MeasureUnit MILE_SCANDINAVIAN = MeasureUnit.internalGetInstance("length", "mile-scandinavian"); 734 735 /** 736 * Constant for unit of length: millimeter 737 */ 738 public static final MeasureUnit MILLIMETER = MeasureUnit.internalGetInstance("length", "millimeter"); 739 740 /** 741 * Constant for unit of length: nanometer 742 */ 743 public static final MeasureUnit NANOMETER = MeasureUnit.internalGetInstance("length", "nanometer"); 744 745 /** 746 * Constant for unit of length: nautical-mile 747 */ 748 public static final MeasureUnit NAUTICAL_MILE = MeasureUnit.internalGetInstance("length", "nautical-mile"); 749 750 /** 751 * Constant for unit of length: parsec 752 */ 753 public static final MeasureUnit PARSEC = MeasureUnit.internalGetInstance("length", "parsec"); 754 755 /** 756 * Constant for unit of length: picometer 757 */ 758 public static final MeasureUnit PICOMETER = MeasureUnit.internalGetInstance("length", "picometer"); 759 760 /** 761 * Constant for unit of length: point 762 * @hide draft / provisional / internal are hidden on Android 763 */ 764 public static final MeasureUnit POINT = MeasureUnit.internalGetInstance("length", "point"); 765 766 /** 767 * Constant for unit of length: yard 768 */ 769 public static final MeasureUnit YARD = MeasureUnit.internalGetInstance("length", "yard"); 770 771 /** 772 * Constant for unit of light: lux 773 */ 774 public static final MeasureUnit LUX = MeasureUnit.internalGetInstance("light", "lux"); 775 776 /** 777 * Constant for unit of mass: carat 778 */ 779 public static final MeasureUnit CARAT = MeasureUnit.internalGetInstance("mass", "carat"); 780 781 /** 782 * Constant for unit of mass: gram 783 */ 784 public static final MeasureUnit GRAM = MeasureUnit.internalGetInstance("mass", "gram"); 785 786 /** 787 * Constant for unit of mass: kilogram 788 */ 789 public static final MeasureUnit KILOGRAM = MeasureUnit.internalGetInstance("mass", "kilogram"); 790 791 /** 792 * Constant for unit of mass: metric-ton 793 */ 794 public static final MeasureUnit METRIC_TON = MeasureUnit.internalGetInstance("mass", "metric-ton"); 795 796 /** 797 * Constant for unit of mass: microgram 798 */ 799 public static final MeasureUnit MICROGRAM = MeasureUnit.internalGetInstance("mass", "microgram"); 800 801 /** 802 * Constant for unit of mass: milligram 803 */ 804 public static final MeasureUnit MILLIGRAM = MeasureUnit.internalGetInstance("mass", "milligram"); 805 806 /** 807 * Constant for unit of mass: ounce 808 */ 809 public static final MeasureUnit OUNCE = MeasureUnit.internalGetInstance("mass", "ounce"); 810 811 /** 812 * Constant for unit of mass: ounce-troy 813 */ 814 public static final MeasureUnit OUNCE_TROY = MeasureUnit.internalGetInstance("mass", "ounce-troy"); 815 816 /** 817 * Constant for unit of mass: pound 818 */ 819 public static final MeasureUnit POUND = MeasureUnit.internalGetInstance("mass", "pound"); 820 821 /** 822 * Constant for unit of mass: stone 823 */ 824 public static final MeasureUnit STONE = MeasureUnit.internalGetInstance("mass", "stone"); 825 826 /** 827 * Constant for unit of mass: ton 828 */ 829 public static final MeasureUnit TON = MeasureUnit.internalGetInstance("mass", "ton"); 830 831 /** 832 * Constant for unit of power: gigawatt 833 */ 834 public static final MeasureUnit GIGAWATT = MeasureUnit.internalGetInstance("power", "gigawatt"); 835 836 /** 837 * Constant for unit of power: horsepower 838 */ 839 public static final MeasureUnit HORSEPOWER = MeasureUnit.internalGetInstance("power", "horsepower"); 840 841 /** 842 * Constant for unit of power: kilowatt 843 */ 844 public static final MeasureUnit KILOWATT = MeasureUnit.internalGetInstance("power", "kilowatt"); 845 846 /** 847 * Constant for unit of power: megawatt 848 */ 849 public static final MeasureUnit MEGAWATT = MeasureUnit.internalGetInstance("power", "megawatt"); 850 851 /** 852 * Constant for unit of power: milliwatt 853 */ 854 public static final MeasureUnit MILLIWATT = MeasureUnit.internalGetInstance("power", "milliwatt"); 855 856 /** 857 * Constant for unit of power: watt 858 */ 859 public static final MeasureUnit WATT = MeasureUnit.internalGetInstance("power", "watt"); 860 861 /** 862 * Constant for unit of pressure: hectopascal 863 */ 864 public static final MeasureUnit HECTOPASCAL = MeasureUnit.internalGetInstance("pressure", "hectopascal"); 865 866 /** 867 * Constant for unit of pressure: inch-hg 868 */ 869 public static final MeasureUnit INCH_HG = MeasureUnit.internalGetInstance("pressure", "inch-hg"); 870 871 /** 872 * Constant for unit of pressure: millibar 873 */ 874 public static final MeasureUnit MILLIBAR = MeasureUnit.internalGetInstance("pressure", "millibar"); 875 876 /** 877 * Constant for unit of pressure: millimeter-of-mercury 878 */ 879 public static final MeasureUnit MILLIMETER_OF_MERCURY = MeasureUnit.internalGetInstance("pressure", "millimeter-of-mercury"); 880 881 /** 882 * Constant for unit of pressure: pound-per-square-inch 883 */ 884 public static final MeasureUnit POUND_PER_SQUARE_INCH = MeasureUnit.internalGetInstance("pressure", "pound-per-square-inch"); 885 886 /** 887 * Constant for unit of speed: kilometer-per-hour 888 */ 889 public static final MeasureUnit KILOMETER_PER_HOUR = MeasureUnit.internalGetInstance("speed", "kilometer-per-hour"); 890 891 /** 892 * Constant for unit of speed: knot 893 */ 894 public static final MeasureUnit KNOT = MeasureUnit.internalGetInstance("speed", "knot"); 895 896 /** 897 * Constant for unit of speed: meter-per-second 898 */ 899 public static final MeasureUnit METER_PER_SECOND = MeasureUnit.internalGetInstance("speed", "meter-per-second"); 900 901 /** 902 * Constant for unit of speed: mile-per-hour 903 */ 904 public static final MeasureUnit MILE_PER_HOUR = MeasureUnit.internalGetInstance("speed", "mile-per-hour"); 905 906 /** 907 * Constant for unit of temperature: celsius 908 */ 909 public static final MeasureUnit CELSIUS = MeasureUnit.internalGetInstance("temperature", "celsius"); 910 911 /** 912 * Constant for unit of temperature: fahrenheit 913 */ 914 public static final MeasureUnit FAHRENHEIT = MeasureUnit.internalGetInstance("temperature", "fahrenheit"); 915 916 /** 917 * Constant for unit of temperature: generic 918 */ 919 public static final MeasureUnit GENERIC_TEMPERATURE = MeasureUnit.internalGetInstance("temperature", "generic"); 920 921 /** 922 * Constant for unit of temperature: kelvin 923 */ 924 public static final MeasureUnit KELVIN = MeasureUnit.internalGetInstance("temperature", "kelvin"); 925 926 /** 927 * Constant for unit of volume: acre-foot 928 */ 929 public static final MeasureUnit ACRE_FOOT = MeasureUnit.internalGetInstance("volume", "acre-foot"); 930 931 /** 932 * Constant for unit of volume: bushel 933 */ 934 public static final MeasureUnit BUSHEL = MeasureUnit.internalGetInstance("volume", "bushel"); 935 936 /** 937 * Constant for unit of volume: centiliter 938 */ 939 public static final MeasureUnit CENTILITER = MeasureUnit.internalGetInstance("volume", "centiliter"); 940 941 /** 942 * Constant for unit of volume: cubic-centimeter 943 */ 944 public static final MeasureUnit CUBIC_CENTIMETER = MeasureUnit.internalGetInstance("volume", "cubic-centimeter"); 945 946 /** 947 * Constant for unit of volume: cubic-foot 948 */ 949 public static final MeasureUnit CUBIC_FOOT = MeasureUnit.internalGetInstance("volume", "cubic-foot"); 950 951 /** 952 * Constant for unit of volume: cubic-inch 953 */ 954 public static final MeasureUnit CUBIC_INCH = MeasureUnit.internalGetInstance("volume", "cubic-inch"); 955 956 /** 957 * Constant for unit of volume: cubic-kilometer 958 */ 959 public static final MeasureUnit CUBIC_KILOMETER = MeasureUnit.internalGetInstance("volume", "cubic-kilometer"); 960 961 /** 962 * Constant for unit of volume: cubic-meter 963 */ 964 public static final MeasureUnit CUBIC_METER = MeasureUnit.internalGetInstance("volume", "cubic-meter"); 965 966 /** 967 * Constant for unit of volume: cubic-mile 968 */ 969 public static final MeasureUnit CUBIC_MILE = MeasureUnit.internalGetInstance("volume", "cubic-mile"); 970 971 /** 972 * Constant for unit of volume: cubic-yard 973 */ 974 public static final MeasureUnit CUBIC_YARD = MeasureUnit.internalGetInstance("volume", "cubic-yard"); 975 976 /** 977 * Constant for unit of volume: cup 978 */ 979 public static final MeasureUnit CUP = MeasureUnit.internalGetInstance("volume", "cup"); 980 981 /** 982 * Constant for unit of volume: cup-metric 983 */ 984 public static final MeasureUnit CUP_METRIC = MeasureUnit.internalGetInstance("volume", "cup-metric"); 985 986 /** 987 * Constant for unit of volume: deciliter 988 */ 989 public static final MeasureUnit DECILITER = MeasureUnit.internalGetInstance("volume", "deciliter"); 990 991 /** 992 * Constant for unit of volume: fluid-ounce 993 */ 994 public static final MeasureUnit FLUID_OUNCE = MeasureUnit.internalGetInstance("volume", "fluid-ounce"); 995 996 /** 997 * Constant for unit of volume: gallon 998 */ 999 public static final MeasureUnit GALLON = MeasureUnit.internalGetInstance("volume", "gallon"); 1000 1001 /** 1002 * Constant for unit of volume: gallon-imperial 1003 */ 1004 public static final MeasureUnit GALLON_IMPERIAL = MeasureUnit.internalGetInstance("volume", "gallon-imperial"); 1005 1006 /** 1007 * Constant for unit of volume: hectoliter 1008 */ 1009 public static final MeasureUnit HECTOLITER = MeasureUnit.internalGetInstance("volume", "hectoliter"); 1010 1011 /** 1012 * Constant for unit of volume: liter 1013 */ 1014 public static final MeasureUnit LITER = MeasureUnit.internalGetInstance("volume", "liter"); 1015 1016 /** 1017 * Constant for unit of volume: megaliter 1018 */ 1019 public static final MeasureUnit MEGALITER = MeasureUnit.internalGetInstance("volume", "megaliter"); 1020 1021 /** 1022 * Constant for unit of volume: milliliter 1023 */ 1024 public static final MeasureUnit MILLILITER = MeasureUnit.internalGetInstance("volume", "milliliter"); 1025 1026 /** 1027 * Constant for unit of volume: pint 1028 */ 1029 public static final MeasureUnit PINT = MeasureUnit.internalGetInstance("volume", "pint"); 1030 1031 /** 1032 * Constant for unit of volume: pint-metric 1033 */ 1034 public static final MeasureUnit PINT_METRIC = MeasureUnit.internalGetInstance("volume", "pint-metric"); 1035 1036 /** 1037 * Constant for unit of volume: quart 1038 */ 1039 public static final MeasureUnit QUART = MeasureUnit.internalGetInstance("volume", "quart"); 1040 1041 /** 1042 * Constant for unit of volume: tablespoon 1043 */ 1044 public static final MeasureUnit TABLESPOON = MeasureUnit.internalGetInstance("volume", "tablespoon"); 1045 1046 /** 1047 * Constant for unit of volume: teaspoon 1048 */ 1049 public static final MeasureUnit TEASPOON = MeasureUnit.internalGetInstance("volume", "teaspoon"); 1050 1051 private static HashMap<Pair<MeasureUnit, MeasureUnit>, MeasureUnit>unitPerUnitToSingleUnit = 1052 new HashMap<Pair<MeasureUnit, MeasureUnit>, MeasureUnit>(); 1053 1054 static { 1055 unitPerUnitToSingleUnit.put(Pair.<MeasureUnit, MeasureUnit>of(MeasureUnit.LITER, MeasureUnit.KILOMETER), MeasureUnit.LITER_PER_KILOMETER); 1056 unitPerUnitToSingleUnit.put(Pair.<MeasureUnit, MeasureUnit>of(MeasureUnit.POUND, MeasureUnit.SQUARE_INCH), MeasureUnit.POUND_PER_SQUARE_INCH); 1057 unitPerUnitToSingleUnit.put(Pair.<MeasureUnit, MeasureUnit>of(MeasureUnit.MILE, MeasureUnit.HOUR), MeasureUnit.MILE_PER_HOUR); 1058 unitPerUnitToSingleUnit.put(Pair.<MeasureUnit, MeasureUnit>of(MeasureUnit.MILLIGRAM, MeasureUnit.DECILITER), MeasureUnit.MILLIGRAM_PER_DECILITER); 1059 unitPerUnitToSingleUnit.put(Pair.<MeasureUnit, MeasureUnit>of(MeasureUnit.MILE, MeasureUnit.GALLON_IMPERIAL), MeasureUnit.MILE_PER_GALLON_IMPERIAL); 1060 unitPerUnitToSingleUnit.put(Pair.<MeasureUnit, MeasureUnit>of(MeasureUnit.KILOMETER, MeasureUnit.HOUR), MeasureUnit.KILOMETER_PER_HOUR); 1061 unitPerUnitToSingleUnit.put(Pair.<MeasureUnit, MeasureUnit>of(MeasureUnit.MILE, MeasureUnit.GALLON), MeasureUnit.MILE_PER_GALLON); 1062 unitPerUnitToSingleUnit.put(Pair.<MeasureUnit, MeasureUnit>of(MeasureUnit.METER, MeasureUnit.SECOND), MeasureUnit.METER_PER_SECOND); 1063 } 1064 1065 // End generated MeasureUnit constants 1066 /* Private */ 1067 1068 private Object writeReplace() throws ObjectStreamException { 1069 return new MeasureUnitProxy(type, subType); 1070 } 1071 1072 static final class MeasureUnitProxy implements Externalizable { 1073 private static final long serialVersionUID = -3910681415330989598L; 1074 1075 private String type; 1076 private String subType; 1077 1078 public MeasureUnitProxy(String type, String subType) { 1079 this.type = type; 1080 this.subType = subType; 1081 } 1082 1083 // Must have public constructor, to enable Externalizable 1084 public MeasureUnitProxy() { 1085 } 1086 1087 @Override 1088 public void writeExternal(ObjectOutput out) throws IOException { 1089 out.writeByte(0); // version 1090 out.writeUTF(type); 1091 out.writeUTF(subType); 1092 out.writeShort(0); // allow for more data. 1093 } 1094 1095 @Override 1096 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { 1097 /* byte version = */ in.readByte(); // version 1098 type = in.readUTF(); 1099 subType = in.readUTF(); 1100 // allow for more data from future version 1101 int extra = in.readShort(); 1102 if (extra > 0) { 1103 byte[] extraBytes = new byte[extra]; 1104 in.read(extraBytes, 0, extra); 1105 } 1106 } 1107 1108 private Object readResolve() throws ObjectStreamException { 1109 return MeasureUnit.internalGetInstance(type, subType); 1110 } 1111 } 1112} 1113