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

Print this page
rev 5696 : 6336885: RFE: Locale Data Deployment Enhancements
4609153: Provide locale data for Indic locales
5104387: Support for gl_ES locale (galician language)
6337471: desktop/system locale preferences support
7056139: (cal) SPI support for locale-dependent Calendar parameters
7058206: Provide CalendarData SPI for week params and display field value names
7073852: Support multiple scripts for digits and decimal symbols per locale
7079560: [Fmt-Da] Context dependent month names support in SimpleDateFormat
7171324: getAvailableLocales() of locale sensitive services should return the actual availability of locales
7151414: (cal) Support calendar type identification
7168528: LocaleServiceProvider needs to be aware of Locale extensions
7171372: (cal) locale's default Calendar should be created if unknown calendar is specified
Summary: JEP 127: Improve Locale Data Packaging and Adopt Unicode CLDR Data (part 1 w/o packaging changes. by Naoto Sato and Masayoshi Okutsu)

*** 1,7 **** /* ! * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 25,43 **** package java.util; import java.io.IOException; import java.io.ObjectInputStream; import sun.util.calendar.BaseCalendar; import sun.util.calendar.CalendarDate; import sun.util.calendar.CalendarSystem; import sun.util.calendar.CalendarUtils; import sun.util.calendar.Era; import sun.util.calendar.Gregorian; import sun.util.calendar.LocalGregorianCalendar; import sun.util.calendar.ZoneInfo; - import sun.util.resources.LocaleData; /** * <code>JapaneseImperialCalendar</code> implements a Japanese * calendar system in which the imperial era-based year numbering is * supported from the Meiji era. The following are the eras supported --- 25,43 ---- package java.util; import java.io.IOException; import java.io.ObjectInputStream; + import sun.util.locale.provider.CalendarDataUtility; import sun.util.calendar.BaseCalendar; import sun.util.calendar.CalendarDate; import sun.util.calendar.CalendarSystem; import sun.util.calendar.CalendarUtils; import sun.util.calendar.Era; import sun.util.calendar.Gregorian; import sun.util.calendar.LocalGregorianCalendar; import sun.util.calendar.ZoneInfo; /** * <code>JapaneseImperialCalendar</code> implements a Japanese * calendar system in which the imperial era-based year numbering is * supported from the Meiji era. The following are the eras supported
*** 300,309 **** --- 300,320 ---- jdate = jcal.newCalendarDate(zone); setTimeInMillis(System.currentTimeMillis()); } /** + * Returns {@code "japanese"} as the calendar type of this {@code + * JapaneseImperialCalendar}. + * + * @return {@code "japanese"} + */ + @Override + public String getCalendarType() { + return "japanese"; + } + + /** * Compares this <code>JapaneseImperialCalendar</code> to the specified * <code>Object</code>. The result is <code>true</code> if and * only if the argument is a <code>JapaneseImperialCalendar</code> object * that represents the same time value (millisecond offset from * the <a href="Calendar.html#Epoch">Epoch</a>) under the same
*** 939,1065 **** if (!checkDisplayNameParams(field, style, SHORT, LONG, locale, ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) { return null; } // "GanNen" is supported only in the LONG style. if (field == YEAR ! && (style == SHORT || get(YEAR) != 1 || get(ERA) == 0)) { return null; } ! ResourceBundle rb = LocaleData.getDateFormatData(locale); ! String name = null; ! String key = getKey(field, style); ! if (key != null) { ! String[] strings = rb.getStringArray(key); ! if (field == YEAR) { ! if (strings.length > 0) { ! name = strings[0]; ! } ! } else { ! int index = get(field); ! // If the ERA value is out of range for strings, then // try to get its name or abbreviation from the Era instance. ! if (field == ERA && index >= strings.length && index < eras.length) { ! Era era = eras[index]; name = (style == SHORT) ? era.getAbbreviation() : era.getName(); - } else { - if (field == DAY_OF_WEEK) { - --index; } - name = strings[index]; - } - } - } return name; } public Map<String,Integer> getDisplayNames(int field, int style, Locale locale) { if (!checkDisplayNameParams(field, style, ALL_STYLES, LONG, locale, ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) { return null; } ! if (style == ALL_STYLES) { ! Map<String,Integer> shortNames = getDisplayNamesImpl(field, SHORT, locale); ! if (field == AM_PM) { ! return shortNames; } ! Map<String,Integer> longNames = getDisplayNamesImpl(field, LONG, locale); ! if (shortNames == null) { ! return longNames; ! } ! if (longNames != null) { ! shortNames.putAll(longNames); ! } ! return shortNames; ! } ! ! // SHORT or LONG ! return getDisplayNamesImpl(field, style, locale); ! } ! ! private Map<String,Integer> getDisplayNamesImpl(int field, int style, Locale locale) { ! ResourceBundle rb = LocaleData.getDateFormatData(locale); ! String key = getKey(field, style); ! Map<String,Integer> map = new HashMap<>(); ! if (key != null) { ! String[] strings = rb.getStringArray(key); ! if (field == YEAR) { ! if (strings.length > 0) { ! map.put(strings[0], 1); ! } ! } else { ! int base = (field == DAY_OF_WEEK) ? 1 : 0; ! for (int i = 0; i < strings.length; i++) { ! map.put(strings[i], base + i); ! } ! // If strings[] has fewer than eras[], get more names from eras[]. ! if (field == ERA && strings.length < eras.length) { ! for (int i = strings.length; i < eras.length; i++) { Era era = eras[i]; ! String name = (style == SHORT) ? era.getAbbreviation() : era.getName(); ! map.put(name, i); } } } } - return map.size() > 0 ? map : null; } ! ! private String getKey(int field, int style) { ! String className = JapaneseImperialCalendar.class.getName(); ! StringBuilder key = new StringBuilder(); ! switch (field) { ! case ERA: ! key.append(className); ! if (style == SHORT) { ! key.append(".short"); } - key.append(".Eras"); - break; - case YEAR: - key.append(className).append(".FirstYear"); - break; - - case MONTH: - key.append(style == SHORT ? "MonthAbbreviations" : "MonthNames"); - break; - - case DAY_OF_WEEK: - key.append(style == SHORT ? "DayAbbreviations" : "DayNames"); - break; - - case AM_PM: - key.append("AmPmMarkers"); - break; - } - return key.length() > 0 ? key.toString() : null; - } - /** * Returns the minimum value for the given calendar field of this * <code>Calendar</code> instance. The minimum value is * defined as the smallest value returned by the {@link * Calendar#get(int) get} method for any possible time value, --- 950,1005 ---- if (!checkDisplayNameParams(field, style, SHORT, LONG, 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)) { return null; } ! String name = CalendarDataUtility.retrieveFieldValueName("japanese", 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; } public Map<String,Integer> getDisplayNames(int field, int style, Locale locale) { if (!checkDisplayNameParams(field, style, ALL_STYLES, LONG, 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); ! // If strings[] has fewer than eras[], get more names from eras[]. ! if (field == ERA) { ! int size = names.size(); if (style == ALL_STYLES) { ! size /= 2; // SHORT and LONG } ! 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) { ! 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 * <code>Calendar</code> instance. The minimum value is * defined as the smallest value returned by the {@link * Calendar#get(int) get} method for any possible time value,