src/share/classes/java/util/JapaneseImperialCalendar.java

Print this page

        

@@ -944,59 +944,71 @@
         }
 
         set(field, getRolledValue(internalGet(field), amount, min, max));
     }
 
+    @Override
     public String getDisplayName(int field, int style, Locale locale) {
-        if (!checkDisplayNameParams(field, style, SHORT, LONG, locale,
+        if (!checkDisplayNameParams(field, style, SHORT, NARROW_FORMAT, locale,
                                     ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
             return null;
         }
 
         int fieldValue = get(field);
 
         // "GanNen" is supported only in the LONG style.
         if (field == YEAR
-            && (getBaseStyle(style) == SHORT || fieldValue != 1 || get(ERA) == 0)) {
+            && (getBaseStyle(style) != LONG || fieldValue != 1 || get(ERA) == 0)) {
             return null;
         }
 
-        String name = CalendarDataUtility.retrieveFieldValueName("japanese", field, fieldValue, style, locale);
+        String name = CalendarDataUtility.retrieveFieldValueName(getCalendarType(), field,
+                                                                 fieldValue, style, locale);
         // If the ERA value is null, then
         // try to get its name or abbreviation from the Era instance.
         if (name == null && field == ERA && fieldValue < eras.length) {
             Era era = eras[fieldValue];
             name = (style == SHORT) ? era.getAbbreviation() : era.getName();
         }
         return name;
     }
 
+    @Override
     public Map<String,Integer> getDisplayNames(int field, int style, Locale locale) {
-        if (!checkDisplayNameParams(field, style, ALL_STYLES, LONG, locale,
+        if (!checkDisplayNameParams(field, style, ALL_STYLES, NARROW_FORMAT, locale,
                                     ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
             return null;
         }
-        Map<String, Integer> names = CalendarDataUtility.retrieveFieldValueNames("japanese", field, style, locale);
+        Map<String, Integer> names;
+        names = CalendarDataUtility.retrieveFieldValueNames(getCalendarType(), field, style, locale);
         // If strings[] has fewer than eras[], get more names from eras[].
+        if (names != null) {
         if (field == ERA) {
             int size = names.size();
             if (style == ALL_STYLES) {
-                size /= 2; // SHORT and LONG
+                    Set<Integer> values = new HashSet<>();
+                    // count unique era values
+                    for (String key : names.keySet()) {
+                        values.add(names.get(key));
+                    }
+                    size = values.size();
             }
             if (size < eras.length) {
                 int baseStyle = getBaseStyle(style);
                 for (int i = size; i < eras.length; i++) {
                     Era era = eras[i];
-                    if (baseStyle == ALL_STYLES || baseStyle == SHORT) {
+                        if (baseStyle == ALL_STYLES || baseStyle == SHORT
+                                || baseStyle == NARROW_FORMAT) {
                         names.put(era.getAbbreviation(), i);
                     }
                     if (baseStyle == ALL_STYLES || baseStyle == LONG) {
                         names.put(era.getName(), i);
                     }
                 }
             }
         }
+        }
         return names;
     }
 
     /**
      * Returns the minimum value for the given calendar field of this