jdk/src/share/classes/java/util/Calendar.java
changeset 16481 8e30386cc014
parent 16010 2727163b5df5
child 18156 edb590d448c5
equal deleted inserted replaced
16480:fcad3b6ec812 16481:8e30386cc014
    55 import java.util.concurrent.ConcurrentHashMap;
    55 import java.util.concurrent.ConcurrentHashMap;
    56 import java.util.concurrent.ConcurrentMap;
    56 import java.util.concurrent.ConcurrentMap;
    57 import sun.util.BuddhistCalendar;
    57 import sun.util.BuddhistCalendar;
    58 import sun.util.calendar.ZoneInfo;
    58 import sun.util.calendar.ZoneInfo;
    59 import sun.util.locale.provider.CalendarDataUtility;
    59 import sun.util.locale.provider.CalendarDataUtility;
       
    60 import sun.util.locale.provider.LocaleProviderAdapter;
       
    61 import sun.util.spi.CalendarProvider;
    60 
    62 
    61 /**
    63 /**
    62  * The <code>Calendar</code> class is an abstract class that provides methods
    64  * The <code>Calendar</code> class is an abstract class that provides methods
    63  * for converting between a specific instant in time and a set of {@link
    65  * for converting between a specific instant in time and a set of {@link
    64  * #fields calendar fields} such as <code>YEAR</code>, <code>MONTH</code>,
    66  * #fields calendar fields} such as <code>YEAR</code>, <code>MONTH</code>,
  1606      *
  1608      *
  1607      * @return a Calendar.
  1609      * @return a Calendar.
  1608      */
  1610      */
  1609     public static Calendar getInstance()
  1611     public static Calendar getInstance()
  1610     {
  1612     {
  1611         Calendar cal = createCalendar(TimeZone.getDefaultRef(), Locale.getDefault(Locale.Category.FORMAT));
  1613         return createCalendar(TimeZone.getDefault(), Locale.getDefault(Locale.Category.FORMAT));
  1612         cal.sharedZone = true;
       
  1613         return cal;
       
  1614     }
  1614     }
  1615 
  1615 
  1616     /**
  1616     /**
  1617      * Gets a calendar using the specified time zone and default locale.
  1617      * Gets a calendar using the specified time zone and default locale.
  1618      * The <code>Calendar</code> returned is based on the current time
  1618      * The <code>Calendar</code> returned is based on the current time
  1635      * @param aLocale the locale for the week data
  1635      * @param aLocale the locale for the week data
  1636      * @return a Calendar.
  1636      * @return a Calendar.
  1637      */
  1637      */
  1638     public static Calendar getInstance(Locale aLocale)
  1638     public static Calendar getInstance(Locale aLocale)
  1639     {
  1639     {
  1640         Calendar cal = createCalendar(TimeZone.getDefaultRef(), aLocale);
  1640         return createCalendar(TimeZone.getDefault(), aLocale);
  1641         cal.sharedZone = true;
       
  1642         return cal;
       
  1643     }
  1641     }
  1644 
  1642 
  1645     /**
  1643     /**
  1646      * Gets a calendar with the specified time zone and locale.
  1644      * Gets a calendar with the specified time zone and locale.
  1647      * The <code>Calendar</code> returned is based on the current time
  1645      * The <code>Calendar</code> returned is based on the current time
  1658     }
  1656     }
  1659 
  1657 
  1660     private static Calendar createCalendar(TimeZone zone,
  1658     private static Calendar createCalendar(TimeZone zone,
  1661                                            Locale aLocale)
  1659                                            Locale aLocale)
  1662     {
  1660     {
       
  1661         CalendarProvider provider =
       
  1662             LocaleProviderAdapter.getAdapter(CalendarProvider.class, aLocale)
       
  1663                                  .getCalendarProvider();
       
  1664         if (provider != null) {
       
  1665             try {
       
  1666                 return provider.getInstance(zone, aLocale);
       
  1667             } catch (IllegalArgumentException iae) {
       
  1668                 // fall back to the default instantiation
       
  1669             }
       
  1670         }
       
  1671 
  1663         Calendar cal = null;
  1672         Calendar cal = null;
  1664 
  1673 
  1665         if (aLocale.hasExtensions()) {
  1674         if (aLocale.hasExtensions()) {
  1666             String caltype = aLocale.getUnicodeLocaleType("ca");
  1675             String caltype = aLocale.getUnicodeLocaleType("ca");
  1667             if (caltype != null) {
  1676             if (caltype != null) {