src/share/classes/sun/util/BuddhistCalendar.java
Print this page
rev 5615 : 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 Jigsaw. by Naoto Sato and Masayoshi Okutsu)
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -23,20 +23,17 @@
* questions.
*/
package sun.util;
+import sun.util.locale.provider.CalendarDataUtility;
import java.io.IOException;
import java.io.ObjectInputStream;
-import java.util.Calendar;
import java.util.GregorianCalendar;
-import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
-import java.util.ResourceBundle;
import java.util.TimeZone;
-import sun.util.resources.LocaleData;
public class BuddhistCalendar extends GregorianCalendar {
//////////////////
// Class Variables
@@ -89,10 +86,18 @@
/////////////////
// Public methods
/////////////////
/**
+ * Returns {@code "buddhist"} as the calendar type of this Calendar.
+ */
+ @Override
+ public String getCalendarType() {
+ return "buddhist";
+ }
+
+ /**
* Compares this BuddhistCalendar to an object reference.
* @param obj the object reference with which to compare
* @return true if this object is equal to <code>obj</code>; false otherwise
*/
public boolean equals(Object obj) {
@@ -176,73 +181,22 @@
public String getDisplayName(int field, int style, Locale locale) {
if (field != ERA) {
return super.getDisplayName(field, style, locale);
}
- // Handle Thai BuddhistCalendar specific era names
- if (field < 0 || field >= fields.length ||
- style < SHORT || style > LONG) {
- throw new IllegalArgumentException();
+ String name = CalendarDataUtility.retrieveFieldValueName("buddhist", field, get(field), style, locale);
+ return name;
}
- if (locale == null) {
- throw new NullPointerException();
- }
- ResourceBundle rb = LocaleData.getDateFormatData(locale);
- String[] eras = rb.getStringArray(getKey(style));
- return eras[get(field)];
- }
public Map<String,Integer> getDisplayNames(int field, int style, Locale locale) {
if (field != ERA) {
return super.getDisplayNames(field, style, locale);
}
-
- // Handle Thai BuddhistCalendar specific era names
- if (field < 0 || field >= fields.length ||
- style < ALL_STYLES || style > LONG) {
- throw new IllegalArgumentException();
+ Map<String, Integer> names = CalendarDataUtility.retrieveFieldValueNames("buddhist", field, style, locale);
+ return names;
}
- if (locale == null) {
- throw new NullPointerException();
- }
- // ALL_STYLES
- if (style == ALL_STYLES) {
- Map<String,Integer> shortNames = getDisplayNamesImpl(field, SHORT, locale);
- 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[] eras = rb.getStringArray(getKey(style));
- Map<String,Integer> map = new HashMap<String,Integer>(4);
- for (int i = 0; i < eras.length; i++) {
- map.put(eras[i], i);
- }
- return map;
- }
-
- private String getKey(int style) {
- StringBuilder key = new StringBuilder();
- key.append(BuddhistCalendar.class.getName());
- if (style == SHORT) {
- key.append(".short");
- }
- key.append(".Eras");
- return key.toString();
- }
-
/**
* Returns the maximum value that this field could have, given the
* current date. For example, with the date "Feb 3, 2540" and the
* <code>DAY_OF_MONTH</code> field, the actual maximum is 28; for
* "Feb 3, 2539" it is 29.