1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.ibm.icu4jni.util;
18
19import java.text.DateFormat;
20
21/**
22 * Passes locale-specific from ICU native code to Java.
23 * <p>
24 * Note that you share these; you must not alter any of the fields, nor their array elements
25 * in the case of arrays. If you ever expose any of these things to user code, you must give
26 * them a clone rather than the original.
27 */
28public class LocaleData {
29    public Integer firstDayOfWeek;
30    public Integer minimalDaysInFirstWeek;
31
32    public String[] amPm;
33
34    public String[] eras;
35
36    public String[] longMonthNames;
37    public String[] shortMonthNames;
38
39    public String[] longWeekdayNames;
40    public String[] shortWeekdayNames;
41
42    public String fullTimeFormat;
43    public String longTimeFormat;
44    public String mediumTimeFormat;
45    public String shortTimeFormat;
46
47    public String fullDateFormat;
48    public String longDateFormat;
49    public String mediumDateFormat;
50    public String shortDateFormat;
51
52    public String decimalPatternChars;
53
54    public String infinity;
55    public String NaN;
56
57    public String currencySymbol;
58    public String internationalCurrencySymbol;
59
60    public String numberPattern;
61    public String integerPattern;
62    public String currencyPattern;
63    public String percentPattern;
64
65    @Override public String toString() {
66        return "LocaleData[" +
67                "firstDayOfWeek=" + firstDayOfWeek + "," +
68                "minimalDaysInFirstWeek=" + minimalDaysInFirstWeek + "," +
69                "amPm=" + amPm + "," +
70                "eras=" + eras + "," +
71                "longMonthNames=" + longMonthNames + "," +
72                "shortMonthNames=" + shortMonthNames + "," +
73                "longWeekdayNames=" + longWeekdayNames + "," +
74                "shortWeekdayNames=" + shortWeekdayNames + "," +
75                "fullTimeFormat=" + fullTimeFormat + "," +
76                "longTimeFormat=" + longTimeFormat + "," +
77                "mediumTimeFormat=" + mediumTimeFormat + "," +
78                "shortTimeFormat=" + shortTimeFormat + "," +
79                "fullDateFormat=" + fullDateFormat + "," +
80                "longDateFormat=" + longDateFormat + "," +
81                "mediumDateFormat=" + mediumDateFormat + "," +
82                "shortDateFormat=" + shortDateFormat + "," +
83                "decimalPatternChars=" + decimalPatternChars + "," +
84                "infinity=" + infinity + "," +
85                "NaN=" + NaN + "," +
86                "currencySymbol=" + currencySymbol + "," +
87                "internationalCurrencySymbol=" + internationalCurrencySymbol + "," +
88                "numberPattern=" + numberPattern + "," +
89                "integerPattern=" + integerPattern + "," +
90                "currencyPattern=" + currencyPattern + "," +
91                "percentPattern=" + percentPattern + "]";
92    }
93
94    public void overrideWithDataFrom(LocaleData overrides) {
95        if (overrides.firstDayOfWeek != null) {
96            firstDayOfWeek = overrides.firstDayOfWeek;
97        }
98        if (overrides.minimalDaysInFirstWeek != null) {
99            minimalDaysInFirstWeek = overrides.minimalDaysInFirstWeek;
100        }
101        if (overrides.amPm != null) {
102            amPm = overrides.amPm;
103        }
104        if (overrides.eras != null) {
105            eras = overrides.eras;
106        }
107        if (overrides.longMonthNames != null) {
108            longMonthNames = overrides.longMonthNames;
109        }
110        if (overrides.shortMonthNames != null) {
111            shortMonthNames = overrides.shortMonthNames;
112        }
113        if (overrides.longWeekdayNames != null) {
114            longWeekdayNames = overrides.longWeekdayNames;
115        }
116        if (overrides.shortWeekdayNames != null) {
117            shortWeekdayNames = overrides.shortWeekdayNames;
118        }
119        if (overrides.fullTimeFormat != null) {
120            fullTimeFormat = overrides.fullTimeFormat;
121        }
122        if (overrides.longTimeFormat != null) {
123            longTimeFormat = overrides.longTimeFormat;
124        }
125        if (overrides.mediumTimeFormat != null) {
126            mediumTimeFormat = overrides.mediumTimeFormat;
127        }
128        if (overrides.shortTimeFormat != null) {
129            shortTimeFormat = overrides.shortTimeFormat;
130        }
131        if (overrides.fullDateFormat != null) {
132            fullDateFormat = overrides.fullDateFormat;
133        }
134        if (overrides.longDateFormat != null) {
135            longDateFormat = overrides.longDateFormat;
136        }
137        if (overrides.mediumDateFormat != null) {
138            mediumDateFormat = overrides.mediumDateFormat;
139        }
140        if (overrides.shortDateFormat != null) {
141            shortDateFormat = overrides.shortDateFormat;
142        }
143        if (overrides.decimalPatternChars != null) {
144            decimalPatternChars = overrides.decimalPatternChars;
145        }
146        if (overrides.NaN != null) {
147            NaN = overrides.NaN;
148        }
149        if (overrides.infinity != null) {
150            infinity = overrides.infinity;
151        }
152        if (overrides.currencySymbol != null) {
153            currencySymbol = overrides.currencySymbol;
154        }
155        if (overrides.internationalCurrencySymbol != null) {
156            internationalCurrencySymbol = overrides.internationalCurrencySymbol;
157        }
158        if (overrides.numberPattern != null) {
159            numberPattern = overrides.numberPattern;
160        }
161        if (overrides.integerPattern != null) {
162            integerPattern = overrides.integerPattern;
163        }
164        if (overrides.currencyPattern != null) {
165            currencyPattern = overrides.currencyPattern;
166        }
167        if (overrides.percentPattern != null) {
168            percentPattern = overrides.percentPattern;
169        }
170    }
171
172    public String getDateFormat(int style) {
173        switch (style) {
174        case DateFormat.SHORT:
175            return shortDateFormat;
176        case DateFormat.MEDIUM:
177            return mediumDateFormat;
178        case DateFormat.LONG:
179            return longDateFormat;
180        case DateFormat.FULL:
181            return fullDateFormat;
182        }
183        throw new AssertionError();
184    }
185
186    public String getTimeFormat(int style) {
187        switch (style) {
188        case DateFormat.SHORT:
189            return shortTimeFormat;
190        case DateFormat.MEDIUM:
191            return mediumTimeFormat;
192        case DateFormat.LONG:
193            return longTimeFormat;
194        case DateFormat.FULL:
195            return fullTimeFormat;
196        }
197        throw new AssertionError();
198    }
199}
200