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