LocaleData.java revision deacd761e85ee4d75a6adbdd63225fc4a6d3088d
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
1733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughespackage com.ibm.icu4jni.util;
1833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes
196ca85c49efc0f02d69933f60b207b964a999061fElliott Hughesimport java.text.DateFormat;
20deacd761e85ee4d75a6adbdd63225fc4a6d3088dElliott Hughesimport java.util.Arrays;
216ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes
2233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes/**
2333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * Passes locale-specific from ICU native code to Java.
2433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * <p>
2533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * Note that you share these; you must not alter any of the fields, nor their array elements
2633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * in the case of arrays. If you ever expose any of these things to user code, you must give
2733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * them a clone rather than the original.
2833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes */
2933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughespublic class LocaleData {
3033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public Integer firstDayOfWeek;
3133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public Integer minimalDaysInFirstWeek;
3233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes
3333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String[] amPm;
3433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes
3533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String[] eras;
3633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes
3733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String[] longMonthNames;
3833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String[] shortMonthNames;
3933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes
4033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String[] longWeekdayNames;
4133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String[] shortWeekdayNames;
4233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes
4333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String fullTimeFormat;
4433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String longTimeFormat;
4533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String mediumTimeFormat;
4633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String shortTimeFormat;
4733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes
4833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String fullDateFormat;
4933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String longDateFormat;
5033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String mediumDateFormat;
5133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String shortDateFormat;
5233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes
5333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String decimalPatternChars;
5433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes
5533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String infinity;
5633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String NaN;
5733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes
5833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String currencySymbol;
5933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String internationalCurrencySymbol;
6033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes
6133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String numberPattern;
6233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String integerPattern;
6333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String currencyPattern;
6433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String percentPattern;
6533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes
6633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    @Override public String toString() {
6733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        return "LocaleData[" +
6833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "firstDayOfWeek=" + firstDayOfWeek + "," +
6933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "minimalDaysInFirstWeek=" + minimalDaysInFirstWeek + "," +
70deacd761e85ee4d75a6adbdd63225fc4a6d3088dElliott Hughes                "amPm=" + Arrays.toString(amPm) + "," +
71deacd761e85ee4d75a6adbdd63225fc4a6d3088dElliott Hughes                "eras=" + Arrays.toString(eras) + "," +
72deacd761e85ee4d75a6adbdd63225fc4a6d3088dElliott Hughes                "longMonthNames=" + Arrays.toString(longMonthNames) + "," +
73deacd761e85ee4d75a6adbdd63225fc4a6d3088dElliott Hughes                "shortMonthNames=" + Arrays.toString(shortMonthNames) + "," +
74deacd761e85ee4d75a6adbdd63225fc4a6d3088dElliott Hughes                "longWeekdayNames=" + Arrays.toString(longWeekdayNames) + "," +
75deacd761e85ee4d75a6adbdd63225fc4a6d3088dElliott Hughes                "shortWeekdayNames=" + Arrays.toString(shortWeekdayNames) + "," +
7633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "fullTimeFormat=" + fullTimeFormat + "," +
7733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "longTimeFormat=" + longTimeFormat + "," +
7833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "mediumTimeFormat=" + mediumTimeFormat + "," +
7933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "shortTimeFormat=" + shortTimeFormat + "," +
8033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "fullDateFormat=" + fullDateFormat + "," +
8133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "longDateFormat=" + longDateFormat + "," +
8233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "mediumDateFormat=" + mediumDateFormat + "," +
8333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "shortDateFormat=" + shortDateFormat + "," +
8433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "decimalPatternChars=" + decimalPatternChars + "," +
8533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "infinity=" + infinity + "," +
8633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "NaN=" + NaN + "," +
8733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "currencySymbol=" + currencySymbol + "," +
8833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "internationalCurrencySymbol=" + internationalCurrencySymbol + "," +
8933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "numberPattern=" + numberPattern + "," +
9033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "integerPattern=" + integerPattern + "," +
9133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "currencyPattern=" + currencyPattern + "," +
9233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes                "percentPattern=" + percentPattern + "]";
9333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    }
9433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes
9533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public void overrideWithDataFrom(LocaleData overrides) {
9633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.firstDayOfWeek != null) {
9733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            firstDayOfWeek = overrides.firstDayOfWeek;
9833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
9933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.minimalDaysInFirstWeek != null) {
10033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            minimalDaysInFirstWeek = overrides.minimalDaysInFirstWeek;
10133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
10233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.amPm != null) {
10333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            amPm = overrides.amPm;
10433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
10533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.eras != null) {
10633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            eras = overrides.eras;
10733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
10833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.longMonthNames != null) {
10933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            longMonthNames = overrides.longMonthNames;
11033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
11133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.shortMonthNames != null) {
11233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            shortMonthNames = overrides.shortMonthNames;
11333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
11433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.longWeekdayNames != null) {
11533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            longWeekdayNames = overrides.longWeekdayNames;
11633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
11733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.shortWeekdayNames != null) {
11833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            shortWeekdayNames = overrides.shortWeekdayNames;
11933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
12033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.fullTimeFormat != null) {
12133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            fullTimeFormat = overrides.fullTimeFormat;
12233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
12333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.longTimeFormat != null) {
12433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            longTimeFormat = overrides.longTimeFormat;
12533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
12633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.mediumTimeFormat != null) {
12733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            mediumTimeFormat = overrides.mediumTimeFormat;
12833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
12933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.shortTimeFormat != null) {
13033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            shortTimeFormat = overrides.shortTimeFormat;
13133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
13233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.fullDateFormat != null) {
13333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            fullDateFormat = overrides.fullDateFormat;
13433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
13533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.longDateFormat != null) {
13633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            longDateFormat = overrides.longDateFormat;
13733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
13833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.mediumDateFormat != null) {
13933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            mediumDateFormat = overrides.mediumDateFormat;
14033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
14133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.shortDateFormat != null) {
14233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            shortDateFormat = overrides.shortDateFormat;
14333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
14433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.decimalPatternChars != null) {
14533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            decimalPatternChars = overrides.decimalPatternChars;
14633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
14733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.NaN != null) {
14833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            NaN = overrides.NaN;
14933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
15033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.infinity != null) {
15133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            infinity = overrides.infinity;
15233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
15333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.currencySymbol != null) {
15433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            currencySymbol = overrides.currencySymbol;
15533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
15633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.internationalCurrencySymbol != null) {
15733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            internationalCurrencySymbol = overrides.internationalCurrencySymbol;
15833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
15933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.numberPattern != null) {
16033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            numberPattern = overrides.numberPattern;
16133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
16233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.integerPattern != null) {
16333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            integerPattern = overrides.integerPattern;
16433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
16533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.currencyPattern != null) {
16633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            currencyPattern = overrides.currencyPattern;
16733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
16833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        if (overrides.percentPattern != null) {
16933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes            percentPattern = overrides.percentPattern;
17033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes        }
17133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    }
1726ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes
1736ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes    public String getDateFormat(int style) {
1746ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        switch (style) {
1756ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.SHORT:
1766ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return shortDateFormat;
1776ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.MEDIUM:
1786ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return mediumDateFormat;
1796ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.LONG:
1806ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return longDateFormat;
1816ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.FULL:
1826ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return fullDateFormat;
1836ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        }
1846ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        throw new AssertionError();
1856ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes    }
1866ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes
1876ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes    public String getTimeFormat(int style) {
1886ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        switch (style) {
1896ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.SHORT:
1906ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return shortTimeFormat;
1916ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.MEDIUM:
1926ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return mediumTimeFormat;
1936ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.LONG:
1946ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return longTimeFormat;
1956ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.FULL:
1966ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return fullTimeFormat;
1976ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        }
1986ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        throw new AssertionError();
1996ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes    }
20033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes}
201