59 return getDisplayNameImpl(calendarType, field, value, style, locale, true); 60 } 61 62 public String getDisplayNameImpl(String calendarType, int field, int value, int style, Locale locale, boolean javatime) { 63 String name = null; 64 String key = getResourceKey(calendarType, field, style, javatime); 65 if (key != null) { 66 LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale); 67 String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key); 68 if (strings != null && strings.length > 0) { 69 if (field == DAY_OF_WEEK || field == YEAR) { 70 --value; 71 } 72 if (value < 0) { 73 return null; 74 } else if (value >= strings.length) { 75 if (field == ERA && "japanese".equals(calendarType)) { 76 Era[] jeras = CalendarSystem.forName("japanese").getEras(); 77 if (value <= jeras.length) { 78 // Localized era name could not be retrieved from this provider. 79 // This can occur either for NewEra or SupEra. 80 // 81 // If it's CLDR provider, try COMPAT first, which is guaranteed to have 82 // the name for NewEra. 83 if (type == LocaleProviderAdapter.Type.CLDR) { 84 lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale); 85 key = getResourceKeyFor(LocaleProviderAdapter.Type.JRE, 86 calendarType, field, style, javatime); 87 strings = 88 javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key); 89 } 90 if (strings == null || value >= strings.length) { 91 // Get the default name for SupEra 92 Era supEra = jeras[value - 1]; // 0-based index 93 if (javatime) { 94 return getBaseStyle(style) == NARROW_FORMAT ? 95 supEra.getAbbreviation() : 96 supEra.getName(); 97 } else { 98 return (style & LONG) != 0 ? 99 supEra.getName() : 100 supEra.getAbbreviation(); 101 } 102 } | 59 return getDisplayNameImpl(calendarType, field, value, style, locale, true); 60 } 61 62 public String getDisplayNameImpl(String calendarType, int field, int value, int style, Locale locale, boolean javatime) { 63 String name = null; 64 String key = getResourceKey(calendarType, field, style, javatime); 65 if (key != null) { 66 LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale); 67 String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key); 68 if (strings != null && strings.length > 0) { 69 if (field == DAY_OF_WEEK || field == YEAR) { 70 --value; 71 } 72 if (value < 0) { 73 return null; 74 } else if (value >= strings.length) { 75 if (field == ERA && "japanese".equals(calendarType)) { 76 Era[] jeras = CalendarSystem.forName("japanese").getEras(); 77 if (value <= jeras.length) { 78 // Localized era name could not be retrieved from this provider. 79 // This can occur either for Reiwa or SupEra. 80 // 81 // If it's CLDR provider, try COMPAT first, which is guaranteed to have 82 // the name for Reiwa. 83 if (type == LocaleProviderAdapter.Type.CLDR) { 84 lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale); 85 key = getResourceKeyFor(LocaleProviderAdapter.Type.JRE, 86 calendarType, field, style, javatime); 87 strings = 88 javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key); 89 } 90 if (strings == null || value >= strings.length) { 91 // Get the default name for SupEra 92 Era supEra = jeras[value - 1]; // 0-based index 93 if (javatime) { 94 return getBaseStyle(style) == NARROW_FORMAT ? 95 supEra.getAbbreviation() : 96 supEra.getName(); 97 } else { 98 return (style & LONG) != 0 ? 99 supEra.getName() : 100 supEra.getAbbreviation(); 101 } 102 } |