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