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/sun/util/BuddhistCalendar.java
          +++ new/src/share/classes/sun/util/BuddhistCalendar.java
   1    1  /*
   2      - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
        2 + * Copyright (c) 2000, 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 sun.util;
  27   27  
  28   28  import java.io.IOException;
  29   29  import java.io.ObjectInputStream;
  30      -import java.util.Calendar;
  31   30  import java.util.GregorianCalendar;
  32      -import java.util.HashMap;
  33   31  import java.util.Locale;
  34   32  import java.util.Map;
  35      -import java.util.ResourceBundle;
  36   33  import java.util.TimeZone;
  37      -import sun.util.resources.LocaleData;
       34 +import sun.util.locale.provider.CalendarDataUtility;
  38   35  
  39   36  public class BuddhistCalendar extends GregorianCalendar {
  40   37  
  41   38  //////////////////
  42   39  // Class Variables
  43   40  //////////////////
  44   41  
  45   42      private static final long serialVersionUID = -8527488697350388578L;
  46   43  
  47   44      private static final int BUDDHIST_YEAR_OFFSET = 543;
↓ open down ↓ 36 lines elided ↑ open up ↑
  84   81       */
  85   82      public BuddhistCalendar(TimeZone zone, Locale aLocale) {
  86   83          super(zone, aLocale);
  87   84      }
  88   85  
  89   86  /////////////////
  90   87  // Public methods
  91   88  /////////////////
  92   89  
  93   90      /**
       91 +     * Returns {@code "buddhist"} as the calendar type of this Calendar.
       92 +     */
       93 +    @Override
       94 +    public String getCalendarType() {
       95 +        return "buddhist";
       96 +    }
       97 +
       98 +    /**
  94   99       * Compares this BuddhistCalendar to an object reference.
  95  100       * @param obj the object reference with which to compare
  96  101       * @return true if this object is equal to <code>obj</code>; false otherwise
  97  102       */
      103 +    @Override
  98  104      public boolean equals(Object obj) {
  99  105          return obj instanceof BuddhistCalendar
 100  106              && super.equals(obj);
 101  107      }
 102  108  
 103  109      /**
 104  110       * Override hashCode.
 105  111       * Generates the hash code for the BuddhistCalendar object
 106  112       */
      113 +    @Override
 107  114      public int hashCode() {
 108  115          return super.hashCode() ^ BUDDHIST_YEAR_OFFSET;
 109  116      }
 110  117  
 111  118      /**
 112  119       * Gets the value for a given time field.
 113  120       * @param field the given time field.
 114  121       * @return the value for the given time field.
 115  122       */
      123 +    @Override
 116  124      public int get(int field)
 117  125      {
 118  126          if (field == YEAR) {
 119  127              return super.get(field) + yearOffset;
 120  128          }
 121  129          return super.get(field);
 122  130      }
 123  131  
 124  132      /**
 125  133       * Sets the time field with the given value.
 126  134       * @param field the given time field.
 127  135       * @param value the value to be set for the given time field.
 128  136       */
      137 +    @Override
 129  138      public void set(int field, int value)
 130  139      {
 131  140          if (field == YEAR) {
 132  141              super.set(field, value - yearOffset);
 133  142          } else {
 134  143              super.set(field, value);
 135  144          }
 136  145      }
 137  146  
 138  147      /**
 139  148       * Adds the specified (signed) amount of time to the given time field.
 140  149       * @param field the time field.
 141  150       * @param amount the amount of date or time to be added to the field.
 142  151       */
      152 +    @Override
 143  153      public void add(int field, int amount)
 144  154      {
 145  155          int savedYearOffset = yearOffset;
 146  156          // To let the superclass calculate date-time values correctly,
 147  157          // temporarily make this GregorianCalendar.
 148  158          yearOffset = 0;
 149  159          try {
 150  160              super.add(field, amount);
 151  161          } finally {
 152  162              yearOffset = savedYearOffset;
 153  163          }
 154  164      }
 155  165  
 156  166      /**
 157  167       * Add to field a signed amount without changing larger fields.
 158  168       * A negative roll amount means to subtract from field without changing
 159  169       * larger fields.
 160  170       * @param field the time field.
 161  171       * @param amount the signed amount to add to <code>field</code>.
 162  172       */
      173 +    @Override
 163  174      public void roll(int field, int amount)
 164  175      {
 165  176          int savedYearOffset = yearOffset;
 166  177          // To let the superclass calculate date-time values correctly,
 167  178          // temporarily make this GregorianCalendar.
 168  179          yearOffset = 0;
 169  180          try {
 170  181              super.roll(field, amount);
 171  182          } finally {
 172  183              yearOffset = savedYearOffset;
 173  184          }
 174  185      }
 175  186  
      187 +    @Override
 176  188      public String getDisplayName(int field, int style, Locale locale) {
 177  189          if (field != ERA) {
 178  190              return super.getDisplayName(field, style, locale);
 179  191          }
 180  192  
 181      -        // Handle Thai BuddhistCalendar specific era names
 182      -        if (field < 0 || field >= fields.length ||
 183      -            style < SHORT || style > LONG) {
 184      -            throw new IllegalArgumentException();
 185      -        }
 186      -        if (locale == null) {
 187      -            throw new NullPointerException();
 188      -        }
 189      -        ResourceBundle rb = LocaleData.getDateFormatData(locale);
 190      -        String[] eras = rb.getStringArray(getKey(style));
 191      -        return eras[get(field)];
      193 +        return CalendarDataUtility.retrieveFieldValueName("buddhist", field, get(field), style, locale);
 192  194      }
 193  195  
      196 +    @Override
 194  197      public Map<String,Integer> getDisplayNames(int field, int style, Locale locale) {
 195  198          if (field != ERA) {
 196  199              return super.getDisplayNames(field, style, locale);
 197  200          }
 198      -
 199      -        // Handle Thai BuddhistCalendar specific era names
 200      -        if (field < 0 || field >= fields.length ||
 201      -            style < ALL_STYLES || style > LONG) {
 202      -            throw new IllegalArgumentException();
 203      -        }
 204      -        if (locale == null) {
 205      -            throw new NullPointerException();
 206      -        }
 207      -        // ALL_STYLES
 208      -        if (style == ALL_STYLES) {
 209      -            Map<String,Integer> shortNames = getDisplayNamesImpl(field, SHORT, locale);
 210      -            Map<String,Integer> longNames = getDisplayNamesImpl(field, LONG, locale);
 211      -            if (shortNames == null) {
 212      -                return longNames;
 213      -            }
 214      -            if (longNames != null) {
 215      -                shortNames.putAll(longNames);
 216      -            }
 217      -            return shortNames;
 218      -        }
 219      -
 220      -        // SHORT or LONG
 221      -        return getDisplayNamesImpl(field, style, locale);
      201 +        return CalendarDataUtility.retrieveFieldValueNames("buddhist", field, style, locale);
 222  202      }
 223  203  
 224      -    private Map<String,Integer> getDisplayNamesImpl(int field, int style, Locale locale) {
 225      -        ResourceBundle rb = LocaleData.getDateFormatData(locale);
 226      -        String[] eras = rb.getStringArray(getKey(style));
 227      -        Map<String,Integer> map = new HashMap<String,Integer>(4);
 228      -        for (int i = 0; i < eras.length; i++) {
 229      -            map.put(eras[i], i);
 230      -        }
 231      -        return map;
 232      -    }
 233      -
 234      -    private String getKey(int style) {
 235      -        StringBuilder key = new StringBuilder();
 236      -        key.append(BuddhistCalendar.class.getName());
 237      -        if (style == SHORT) {
 238      -            key.append(".short");
 239      -        }
 240      -        key.append(".Eras");
 241      -        return key.toString();
 242      -    }
 243      -
 244  204      /**
 245  205       * Returns the maximum value that this field could have, given the
 246  206       * current date.  For example, with the date "Feb 3, 2540" and the
 247  207       * <code>DAY_OF_MONTH</code> field, the actual maximum is 28; for
 248  208       * "Feb 3, 2539" it is 29.
 249  209       *
 250  210       * @param field the field to determine the maximum of
 251  211       * @return the maximum of the given field for the current date of this Calendar
 252  212       */
      213 +    @Override
 253  214      public int getActualMaximum(int field) {
 254  215          int savedYearOffset = yearOffset;
 255  216          // To let the superclass calculate date-time values correctly,
 256  217          // temporarily make this GregorianCalendar.
 257  218          yearOffset = 0;
 258  219          try {
 259  220              return super.getActualMaximum(field);
 260  221          } finally {
 261  222              yearOffset = savedYearOffset;
 262  223          }
 263  224      }
 264  225  
      226 +    @Override
      227 +    @SuppressWarnings("empty-statement")
 265  228      public String toString() {
 266  229          // The super class produces a String with the Gregorian year
 267  230          // value (or '?')
 268  231          String s = super.toString();
 269  232          // If the YEAR field is UNSET, then return the Gregorian string.
 270  233          if (!isSet(YEAR)) {
 271  234              return s;
 272  235          }
 273  236  
 274  237          final String yearField = "YEAR=";
↓ open down ↓ 24 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX