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)

Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/util/JapaneseImperialCalendar.java
          +++ new/src/share/classes/java/util/JapaneseImperialCalendar.java
   1    1  /*
   2      - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
        2 + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
   3    3   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4    4   *
   5    5   * This code is free software; you can redistribute it and/or modify it
   6    6   * under the terms of the GNU General Public License version 2 only, as
   7    7   * published by the Free Software Foundation.  Oracle designates this
   8    8   * particular file as subject to the "Classpath" exception as provided
   9    9   * by Oracle in the LICENSE file that accompanied this code.
  10   10   *
  11   11   * This code is distributed in the hope that it will be useful, but WITHOUT
  12   12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
↓ open down ↓ 7 lines elided ↑ open up ↑
  20   20   *
  21   21   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22   22   * or visit www.oracle.com if you need additional information or have any
  23   23   * questions.
  24   24   */
  25   25  
  26   26  package java.util;
  27   27  
  28   28  import java.io.IOException;
  29   29  import java.io.ObjectInputStream;
       30 +import sun.util.locale.provider.CalendarDataUtility;
  30   31  import sun.util.calendar.BaseCalendar;
  31   32  import sun.util.calendar.CalendarDate;
  32   33  import sun.util.calendar.CalendarSystem;
  33   34  import sun.util.calendar.CalendarUtils;
  34   35  import sun.util.calendar.Era;
  35   36  import sun.util.calendar.Gregorian;
  36   37  import sun.util.calendar.LocalGregorianCalendar;
  37   38  import sun.util.calendar.ZoneInfo;
  38      -import sun.util.resources.LocaleData;
  39   39  
  40   40  /**
  41   41   * <code>JapaneseImperialCalendar</code> implements a Japanese
  42   42   * calendar system in which the imperial era-based year numbering is
  43   43   * supported from the Meiji era. The following are the eras supported
  44   44   * by this calendar system.
  45   45   * <pre><tt>
  46   46   * ERA value   Era name    Since (in Gregorian)
  47   47   * ------------------------------------------------------
  48   48   *     0       N/A         N/A
↓ open down ↓ 246 lines elided ↑ open up ↑
 295  295       * @param zone the given time zone.
 296  296       * @param aLocale the given locale.
 297  297       */
 298  298      JapaneseImperialCalendar(TimeZone zone, Locale aLocale) {
 299  299          super(zone, aLocale);
 300  300          jdate = jcal.newCalendarDate(zone);
 301  301          setTimeInMillis(System.currentTimeMillis());
 302  302      }
 303  303  
 304  304      /**
      305 +     * Returns {@code "japanese"} as the calendar type of this {@code
      306 +     * JapaneseImperialCalendar}.
      307 +     *
      308 +     * @return {@code "japanese"}
      309 +     */
      310 +    @Override
      311 +    public String getCalendarType() {
      312 +        return "japanese";
      313 +    }
      314 +
      315 +    /**
 305  316       * Compares this <code>JapaneseImperialCalendar</code> to the specified
 306  317       * <code>Object</code>. The result is <code>true</code> if and
 307  318       * only if the argument is a <code>JapaneseImperialCalendar</code> object
 308  319       * that represents the same time value (millisecond offset from
 309  320       * the <a href="Calendar.html#Epoch">Epoch</a>) under the same
 310  321       * <code>Calendar</code> parameters.
 311  322       *
 312  323       * @param obj the object to compare with.
 313  324       * @return <code>true</code> if this object is equal to <code>obj</code>;
 314  325       * <code>false</code> otherwise.
↓ open down ↓ 619 lines elided ↑ open up ↑
 934  945  
 935  946          set(field, getRolledValue(internalGet(field), amount, min, max));
 936  947      }
 937  948  
 938  949      public String getDisplayName(int field, int style, Locale locale) {
 939  950          if (!checkDisplayNameParams(field, style, SHORT, LONG, locale,
 940  951                                      ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
 941  952              return null;
 942  953          }
 943  954  
      955 +        int fieldValue = get(field);
      956 +
 944  957          // "GanNen" is supported only in the LONG style.
 945  958          if (field == YEAR
 946      -            && (style == SHORT || get(YEAR) != 1 || get(ERA) == 0)) {
      959 +            && (getBaseStyle(style) == SHORT || fieldValue != 1 || get(ERA) == 0)) {
 947  960              return null;
 948  961          }
 949  962  
 950      -        ResourceBundle rb = LocaleData.getDateFormatData(locale);
 951      -        String name = null;
 952      -        String key = getKey(field, style);
 953      -        if (key != null) {
 954      -            String[] strings = rb.getStringArray(key);
 955      -            if (field == YEAR) {
 956      -                if (strings.length > 0) {
 957      -                    name = strings[0];
 958      -                }
 959      -            } else {
 960      -                int index = get(field);
 961      -                // If the ERA value is out of range for strings, then
 962      -                // try to get its name or abbreviation from the Era instance.
 963      -                if (field == ERA && index >= strings.length && index < eras.length) {
 964      -                    Era era = eras[index];
 965      -                    name = (style == SHORT) ? era.getAbbreviation() : era.getName();
 966      -                } else {
 967      -                    if (field == DAY_OF_WEEK) {
 968      -                        --index;
 969      -                    }
 970      -                    name = strings[index];
 971      -                }
 972      -            }
      963 +        String name = CalendarDataUtility.retrieveFieldValueName("japanese", field, fieldValue, style, locale);
      964 +        // If the ERA value is null, then
      965 +        // try to get its name or abbreviation from the Era instance.
      966 +        if (name == null && field == ERA && fieldValue < eras.length) {
      967 +            Era era = eras[fieldValue];
      968 +            name = (style == SHORT) ? era.getAbbreviation() : era.getName();
 973  969          }
 974  970          return name;
 975  971      }
 976  972  
 977  973      public Map<String,Integer> getDisplayNames(int field, int style, Locale locale) {
 978  974          if (!checkDisplayNameParams(field, style, ALL_STYLES, LONG, locale,
 979  975                                      ERA_MASK|YEAR_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
 980  976              return null;
 981  977          }
 982      -
 983      -        if (style == ALL_STYLES) {
 984      -            Map<String,Integer> shortNames = getDisplayNamesImpl(field, SHORT, locale);
 985      -            if (field == AM_PM) {
 986      -                return shortNames;
      978 +        Map<String, Integer> names = CalendarDataUtility.retrieveFieldValueNames("japanese", field, style, locale);
      979 +        // If strings[] has fewer than eras[], get more names from eras[].
      980 +        if (field == ERA) {
      981 +            int size = names.size();
      982 +            if (style == ALL_STYLES) {
      983 +                size /= 2; // SHORT and LONG
 987  984              }
 988      -            Map<String,Integer> longNames = getDisplayNamesImpl(field, LONG, locale);
 989      -            if (shortNames == null) {
 990      -                return longNames;
 991      -            }
 992      -            if (longNames != null) {
 993      -                shortNames.putAll(longNames);
 994      -            }
 995      -            return shortNames;
 996      -        }
 997      -
 998      -        // SHORT or LONG
 999      -        return getDisplayNamesImpl(field, style, locale);
1000      -    }
1001      -
1002      -    private Map<String,Integer> getDisplayNamesImpl(int field, int style, Locale locale) {
1003      -        ResourceBundle rb = LocaleData.getDateFormatData(locale);
1004      -        String key = getKey(field, style);
1005      -        Map<String,Integer> map = new HashMap<>();
1006      -        if (key != null) {
1007      -            String[] strings = rb.getStringArray(key);
1008      -            if (field == YEAR) {
1009      -                if (strings.length > 0) {
1010      -                    map.put(strings[0], 1);
1011      -                }
1012      -            } else {
1013      -                int base = (field == DAY_OF_WEEK) ? 1 : 0;
1014      -                for (int i = 0; i < strings.length; i++) {
1015      -                    map.put(strings[i], base + i);
1016      -                }
1017      -                // If strings[] has fewer than eras[], get more names from eras[].
1018      -                if (field == ERA && strings.length < eras.length) {
1019      -                    for (int i = strings.length; i < eras.length; i++) {
1020      -                        Era era = eras[i];
1021      -                        String name = (style == SHORT) ? era.getAbbreviation() : era.getName();
1022      -                        map.put(name, i);
      985 +            if (size < eras.length) {
      986 +                int baseStyle = getBaseStyle(style);
      987 +                for (int i = size; i < eras.length; i++) {
      988 +                    Era era = eras[i];
      989 +                    if (baseStyle == ALL_STYLES || baseStyle == SHORT) {
      990 +                        names.put(era.getAbbreviation(), i);
1023  991                      }
      992 +                    if (baseStyle == ALL_STYLES || baseStyle == LONG) {
      993 +                        names.put(era.getName(), i);
      994 +                    }
1024  995                  }
1025  996              }
1026  997          }
1027      -        return map.size() > 0 ? map : null;
      998 +        return names;
1028  999      }
1029 1000  
1030      -    private String getKey(int field, int style) {
1031      -        String className = JapaneseImperialCalendar.class.getName();
1032      -        StringBuilder key = new StringBuilder();
1033      -        switch (field) {
1034      -        case ERA:
1035      -            key.append(className);
1036      -            if (style == SHORT) {
1037      -                key.append(".short");
1038      -            }
1039      -            key.append(".Eras");
1040      -            break;
1041      -
1042      -        case YEAR:
1043      -            key.append(className).append(".FirstYear");
1044      -            break;
1045      -
1046      -        case MONTH:
1047      -            key.append(style == SHORT ? "MonthAbbreviations" : "MonthNames");
1048      -            break;
1049      -
1050      -        case DAY_OF_WEEK:
1051      -            key.append(style == SHORT ? "DayAbbreviations" : "DayNames");
1052      -            break;
1053      -
1054      -        case AM_PM:
1055      -            key.append("AmPmMarkers");
1056      -            break;
1057      -        }
1058      -        return key.length() > 0 ? key.toString() : null;
1059      -    }
1060      -
1061 1001      /**
1062 1002       * Returns the minimum value for the given calendar field of this
1063 1003       * <code>Calendar</code> instance. The minimum value is
1064 1004       * defined as the smallest value returned by the {@link
1065 1005       * Calendar#get(int) get} method for any possible time value,
1066 1006       * taking into consideration the current values of the
1067 1007       * {@link Calendar#getFirstDayOfWeek() getFirstDayOfWeek},
1068 1008       * {@link Calendar#getMinimalDaysInFirstWeek() getMinimalDaysInFirstWeek},
1069 1009       * and {@link Calendar#getTimeZone() getTimeZone} methods.
1070 1010       *
↓ open down ↓ 1317 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX