944 } |
944 } |
945 |
945 |
946 set(field, getRolledValue(internalGet(field), amount, min, max)); |
946 set(field, getRolledValue(internalGet(field), amount, min, max)); |
947 } |
947 } |
948 |
948 |
|
949 @Override |
949 public String getDisplayName(int field, int style, Locale locale) { |
950 public String getDisplayName(int field, int style, Locale locale) { |
950 if (!checkDisplayNameParams(field, style, SHORT, LONG, locale, |
951 if (!checkDisplayNameParams(field, style, SHORT, NARROW_FORMAT, locale, |
951 ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) { |
952 ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) { |
952 return null; |
953 return null; |
953 } |
954 } |
954 |
955 |
955 int fieldValue = get(field); |
956 int fieldValue = get(field); |
956 |
957 |
957 // "GanNen" is supported only in the LONG style. |
958 // "GanNen" is supported only in the LONG style. |
958 if (field == YEAR |
959 if (field == YEAR |
959 && (getBaseStyle(style) == SHORT || fieldValue != 1 || get(ERA) == 0)) { |
960 && (getBaseStyle(style) != LONG || fieldValue != 1 || get(ERA) == 0)) { |
960 return null; |
961 return null; |
961 } |
962 } |
962 |
963 |
963 String name = CalendarDataUtility.retrieveFieldValueName("japanese", field, fieldValue, style, locale); |
964 String name = CalendarDataUtility.retrieveFieldValueName(getCalendarType(), field, |
|
965 fieldValue, style, locale); |
964 // If the ERA value is null, then |
966 // If the ERA value is null, then |
965 // try to get its name or abbreviation from the Era instance. |
967 // try to get its name or abbreviation from the Era instance. |
966 if (name == null && field == ERA && fieldValue < eras.length) { |
968 if (name == null && field == ERA && fieldValue < eras.length) { |
967 Era era = eras[fieldValue]; |
969 Era era = eras[fieldValue]; |
968 name = (style == SHORT) ? era.getAbbreviation() : era.getName(); |
970 name = (style == SHORT) ? era.getAbbreviation() : era.getName(); |
969 } |
971 } |
970 return name; |
972 return name; |
971 } |
973 } |
972 |
974 |
|
975 @Override |
973 public Map<String,Integer> getDisplayNames(int field, int style, Locale locale) { |
976 public Map<String,Integer> getDisplayNames(int field, int style, Locale locale) { |
974 if (!checkDisplayNameParams(field, style, ALL_STYLES, LONG, locale, |
977 if (!checkDisplayNameParams(field, style, ALL_STYLES, NARROW_FORMAT, locale, |
975 ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) { |
978 ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) { |
976 return null; |
979 return null; |
977 } |
980 } |
978 Map<String, Integer> names = CalendarDataUtility.retrieveFieldValueNames("japanese", field, style, locale); |
981 Map<String, Integer> names; |
|
982 names = CalendarDataUtility.retrieveFieldValueNames(getCalendarType(), field, style, locale); |
979 // If strings[] has fewer than eras[], get more names from eras[]. |
983 // If strings[] has fewer than eras[], get more names from eras[]. |
980 if (field == ERA) { |
984 if (names != null) { |
981 int size = names.size(); |
985 if (field == ERA) { |
982 if (style == ALL_STYLES) { |
986 int size = names.size(); |
983 size /= 2; // SHORT and LONG |
987 if (style == ALL_STYLES) { |
984 } |
988 Set<Integer> values = new HashSet<>(); |
985 if (size < eras.length) { |
989 // count unique era values |
986 int baseStyle = getBaseStyle(style); |
990 for (String key : names.keySet()) { |
987 for (int i = size; i < eras.length; i++) { |
991 values.add(names.get(key)); |
988 Era era = eras[i]; |
992 } |
989 if (baseStyle == ALL_STYLES || baseStyle == SHORT) { |
993 size = values.size(); |
990 names.put(era.getAbbreviation(), i); |
994 } |
991 } |
995 if (size < eras.length) { |
992 if (baseStyle == ALL_STYLES || baseStyle == LONG) { |
996 int baseStyle = getBaseStyle(style); |
993 names.put(era.getName(), i); |
997 for (int i = size; i < eras.length; i++) { |
|
998 Era era = eras[i]; |
|
999 if (baseStyle == ALL_STYLES || baseStyle == SHORT |
|
1000 || baseStyle == NARROW_FORMAT) { |
|
1001 names.put(era.getAbbreviation(), i); |
|
1002 } |
|
1003 if (baseStyle == ALL_STYLES || baseStyle == LONG) { |
|
1004 names.put(era.getName(), i); |
|
1005 } |
994 } |
1006 } |
995 } |
1007 } |
996 } |
1008 } |
997 } |
1009 } |
998 return names; |
1010 return names; |