src/share/classes/sun/util/locale/provider/CalendarNameProviderImpl.java

Print this page

        

*** 51,69 **** @Override public String getDisplayName(String calendarType, int field, int value, int style, Locale locale) { return getDisplayNameImpl(calendarType, field, value, style, locale, false); } ! public String getCldrDisplayName(String calendarType, int field, int value, int style, Locale locale) { return getDisplayNameImpl(calendarType, field, value, style, locale, true); } ! public String getDisplayNameImpl(String calendarType, int field, int value, int style, Locale locale, boolean cldr) { String name = null; ! String key = getResourceKey(calendarType, field, style, cldr); if (key != null) { ! String[] strings = LocaleProviderAdapter.forType(type).getLocaleResources(locale).getCalendarNames(key); if (strings != null && strings.length > 0) { if (field == DAY_OF_WEEK || field == YEAR) { --value; } if (value < 0 || value >= strings.length) { --- 51,70 ---- @Override public String getDisplayName(String calendarType, int field, int value, int style, Locale locale) { return getDisplayNameImpl(calendarType, field, value, style, locale, false); } ! public String getJavaTimeDisplayName(String calendarType, int field, int value, int style, Locale locale) { return getDisplayNameImpl(calendarType, field, value, style, locale, true); } ! public String getDisplayNameImpl(String calendarType, int field, int value, int style, Locale locale, boolean javatime) { String name = null; ! String key = getResourceKey(calendarType, field, style, javatime); if (key != null) { ! LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale); ! String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key); if (strings != null && strings.length > 0) { if (field == DAY_OF_WEEK || field == YEAR) { --value; } if (value < 0 || value >= strings.length) {
*** 102,123 **** } return names.isEmpty() ? null : names; } // NOTE: This method should be used ONLY BY JSR 310 classes. ! public Map<String, Integer> getCldrDisplayNames(String calendarType, int field, int style, Locale locale) { Map<String, Integer> names; names = getDisplayNamesImpl(calendarType, field, style, locale, true); return names.isEmpty() ? null : names; } private Map<String, Integer> getDisplayNamesImpl(String calendarType, int field, ! int style, Locale locale, boolean cldr) { ! String key = getResourceKey(calendarType, field, style, cldr); Map<String, Integer> map = new TreeMap<>(LengthBasedComparator.INSTANCE); if (key != null) { ! String[] strings = LocaleProviderAdapter.forType(type).getLocaleResources(locale).getCalendarNames(key); if (strings != null) { if (!hasDuplicates(strings)) { if (field == YEAR) { if (strings.length > 0) { map.put(strings[0], 1); --- 103,125 ---- } return names.isEmpty() ? null : names; } // NOTE: This method should be used ONLY BY JSR 310 classes. ! public Map<String, Integer> getJavaTimeDisplayNames(String calendarType, int field, int style, Locale locale) { Map<String, Integer> names; names = getDisplayNamesImpl(calendarType, field, style, locale, true); return names.isEmpty() ? null : names; } private Map<String, Integer> getDisplayNamesImpl(String calendarType, int field, ! int style, Locale locale, boolean javatime) { ! String key = getResourceKey(calendarType, field, style, javatime); Map<String, Integer> map = new TreeMap<>(LengthBasedComparator.INSTANCE); if (key != null) { ! LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale); ! String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key); if (strings != null) { if (!hasDuplicates(strings)) { if (field == YEAR) { if (strings.length > 0) { map.put(strings[0], 1);
*** 218,239 **** } } return false; } ! private String getResourceKey(String type, int field, int style, boolean cldr) { int baseStyle = getBaseStyle(style); boolean isStandalone = (style != baseStyle); if ("gregory".equals(type)) { type = null; } boolean isNarrow = (baseStyle == NARROW_FORMAT); StringBuilder key = new StringBuilder(); ! // If cldr is true, use prefix "cldr.". ! if (cldr) { ! key.append("cldr."); } switch (field) { case ERA: if (type != null) { key.append(type).append('.'); --- 220,241 ---- } } return false; } ! private String getResourceKey(String type, int field, int style, boolean javatime) { int baseStyle = getBaseStyle(style); boolean isStandalone = (style != baseStyle); if ("gregory".equals(type)) { type = null; } boolean isNarrow = (baseStyle == NARROW_FORMAT); StringBuilder key = new StringBuilder(); ! // If javatime is true, use prefix "java.time.". ! if (javatime) { ! key.append("java.time."); } switch (field) { case ERA: if (type != null) { key.append(type).append('.');
*** 243,261 **** } else { // JRE and CLDR use different resource key conventions // due to historical reasons. (JRE DateFormatSymbols.getEras returns // abbreviations while other getShort*() return abbreviations.) if (this.type == LocaleProviderAdapter.Type.JRE) { ! if (cldr) { if (baseStyle == LONG) { key.append("long."); } } if (baseStyle == SHORT) { key.append("short."); } ! } else { // CLDR if (baseStyle == LONG) { key.append("long."); } } } --- 245,263 ---- } else { // JRE and CLDR use different resource key conventions // due to historical reasons. (JRE DateFormatSymbols.getEras returns // abbreviations while other getShort*() return abbreviations.) if (this.type == LocaleProviderAdapter.Type.JRE) { ! if (javatime) { if (baseStyle == LONG) { key.append("long."); } } if (baseStyle == SHORT) { key.append("short."); } ! } else { // this.type == LocaleProviderAdapter.Type.CLDR if (baseStyle == LONG) { key.append("long."); } } }