100 Era supEra = jeras[value - 1]; // 0-based index
101 if (javatime) {
102 return getBaseStyle(style) == NARROW_FORMAT ?
103 supEra.getAbbreviation() :
104 supEra.getName();
105 } else {
106 return (style & LONG) != 0 ?
107 supEra.getName() :
108 supEra.getAbbreviation();
109 }
110 }
111 } else {
112 return null;
113 }
114 } else {
115 return null;
116 }
117 }
118 name = strings[value];
119 // If name is empty in standalone, try its `format' style.
120 if (name.length() == 0
121 && (style == SHORT_STANDALONE || style == LONG_STANDALONE
122 || style == NARROW_STANDALONE)) {
123 name = getDisplayName(calendarType, field, value,
124 getBaseStyle(style),
125 locale);
126 }
127 }
128 }
129 return name;
130 }
131
132 private static int[] REST_OF_STYLES = {
133 SHORT_STANDALONE, LONG_FORMAT, LONG_STANDALONE,
134 NARROW_FORMAT, NARROW_STANDALONE
135 };
136
137 @Override
138 public Map<String, Integer> getDisplayNames(String calendarType, int field, int style, Locale locale) {
139 Map<String, Integer> names;
140 if (style == ALL_STYLES) {
166
167 // If standalone names are requested and no "standalone." resources are found,
168 // try the default ones instead.
169 if (strings == null && key.indexOf("standalone.") != -1) {
170 key = key.replaceFirst("standalone.", "");
171 strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
172 }
173
174 if (strings != null) {
175 if (!hasDuplicates(strings)) {
176 if (field == YEAR) {
177 if (strings.length > 0) {
178 map.put(strings[0], 1);
179 }
180 } else {
181 int base = (field == DAY_OF_WEEK) ? 1 : 0;
182 for (int i = 0; i < strings.length; i++) {
183 String name = strings[i];
184 // Ignore any empty string (some standalone month names
185 // are not defined)
186 if (name.length() == 0) {
187 continue;
188 }
189 map.put(name, base + i);
190 }
191 }
192 }
193 }
194 }
195 return map;
196 }
197
198 private static int getBaseStyle(int style) {
199 return style & ~(SHORT_STANDALONE - SHORT_FORMAT);
200 }
201
202 /**
203 * Comparator implementation for TreeMap which iterates keys from longest
204 * to shortest.
205 */
206 private static class LengthBasedComparator implements Comparator<String> {
|
100 Era supEra = jeras[value - 1]; // 0-based index
101 if (javatime) {
102 return getBaseStyle(style) == NARROW_FORMAT ?
103 supEra.getAbbreviation() :
104 supEra.getName();
105 } else {
106 return (style & LONG) != 0 ?
107 supEra.getName() :
108 supEra.getAbbreviation();
109 }
110 }
111 } else {
112 return null;
113 }
114 } else {
115 return null;
116 }
117 }
118 name = strings[value];
119 // If name is empty in standalone, try its `format' style.
120 if (name.isEmpty()
121 && (style == SHORT_STANDALONE || style == LONG_STANDALONE
122 || style == NARROW_STANDALONE)) {
123 name = getDisplayName(calendarType, field, value,
124 getBaseStyle(style),
125 locale);
126 }
127 }
128 }
129 return name;
130 }
131
132 private static int[] REST_OF_STYLES = {
133 SHORT_STANDALONE, LONG_FORMAT, LONG_STANDALONE,
134 NARROW_FORMAT, NARROW_STANDALONE
135 };
136
137 @Override
138 public Map<String, Integer> getDisplayNames(String calendarType, int field, int style, Locale locale) {
139 Map<String, Integer> names;
140 if (style == ALL_STYLES) {
166
167 // If standalone names are requested and no "standalone." resources are found,
168 // try the default ones instead.
169 if (strings == null && key.indexOf("standalone.") != -1) {
170 key = key.replaceFirst("standalone.", "");
171 strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
172 }
173
174 if (strings != null) {
175 if (!hasDuplicates(strings)) {
176 if (field == YEAR) {
177 if (strings.length > 0) {
178 map.put(strings[0], 1);
179 }
180 } else {
181 int base = (field == DAY_OF_WEEK) ? 1 : 0;
182 for (int i = 0; i < strings.length; i++) {
183 String name = strings[i];
184 // Ignore any empty string (some standalone month names
185 // are not defined)
186 if (name.isEmpty()) {
187 continue;
188 }
189 map.put(name, base + i);
190 }
191 }
192 }
193 }
194 }
195 return map;
196 }
197
198 private static int getBaseStyle(int style) {
199 return style & ~(SHORT_STANDALONE - SHORT_FORMAT);
200 }
201
202 /**
203 * Comparator implementation for TreeMap which iterates keys from longest
204 * to shortest.
205 */
206 private static class LengthBasedComparator implements Comparator<String> {
|