LocaleData.java revision e2377cdd707b830d07a5708216834f7ac76ee3e1
133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes/*
233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * Copyright (C) 2009 The Android Open Source Project
333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes *
433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * you may not use this file except in compliance with the License.
633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * You may obtain a copy of the License at
733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes *
833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes *
1033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * Unless required by applicable law or agreed to in writing, software
1133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
1233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * See the License for the specific language governing permissions and
1433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * limitations under the License.
1533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes */
1633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes
17162b0775772fa66b7eb634760a8159a60c1ddceaElliott Hughespackage libcore.icu;
1833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes
196ca85c49efc0f02d69933f60b207b964a999061fElliott Hughesimport java.text.DateFormat;
20deacd761e85ee4d75a6adbdd63225fc4a6d3088dElliott Hughesimport java.util.Arrays;
21757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughesimport java.util.HashMap;
22757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughesimport java.util.Locale;
236ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes
2433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes/**
2533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * Passes locale-specific from ICU native code to Java.
2633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * <p>
2733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * Note that you share these; you must not alter any of the fields, nor their array elements
2833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * in the case of arrays. If you ever expose any of these things to user code, you must give
2933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * them a clone rather than the original.
3033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes */
319672b4887f2972c1b7c5f3d1a6cf882deccf857fElliott Hughespublic final class LocaleData {
32757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    // A cache for the locale-specific data.
33757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    private static final HashMap<String, LocaleData> localeDataCache = new HashMap<String, LocaleData>();
34e2377cdd707b830d07a5708216834f7ac76ee3e1Elliott Hughes    static {
35e2377cdd707b830d07a5708216834f7ac76ee3e1Elliott Hughes        // Ensure that we pull in the locale data for the root locale, en_US, and the
36e2377cdd707b830d07a5708216834f7ac76ee3e1Elliott Hughes        // user's default locale. (All devices must support the root locale and en_US,
37e2377cdd707b830d07a5708216834f7ac76ee3e1Elliott Hughes        // and they're used for various system things like HTTP headers.) Pre-populating
38e2377cdd707b830d07a5708216834f7ac76ee3e1Elliott Hughes        // the cache is especially useful on Android because we'll share this via the Zygote.
39e2377cdd707b830d07a5708216834f7ac76ee3e1Elliott Hughes        get(Locale.ROOT);
40e2377cdd707b830d07a5708216834f7ac76ee3e1Elliott Hughes        get(Locale.US);
41e2377cdd707b830d07a5708216834f7ac76ee3e1Elliott Hughes        get(Locale.getDefault());
42e2377cdd707b830d07a5708216834f7ac76ee3e1Elliott Hughes    }
43757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
44143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes    // Used by Calendar.
4533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public Integer firstDayOfWeek;
4633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public Integer minimalDaysInFirstWeek;
47757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
48143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes    // Used by DateFormatSymbols.
4933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String[] amPm;
5033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String[] eras;
51757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
5233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String[] longMonthNames;
5333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String[] shortMonthNames;
54143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes    public String[] longStandAloneMonthNames;
55143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes    public String[] shortStandAloneMonthNames;
56757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
5733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String[] longWeekdayNames;
5833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String[] shortWeekdayNames;
59143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes    public String[] longStandAloneWeekdayNames;
60143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes    public String[] shortStandAloneWeekdayNames;
61757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
6233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String fullTimeFormat;
6333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String longTimeFormat;
6433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String mediumTimeFormat;
6533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String shortTimeFormat;
66757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
6733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String fullDateFormat;
6833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String longDateFormat;
6933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String mediumDateFormat;
7033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String shortDateFormat;
71757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
72143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes    // Used by DecimalFormatSymbols.
73b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes    public char zeroDigit;
74b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes    public char decimalSeparator;
75b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes    public char groupingSeparator;
76b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes    public char patternSeparator;
77b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes    public char percent;
78b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes    public char perMill;
79b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes    public char monetarySeparator;
80b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes    public char minusSign;
8190aa512eb7b126deb8d752b7474c30d3f73507b2Elliott Hughes    public String exponentSeparator;
8233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String infinity;
8333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String NaN;
84143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes    // Also used by Currency.
8533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String currencySymbol;
8633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String internationalCurrencySymbol;
87757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
88143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes    // Used by DecimalFormat and NumberFormat.
8933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String numberPattern;
9033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String integerPattern;
9133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String currencyPattern;
9233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String percentPattern;
93757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
94757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    private LocaleData() {
95757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    }
96757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
97757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    /**
98757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes     * Returns a shared LocaleData for the given locale.
99757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes     */
100757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    public static LocaleData get(Locale locale) {
101757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        if (locale == null) {
102757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            locale = Locale.getDefault();
103757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        }
104757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        String localeName = locale.toString();
105757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        synchronized (localeDataCache) {
106757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            LocaleData localeData = localeDataCache.get(localeName);
107757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            if (localeData != null) {
108757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes                return localeData;
109757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            }
110757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        }
111757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        LocaleData newLocaleData = makeLocaleData(locale);
112757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        synchronized (localeDataCache) {
113757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            LocaleData localeData = localeDataCache.get(localeName);
114757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            if (localeData != null) {
115757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes                return localeData;
116757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            }
117757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            localeDataCache.put(localeName, newLocaleData);
118757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            return newLocaleData;
119757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        }
120757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    }
121757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
122757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    private static LocaleData makeLocaleData(Locale locale) {
123757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        String language = locale.getLanguage();
124757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        String country = locale.getCountry();
125757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        String variant = locale.getVariant();
126757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        // Start with data from the parent (next-most-specific) locale...
127757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        LocaleData result = new LocaleData();
128757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        if (!variant.isEmpty()) {
129757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            result.overrideWithDataFrom(get(new Locale(language, country, "")));
130757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        } else if (!country.isEmpty()) {
131757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            result.overrideWithDataFrom(get(new Locale(language, "", "")));
132757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        } else if (!language.isEmpty()) {
133757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            result.overrideWithDataFrom(get(Locale.ROOT));
134757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        }
135757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        // Override with data from this locale.
136757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        result.overrideWithDataFrom(initLocaleData(locale));
137757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        return result;
138757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    }
139757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
14033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    @Override public String toString() {
14133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        return "LocaleData[" +
14233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "firstDayOfWeek=" + firstDayOfWeek + "," +
14333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "minimalDaysInFirstWeek=" + minimalDaysInFirstWeek + "," +
144deacd761e85ee4d75a6adbdd63225fc4a6d3088dElliott Hughes                "amPm=" + Arrays.toString(amPm) + "," +
145deacd761e85ee4d75a6adbdd63225fc4a6d3088dElliott Hughes                "eras=" + Arrays.toString(eras) + "," +
146deacd761e85ee4d75a6adbdd63225fc4a6d3088dElliott Hughes                "longMonthNames=" + Arrays.toString(longMonthNames) + "," +
147deacd761e85ee4d75a6adbdd63225fc4a6d3088dElliott Hughes                "shortMonthNames=" + Arrays.toString(shortMonthNames) + "," +
148143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes                "longStandAloneMonthNames=" + Arrays.toString(longStandAloneMonthNames) + "," +
149143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes                "shortStandAloneMonthNames=" + Arrays.toString(shortStandAloneMonthNames) + "," +
150deacd761e85ee4d75a6adbdd63225fc4a6d3088dElliott Hughes                "longWeekdayNames=" + Arrays.toString(longWeekdayNames) + "," +
151deacd761e85ee4d75a6adbdd63225fc4a6d3088dElliott Hughes                "shortWeekdayNames=" + Arrays.toString(shortWeekdayNames) + "," +
152143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes                "longStandAloneWeekdayNames=" + Arrays.toString(longStandAloneWeekdayNames) + "," +
153143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes                "shortStandAloneWeekdayNames=" + Arrays.toString(shortStandAloneWeekdayNames) + "," +
15433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "fullTimeFormat=" + fullTimeFormat + "," +
15533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "longTimeFormat=" + longTimeFormat + "," +
15633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "mediumTimeFormat=" + mediumTimeFormat + "," +
15733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "shortTimeFormat=" + shortTimeFormat + "," +
15833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "fullDateFormat=" + fullDateFormat + "," +
15933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "longDateFormat=" + longDateFormat + "," +
16033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "mediumDateFormat=" + mediumDateFormat + "," +
16133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "shortDateFormat=" + shortDateFormat + "," +
162b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes                "zeroDigit=" + zeroDigit + "," +
163b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes                "decimalSeparator=" + decimalSeparator + "," +
164b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes                "groupingSeparator=" + groupingSeparator + "," +
165b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes                "patternSeparator=" + patternSeparator + "," +
166b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes                "percent=" + percent + "," +
167b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes                "perMill=" + perMill + "," +
168b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes                "monetarySeparator=" + monetarySeparator + "," +
169b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes                "minusSign=" + minusSign + "," +
17090aa512eb7b126deb8d752b7474c30d3f73507b2Elliott Hughes                "exponentSeparator=" + exponentSeparator + "," +
17133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "infinity=" + infinity + "," +
17233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "NaN=" + NaN + "," +
17333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "currencySymbol=" + currencySymbol + "," +
17433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "internationalCurrencySymbol=" + internationalCurrencySymbol + "," +
17533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "numberPattern=" + numberPattern + "," +
17633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "integerPattern=" + integerPattern + "," +
17733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "currencyPattern=" + currencyPattern + "," +
17833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "percentPattern=" + percentPattern + "]";
17933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    }
180757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
181757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    private void overrideWithDataFrom(LocaleData overrides) {
18233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.firstDayOfWeek != null) {
18333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            firstDayOfWeek = overrides.firstDayOfWeek;
18433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
18533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.minimalDaysInFirstWeek != null) {
18633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            minimalDaysInFirstWeek = overrides.minimalDaysInFirstWeek;
18733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
18833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.amPm != null) {
18933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            amPm = overrides.amPm;
19033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
19133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.eras != null) {
19233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            eras = overrides.eras;
19333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
19433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.longMonthNames != null) {
19533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            longMonthNames = overrides.longMonthNames;
19633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
19733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.shortMonthNames != null) {
19833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            shortMonthNames = overrides.shortMonthNames;
19933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
200143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes        if (overrides.longStandAloneMonthNames != null) {
201143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes            longStandAloneMonthNames = overrides.longStandAloneMonthNames;
202143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes        }
203143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes        if (overrides.shortStandAloneMonthNames != null) {
204143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes            shortStandAloneMonthNames = overrides.shortStandAloneMonthNames;
205143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes        }
20633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.longWeekdayNames != null) {
20733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            longWeekdayNames = overrides.longWeekdayNames;
20833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
20933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.shortWeekdayNames != null) {
21033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            shortWeekdayNames = overrides.shortWeekdayNames;
21133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
212143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes        if (overrides.longStandAloneWeekdayNames != null) {
213143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes            longStandAloneWeekdayNames = overrides.longStandAloneWeekdayNames;
214143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes        }
215143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes        if (overrides.shortStandAloneWeekdayNames != null) {
216143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes            shortStandAloneWeekdayNames = overrides.shortStandAloneWeekdayNames;
217143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes        }
21833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.fullTimeFormat != null) {
21933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            fullTimeFormat = overrides.fullTimeFormat;
22033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
22133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.longTimeFormat != null) {
22233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            longTimeFormat = overrides.longTimeFormat;
22333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
22433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.mediumTimeFormat != null) {
22533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            mediumTimeFormat = overrides.mediumTimeFormat;
22633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
22733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.shortTimeFormat != null) {
22833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            shortTimeFormat = overrides.shortTimeFormat;
22933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
23033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.fullDateFormat != null) {
23133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            fullDateFormat = overrides.fullDateFormat;
23233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
23333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.longDateFormat != null) {
23433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            longDateFormat = overrides.longDateFormat;
23533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
23633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.mediumDateFormat != null) {
23733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            mediumDateFormat = overrides.mediumDateFormat;
23833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
23933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.shortDateFormat != null) {
24033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            shortDateFormat = overrides.shortDateFormat;
24133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
242b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes        if (overrides.zeroDigit != '\0') {
243b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes            zeroDigit = overrides.zeroDigit;
244b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes        }
245b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes        if (overrides.decimalSeparator != '\0') {
246b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes            decimalSeparator = overrides.decimalSeparator;
247b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes        }
248b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes        if (overrides.groupingSeparator != '\0') {
249b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes            groupingSeparator = overrides.groupingSeparator;
250b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes        }
251b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes        if (overrides.patternSeparator != '\0') {
252b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes            patternSeparator = overrides.patternSeparator;
253b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes        }
254b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes        if (overrides.percent != '\0') {
255b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes            percent = overrides.percent;
256b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes        }
257b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes        if (overrides.perMill != '\0') {
258b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes            perMill = overrides.perMill;
259b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes        }
260b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes        if (overrides.monetarySeparator != '\0') {
261b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes            monetarySeparator = overrides.monetarySeparator;
262b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes        }
263b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes        if (overrides.minusSign != '\0') {
264b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes            minusSign = overrides.minusSign;
26533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
26690aa512eb7b126deb8d752b7474c30d3f73507b2Elliott Hughes        if (overrides.exponentSeparator != null) {
26790aa512eb7b126deb8d752b7474c30d3f73507b2Elliott Hughes            exponentSeparator = overrides.exponentSeparator;
26890aa512eb7b126deb8d752b7474c30d3f73507b2Elliott Hughes        }
26933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.NaN != null) {
27033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            NaN = overrides.NaN;
27133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
27233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.infinity != null) {
27333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            infinity = overrides.infinity;
27433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
27533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.currencySymbol != null) {
27633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            currencySymbol = overrides.currencySymbol;
27733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
27833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.internationalCurrencySymbol != null) {
27933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            internationalCurrencySymbol = overrides.internationalCurrencySymbol;
28033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
28133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.numberPattern != null) {
28233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            numberPattern = overrides.numberPattern;
28333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
28433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.integerPattern != null) {
28533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            integerPattern = overrides.integerPattern;
28633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
28733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.currencyPattern != null) {
28833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            currencyPattern = overrides.currencyPattern;
28933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
29033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.percentPattern != null) {
29133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            percentPattern = overrides.percentPattern;
29233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
29333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    }
294757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
2956ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes    public String getDateFormat(int style) {
2966ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        switch (style) {
2976ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.SHORT:
2986ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return shortDateFormat;
2996ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.MEDIUM:
3006ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return mediumDateFormat;
3016ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.LONG:
3026ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return longDateFormat;
3036ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.FULL:
3046ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return fullDateFormat;
3056ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        }
3066ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        throw new AssertionError();
3076ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes    }
308757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
3096ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes    public String getTimeFormat(int style) {
3106ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        switch (style) {
3116ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.SHORT:
3126ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return shortTimeFormat;
3136ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.MEDIUM:
3146ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return mediumTimeFormat;
3156ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.LONG:
3166ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return longTimeFormat;
3176ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.FULL:
3186ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return fullTimeFormat;
3196ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        }
3206ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        throw new AssertionError();
3216ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes    }
322757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
323757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    private static LocaleData initLocaleData(Locale locale) {
324757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        LocaleData localeData = new LocaleData();
325757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        if (!ICU.initLocaleDataImpl(locale.toString(), localeData)) {
326757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            throw new AssertionError("couldn't initialize LocaleData for locale " + locale);
327757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        }
328757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        if (localeData.fullTimeFormat != null) {
329757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // There are some full time format patterns in ICU that use the pattern character 'v'.
330757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // Java doesn't accept this, so we replace it with 'z' which has about the same result
331757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // as 'v', the timezone name.
332757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // 'v' -> "PT", 'z' -> "PST", v is the generic timezone and z the standard tz
333757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // "vvvv" -> "Pacific Time", "zzzz" -> "Pacific Standard Time"
334757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            localeData.fullTimeFormat = localeData.fullTimeFormat.replace('v', 'z');
335757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        }
336757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        if (localeData.numberPattern != null) {
337757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // The number pattern might contain positive and negative subpatterns. Arabic, for
338757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // example, might look like "#,##0.###;#,##0.###-" because the minus sign should be
339757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // written last. Macedonian supposedly looks something like "#,##0.###;(#,##0.###)".
340757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // (The negative subpattern is optional, though, and not present in most locales.)
341757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // By only swallowing '#'es and ','s after the '.', we ensure that we don't
342757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // accidentally eat too much.
343757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            localeData.integerPattern = localeData.numberPattern.replaceAll("\\.[#,]*", "");
344757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        }
345757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        return localeData;
346757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    }
34733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes}
348