jdk/src/java.base/share/classes/java/util/Calendar.java
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 24865 jdk/src/share/classes/java/util/Calendar.java@09b1d992ca72
child 28059 e576535359cc
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
15280
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
     2
 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright Taligent, Inc. 1996-1998 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 1996-1998 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *   The original version of this source code and documentation is copyrighted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * materials are provided under terms of a License Agreement between Taligent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * and Sun. This technology is protected by multiple US and International
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * patents. This notice and attribution to Taligent may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *   Taligent is a registered trademark of Taligent, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
package java.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.io.ObjectOutputStream;
2599
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
    44
import java.io.OptionalDataException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.io.Serializable;
2599
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
    46
import java.security.AccessControlContext;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.security.AccessController;
2599
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
    48
import java.security.PermissionCollection;
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
    49
import java.security.PrivilegedActionException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.security.PrivilegedExceptionAction;
2599
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
    51
import java.security.ProtectionDomain;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.text.DateFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.text.DateFormatSymbols;
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15280
diff changeset
    54
import java.time.Instant;
7003
7d8d9506b4ee 6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents: 6501
diff changeset
    55
import java.util.concurrent.ConcurrentHashMap;
7d8d9506b4ee 6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents: 6501
diff changeset
    56
import java.util.concurrent.ConcurrentMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.util.BuddhistCalendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import sun.util.calendar.ZoneInfo;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
    59
import sun.util.locale.provider.CalendarDataUtility;
16481
8e30386cc014 8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents: 16010
diff changeset
    60
import sun.util.locale.provider.LocaleProviderAdapter;
8e30386cc014 8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents: 16010
diff changeset
    61
import sun.util.spi.CalendarProvider;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * The <code>Calendar</code> class is an abstract class that provides methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * for converting between a specific instant in time and a set of {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * #fields calendar fields} such as <code>YEAR</code>, <code>MONTH</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <code>DAY_OF_MONTH</code>, <code>HOUR</code>, and so on, and for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * manipulating the calendar fields, such as getting the date of the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * week. An instant in time can be represented by a millisecond value that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * an offset from the <a name="Epoch"><em>Epoch</em></a>, January 1, 1970
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * 00:00:00.000 GMT (Gregorian).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <p>The class also provides additional fields and methods for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * implementing a concrete calendar system outside the package. Those
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * fields and methods are defined as <code>protected</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * Like other locale-sensitive classes, <code>Calendar</code> provides a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * class method, <code>getInstance</code>, for getting a generally useful
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * object of this type. <code>Calendar</code>'s <code>getInstance</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * returns a <code>Calendar</code> object whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * calendar fields have been initialized with the current date and time:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *     Calendar rightNow = Calendar.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <p>A <code>Calendar</code> object can produce all the calendar field values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * needed to implement the date-time formatting for a particular language and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * calendar style (for example, Japanese-Gregorian, Japanese-Traditional).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * <code>Calendar</code> defines the range of values returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * certain calendar fields, as well as their meaning.  For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * the first month of the calendar system has value <code>MONTH ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * JANUARY</code> for all calendars.  Other values are defined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * concrete subclass, such as <code>ERA</code>.  See individual field
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * documentation and subclass documentation for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *
18829
ec84f0c313b0 8020409: Clean up doclint problems in java.util package, part 1
bpb
parents: 18156
diff changeset
    99
 * <h3>Getting and Setting Calendar Field Values</h3>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * <p>The calendar field values can be set by calling the <code>set</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * methods. Any field values set in a <code>Calendar</code> will not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * interpreted until it needs to calculate its time value (milliseconds from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * the Epoch) or values of the calendar fields. Calling the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * <code>get</code>, <code>getTimeInMillis</code>, <code>getTime</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * <code>add</code> and <code>roll</code> involves such calculation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * <h4>Leniency</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * <p><code>Calendar</code> has two modes for interpreting the calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * fields, <em>lenient</em> and <em>non-lenient</em>.  When a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <code>Calendar</code> is in lenient mode, it accepts a wider range of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * calendar field values than it produces.  When a <code>Calendar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * recomputes calendar field values for return by <code>get()</code>, all of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * the calendar fields are normalized. For example, a lenient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <code>GregorianCalendar</code> interprets <code>MONTH == JANUARY</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * <code>DAY_OF_MONTH == 32</code> as February 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * <p>When a <code>Calendar</code> is in non-lenient mode, it throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * exception if there is any inconsistency in its calendar fields. For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * example, a <code>GregorianCalendar</code> always produces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * <code>DAY_OF_MONTH</code> values between 1 and the length of the month. A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * non-lenient <code>GregorianCalendar</code> throws an exception upon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * calculating its time or calendar field values if any out-of-range field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * value has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   127
 * <h4><a name="first_week">First Week</a></h4>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * <code>Calendar</code> defines a locale-specific seven day week using two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * parameters: the first day of the week and the minimal days in first week
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * (from 1 to 7).  These numbers are taken from the locale resource data when a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * <code>Calendar</code> is constructed.  They may also be specified explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * through the methods for setting their values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * <p>When setting or getting the <code>WEEK_OF_MONTH</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * <code>WEEK_OF_YEAR</code> fields, <code>Calendar</code> must determine the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * first week of the month or year as a reference point.  The first week of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * month or year is defined as the earliest seven day period beginning on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * <code>getFirstDayOfWeek()</code> and containing at least
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * <code>getMinimalDaysInFirstWeek()</code> days of that month or year.  Weeks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * numbered ..., -1, 0 precede the first week; weeks numbered 2, 3,... follow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * it.  Note that the normalized numbering returned by <code>get()</code> may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * different.  For example, a specific <code>Calendar</code> subclass may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * designate the week before week 1 of a year as week <code><i>n</i></code> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * the previous year.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * <h4>Calendar Fields Resolution</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * When computing a date and time from the calendar fields, there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * may be insufficient information for the computation (such as only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * year and month with no day of month), or there may be inconsistent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * information (such as Tuesday, July 15, 1996 (Gregorian) -- July 15,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * 1996 is actually a Monday). <code>Calendar</code> will resolve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * calendar field values to determine the date and time in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * following way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 *
15280
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
   157
 * <p><a name="resolution">If there is any conflict in calendar field values,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * <code>Calendar</code> gives priorities to calendar fields that have been set
15280
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
   159
 * more recently.</a> The following are the default combinations of the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * calendar fields. The most recent combination, as determined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * most recently set single field, will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * <p><a name="date_resolution">For the date fields</a>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * YEAR + MONTH + DAY_OF_MONTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * YEAR + MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * YEAR + MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * YEAR + DAY_OF_YEAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * YEAR + DAY_OF_WEEK + WEEK_OF_YEAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * <a name="time_resolution">For the time of day fields</a>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * HOUR_OF_DAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * AM_PM + HOUR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * <p>If there are any calendar fields whose values haven't been set in the selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * field combination, <code>Calendar</code> uses their default values. The default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * value of each field may vary by concrete calendar systems. For example, in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * <code>GregorianCalendar</code>, the default of a field is the same as that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * of the start of the Epoch: i.e., <code>YEAR = 1970</code>, <code>MONTH =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * JANUARY</code>, <code>DAY_OF_MONTH = 1</code>, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * <strong>Note:</strong> There are certain possible ambiguities in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * interpretation of certain singular times, which are resolved in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * following ways:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 *     <li> 23:59 is the last minute of the day and 00:00 is the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 *          minute of the next day. Thus, 23:59 on Dec 31, 1999 &lt; 00:00 on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 *          Jan 1, 2000 &lt; 00:01 on Jan 1, 2000.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 *     <li> Although historically not precise, midnight also belongs to "am",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 *          and noon belongs to "pm", so on the same day,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 *          12:00 am (midnight) &lt; 12:01 am, and 12:00 pm (noon) &lt; 12:01 pm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * The date or time format strings are not part of the definition of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * calendar, as those must be modifiable or overridable by the user at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * runtime. Use {@link DateFormat}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * to format dates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * <h4>Field Manipulation</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * The calendar fields can be changed using three methods:
18829
ec84f0c313b0 8020409: Clean up doclint problems in java.util package, part 1
bpb
parents: 18156
diff changeset
   210
 * <code>set()</code>, <code>add()</code>, and <code>roll()</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * <p><strong><code>set(f, value)</code></strong> changes calendar field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 * <code>f</code> to <code>value</code>.  In addition, it sets an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 * internal member variable to indicate that calendar field <code>f</code> has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 * been changed. Although calendar field <code>f</code> is changed immediately,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 * the calendar's time value in milliseconds is not recomputed until the next call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 * <code>get()</code>, <code>getTime()</code>, <code>getTimeInMillis()</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 * <code>add()</code>, or <code>roll()</code> is made. Thus, multiple calls to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 * <code>set()</code> do not trigger multiple, unnecessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 * computations. As a result of changing a calendar field using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 * <code>set()</code>, other calendar fields may also change, depending on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 * calendar field, the calendar field value, and the calendar system. In addition,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 * <code>get(f)</code> will not necessarily return <code>value</code> set by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
 * the call to the <code>set</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 * after the calendar fields have been recomputed. The specifics are determined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 * the concrete calendar class.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 * <p><em>Example</em>: Consider a <code>GregorianCalendar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 * originally set to August 31, 1999. Calling <code>set(Calendar.MONTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 * Calendar.SEPTEMBER)</code> sets the date to September 31,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 * 1999. This is a temporary internal representation that resolves to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 * October 1, 1999 if <code>getTime()</code>is then called. However, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 * call to <code>set(Calendar.DAY_OF_MONTH, 30)</code> before the call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 * <code>getTime()</code> sets the date to September 30, 1999, since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 * no recomputation occurs after <code>set()</code> itself.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 * <p><strong><code>add(f, delta)</code></strong> adds <code>delta</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 * to field <code>f</code>.  This is equivalent to calling <code>set(f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 * get(f) + delta)</code> with two adjustments:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 *   <p><strong>Add rule 1</strong>. The value of field <code>f</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 *   after the call minus the value of field <code>f</code> before the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 *   call is <code>delta</code>, modulo any overflow that has occurred in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 *   field <code>f</code>. Overflow occurs when a field value exceeds its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 *   range and, as a result, the next larger field is incremented or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 *   decremented and the field value is adjusted back into its range.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 *   <p><strong>Add rule 2</strong>. If a smaller field is expected to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 *   invariant, but it is impossible for it to be equal to its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 *   prior value because of changes in its minimum or maximum after field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 *   <code>f</code> is changed or other constraints, such as time zone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 *   offset changes, then its value is adjusted to be as close
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 *   as possible to its expected value. A smaller field represents a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
 *   smaller unit of time. <code>HOUR</code> is a smaller field than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
 *   <code>DAY_OF_MONTH</code>. No adjustment is made to smaller fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 *   that are not expected to be invariant. The calendar system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 *   determines what fields are expected to be invariant.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
 * <p>In addition, unlike <code>set()</code>, <code>add()</code> forces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 * an immediate recomputation of the calendar's milliseconds and all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 * fields.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
 * <p><em>Example</em>: Consider a <code>GregorianCalendar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
 * originally set to August 31, 1999. Calling <code>add(Calendar.MONTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
 * 13)</code> sets the calendar to September 30, 2000. <strong>Add rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 * 1</strong> sets the <code>MONTH</code> field to September, since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 * adding 13 months to August gives September of the next year. Since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 * <code>DAY_OF_MONTH</code> cannot be 31 in September in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 * <code>GregorianCalendar</code>, <strong>add rule 2</strong> sets the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 * <code>DAY_OF_MONTH</code> to 30, the closest possible value. Although
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 * it is a smaller field, <code>DAY_OF_WEEK</code> is not adjusted by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 * rule 2, since it is expected to change when the month changes in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 * <code>GregorianCalendar</code>.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 * <p><strong><code>roll(f, delta)</code></strong> adds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 * <code>delta</code> to field <code>f</code> without changing larger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 * fields. This is equivalent to calling <code>add(f, delta)</code> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 * the following adjustment:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 *   <p><strong>Roll rule</strong>. Larger fields are unchanged after the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 *   call. A larger field represents a larger unit of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
 *   time. <code>DAY_OF_MONTH</code> is a larger field than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
 *   <code>HOUR</code>.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
 * <p><em>Example</em>: See {@link java.util.GregorianCalendar#roll(int, int)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 * <p><strong>Usage model</strong>. To motivate the behavior of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 * <code>add()</code> and <code>roll()</code>, consider a user interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
 * component with increment and decrement buttons for the month, day, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
 * year, and an underlying <code>GregorianCalendar</code>. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
 * interface reads January 31, 1999 and the user presses the month
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
 * increment button, what should it read? If the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
 * implementation uses <code>set()</code>, it might read March 3, 1999. A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
 * better result would be February 28, 1999. Furthermore, if the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
 * presses the month increment button again, it should read March 31,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
 * 1999, not March 28, 1999. By saving the original date and using either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
 * <code>add()</code> or <code>roll()</code>, depending on whether larger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
 * fields should be affected, the user interface can behave as most users
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 * will intuitively expect.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
 * @see          java.lang.System#currentTimeMillis()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
 * @see          Date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
 * @see          GregorianCalendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
 * @see          TimeZone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
 * @see          java.text.DateFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
 * @author Mark Davis, David Goldsmith, Chen-Lieh Huang, Alan Liu
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 22078
diff changeset
   311
 * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
public abstract class Calendar implements Serializable, Cloneable, Comparable<Calendar> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    // Data flow in Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    // ---------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    // The current time is represented in two ways by Calendar: as UTC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    // milliseconds from the epoch (1 January 1970 0:00 UTC), and as local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    // fields such as MONTH, HOUR, AM_PM, etc.  It is possible to compute the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    // millis from the fields, and vice versa.  The data needed to do this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    // conversion is encapsulated by a TimeZone object owned by the Calendar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    // The data provided by the TimeZone object may also be overridden if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    // user sets the ZONE_OFFSET and/or DST_OFFSET fields directly. The class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    // keeps track of what information was most recently set by the caller, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    // uses that to compute any other information as needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    // If the user sets the fields using set(), the data flow is as follows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    // This is implemented by the Calendar subclass's computeTime() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    // During this process, certain fields may be ignored.  The disambiguation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    // algorithm for resolving which fields to pay attention to is described
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    // in the class documentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    //   local fields (YEAR, MONTH, DATE, HOUR, MINUTE, etc.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    //           |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    //           | Using Calendar-specific algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    //           V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    //   local standard millis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    //           |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    //           | Using TimeZone or user-set ZONE_OFFSET / DST_OFFSET
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    //           V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    //   UTC millis (in time data member)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    // If the user sets the UTC millis using setTime() or setTimeInMillis(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    // the data flow is as follows.  This is implemented by the Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    // subclass's computeFields() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    //   UTC millis (in time data member)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    //           |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    //           | Using TimeZone getOffset()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    //           V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    //   local standard millis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    //           |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    //           | Using Calendar-specific algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    //           V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    //   local fields (YEAR, MONTH, DATE, HOUR, MINUTE, etc.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    // In general, a round trip from fields, through local and UTC millis, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    // back out to fields is made when necessary.  This is implemented by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    // complete() method.  Resolving a partial set of fields into a UTC millis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    // value allows all remaining fields to be generated from that value.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    // the Calendar is lenient, the fields are also renormalized to standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    // ranges when they are regenerated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * Field number for <code>get</code> and <code>set</code> indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * era, e.g., AD or BC in the Julian calendar. This is a calendar-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * value; see subclass documentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @see GregorianCalendar#AD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @see GregorianCalendar#BC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public final static int ERA = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * Field number for <code>get</code> and <code>set</code> indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * year. This is a calendar-specific value; see subclass documentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    public final static int YEAR = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Field number for <code>get</code> and <code>set</code> indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * month. This is a calendar-specific value. The first month of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * the year in the Gregorian and Julian calendars is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * <code>JANUARY</code> which is 0; the last depends on the number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * of months in a year.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @see #JANUARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @see #FEBRUARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @see #MARCH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @see #APRIL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @see #MAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @see #JUNE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @see #JULY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @see #AUGUST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @see #SEPTEMBER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @see #OCTOBER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @see #NOVEMBER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @see #DECEMBER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @see #UNDECIMBER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    public final static int MONTH = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Field number for <code>get</code> and <code>set</code> indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * week number within the current year.  The first week of the year, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * defined by <code>getFirstDayOfWeek()</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * <code>getMinimalDaysInFirstWeek()</code>, has value 1.  Subclasses define
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * the value of <code>WEEK_OF_YEAR</code> for days before the first week of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * the year.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @see #getFirstDayOfWeek
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @see #getMinimalDaysInFirstWeek
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    public final static int WEEK_OF_YEAR = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * Field number for <code>get</code> and <code>set</code> indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * week number within the current month.  The first week of the month, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * defined by <code>getFirstDayOfWeek()</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * <code>getMinimalDaysInFirstWeek()</code>, has value 1.  Subclasses define
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * the value of <code>WEEK_OF_MONTH</code> for days before the first week of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * the month.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @see #getFirstDayOfWeek
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @see #getMinimalDaysInFirstWeek
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    public final static int WEEK_OF_MONTH = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * Field number for <code>get</code> and <code>set</code> indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * day of the month. This is a synonym for <code>DAY_OF_MONTH</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * The first day of the month has value 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @see #DAY_OF_MONTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    public final static int DATE = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * Field number for <code>get</code> and <code>set</code> indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * day of the month. This is a synonym for <code>DATE</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * The first day of the month has value 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @see #DATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    public final static int DAY_OF_MONTH = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * Field number for <code>get</code> and <code>set</code> indicating the day
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * number within the current year.  The first day of the year has value 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    public final static int DAY_OF_YEAR = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Field number for <code>get</code> and <code>set</code> indicating the day
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * of the week.  This field takes values <code>SUNDAY</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * <code>MONDAY</code>, <code>TUESDAY</code>, <code>WEDNESDAY</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * <code>THURSDAY</code>, <code>FRIDAY</code>, and <code>SATURDAY</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @see #SUNDAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @see #MONDAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @see #TUESDAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @see #WEDNESDAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @see #THURSDAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @see #FRIDAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @see #SATURDAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    public final static int DAY_OF_WEEK = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * Field number for <code>get</code> and <code>set</code> indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * ordinal number of the day of the week within the current month. Together
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * with the <code>DAY_OF_WEEK</code> field, this uniquely specifies a day
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * within a month.  Unlike <code>WEEK_OF_MONTH</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * <code>WEEK_OF_YEAR</code>, this field's value does <em>not</em> depend on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * <code>getFirstDayOfWeek()</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * <code>getMinimalDaysInFirstWeek()</code>.  <code>DAY_OF_MONTH 1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * through <code>7</code> always correspond to <code>DAY_OF_WEEK_IN_MONTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * 1</code>; <code>8</code> through <code>14</code> correspond to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * <code>DAY_OF_WEEK_IN_MONTH 2</code>, and so on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * <code>DAY_OF_WEEK_IN_MONTH 0</code> indicates the week before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * <code>DAY_OF_WEEK_IN_MONTH 1</code>.  Negative values count back from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * end of the month, so the last Sunday of a month is specified as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * <code>DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1</code>.  Because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * negative values count backward they will usually be aligned differently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * within the month than positive values.  For example, if a month has 31
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * days, <code>DAY_OF_WEEK_IN_MONTH -1</code> will overlap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * <code>DAY_OF_WEEK_IN_MONTH 5</code> and the end of <code>4</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @see #DAY_OF_WEEK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @see #WEEK_OF_MONTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    public final static int DAY_OF_WEEK_IN_MONTH = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * Field number for <code>get</code> and <code>set</code> indicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * whether the <code>HOUR</code> is before or after noon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * E.g., at 10:04:15.250 PM the <code>AM_PM</code> is <code>PM</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @see #AM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @see #PM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @see #HOUR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    public final static int AM_PM = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * Field number for <code>get</code> and <code>set</code> indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * hour of the morning or afternoon. <code>HOUR</code> is used for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * 12-hour clock (0 - 11). Noon and midnight are represented by 0, not by 12.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * E.g., at 10:04:15.250 PM the <code>HOUR</code> is 10.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * @see #AM_PM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @see #HOUR_OF_DAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    public final static int HOUR = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * Field number for <code>get</code> and <code>set</code> indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * hour of the day. <code>HOUR_OF_DAY</code> is used for the 24-hour clock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * E.g., at 10:04:15.250 PM the <code>HOUR_OF_DAY</code> is 22.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @see #HOUR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    public final static int HOUR_OF_DAY = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * Field number for <code>get</code> and <code>set</code> indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * minute within the hour.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * E.g., at 10:04:15.250 PM the <code>MINUTE</code> is 4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    public final static int MINUTE = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * Field number for <code>get</code> and <code>set</code> indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * second within the minute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * E.g., at 10:04:15.250 PM the <code>SECOND</code> is 15.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public final static int SECOND = 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * Field number for <code>get</code> and <code>set</code> indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * millisecond within the second.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * E.g., at 10:04:15.250 PM the <code>MILLISECOND</code> is 250.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    public final static int MILLISECOND = 14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * Field number for <code>get</code> and <code>set</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * indicating the raw offset from GMT in milliseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * This field reflects the correct GMT offset value of the time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * zone of this <code>Calendar</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * <code>TimeZone</code> implementation subclass supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * historical GMT offset changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    public final static int ZONE_OFFSET = 15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * Field number for <code>get</code> and <code>set</code> indicating the
8521
ab64b8d109b8 6955047: (tz) javadoc for TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not clear
okutsu
parents: 7003
diff changeset
   560
     * daylight saving offset in milliseconds.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * This field reflects the correct daylight saving offset value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * the time zone of this <code>Calendar</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * <code>TimeZone</code> implementation subclass supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * historical Daylight Saving Time schedule changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    public final static int DST_OFFSET = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * The number of distinct fields recognized by <code>get</code> and <code>set</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * Field numbers range from <code>0..FIELD_COUNT-1</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    public final static int FIELD_COUNT = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * Value of the {@link #DAY_OF_WEEK} field indicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * Sunday.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    public final static int SUNDAY = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * Value of the {@link #DAY_OF_WEEK} field indicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * Monday.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    public final static int MONDAY = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * Value of the {@link #DAY_OF_WEEK} field indicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * Tuesday.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    public final static int TUESDAY = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * Value of the {@link #DAY_OF_WEEK} field indicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * Wednesday.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    public final static int WEDNESDAY = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * Value of the {@link #DAY_OF_WEEK} field indicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * Thursday.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    public final static int THURSDAY = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * Value of the {@link #DAY_OF_WEEK} field indicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * Friday.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    public final static int FRIDAY = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * Value of the {@link #DAY_OF_WEEK} field indicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * Saturday.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    public final static int SATURDAY = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * Value of the {@link #MONTH} field indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * first month of the year in the Gregorian and Julian calendars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    public final static int JANUARY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * Value of the {@link #MONTH} field indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * second month of the year in the Gregorian and Julian calendars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    public final static int FEBRUARY = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * Value of the {@link #MONTH} field indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * third month of the year in the Gregorian and Julian calendars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    public final static int MARCH = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * Value of the {@link #MONTH} field indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * fourth month of the year in the Gregorian and Julian calendars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    public final static int APRIL = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * Value of the {@link #MONTH} field indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * fifth month of the year in the Gregorian and Julian calendars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    public final static int MAY = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * Value of the {@link #MONTH} field indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * sixth month of the year in the Gregorian and Julian calendars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    public final static int JUNE = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * Value of the {@link #MONTH} field indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * seventh month of the year in the Gregorian and Julian calendars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    public final static int JULY = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * Value of the {@link #MONTH} field indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * eighth month of the year in the Gregorian and Julian calendars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    public final static int AUGUST = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * Value of the {@link #MONTH} field indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * ninth month of the year in the Gregorian and Julian calendars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    public final static int SEPTEMBER = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * Value of the {@link #MONTH} field indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * tenth month of the year in the Gregorian and Julian calendars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    public final static int OCTOBER = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * Value of the {@link #MONTH} field indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * eleventh month of the year in the Gregorian and Julian calendars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    public final static int NOVEMBER = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * Value of the {@link #MONTH} field indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * twelfth month of the year in the Gregorian and Julian calendars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    public final static int DECEMBER = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * Value of the {@link #MONTH} field indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * thirteenth month of the year. Although <code>GregorianCalendar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * does not use this value, lunar calendars do.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    public final static int UNDECIMBER = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * Value of the {@link #AM_PM} field indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * period of the day from midnight to just before noon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    public final static int AM = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * Value of the {@link #AM_PM} field indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * period of the day from noon to just before midnight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    public final static int PM = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * A style specifier for {@link #getDisplayNames(int, int, Locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * getDisplayNames} indicating names in all styles, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * "January" and "Jan".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     *
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   713
     * @see #SHORT_FORMAT
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   714
     * @see #LONG_FORMAT
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   715
     * @see #SHORT_STANDALONE
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   716
     * @see #LONG_STANDALONE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * @see #SHORT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * @see #LONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    public static final int ALL_STYLES = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   723
    static final int STANDALONE_MASK = 0x8000;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   724
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * A style specifier for {@link #getDisplayName(int, int, Locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * getDisplayName} and {@link #getDisplayNames(int, int, Locale)
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   728
     * getDisplayNames} equivalent to {@link #SHORT_FORMAT}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     *
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   730
     * @see #SHORT_STANDALONE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * @see #LONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    public static final int SHORT = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * A style specifier for {@link #getDisplayName(int, int, Locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * getDisplayName} and {@link #getDisplayNames(int, int, Locale)
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   739
     * getDisplayNames} equivalent to {@link #LONG_FORMAT}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     *
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   741
     * @see #LONG_STANDALONE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * @see #SHORT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    public static final int LONG = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   747
    /**
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   748
     * A style specifier for {@link #getDisplayName(int, int, Locale)
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   749
     * getDisplayName} and {@link #getDisplayNames(int, int, Locale)
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   750
     * getDisplayNames} indicating a narrow name used for format. Narrow names
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   751
     * are typically single character strings, such as "M" for Monday.
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   752
     *
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   753
     * @see #NARROW_STANDALONE
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   754
     * @see #SHORT_FORMAT
14928
afdc82e5403a 8005561: typo in Calendar
okutsu
parents: 14765
diff changeset
   755
     * @see #LONG_FORMAT
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   756
     * @since 1.8
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   757
     */
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   758
    public static final int NARROW_FORMAT = 4;
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   759
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   760
    /**
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   761
     * A style specifier for {@link #getDisplayName(int, int, Locale)
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   762
     * getDisplayName} and {@link #getDisplayNames(int, int, Locale)
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   763
     * getDisplayNames} indicating a narrow name independently. Narrow names
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   764
     * are typically single character strings, such as "M" for Monday.
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   765
     *
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   766
     * @see #NARROW_FORMAT
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   767
     * @see #SHORT_STANDALONE
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   768
     * @see #LONG_STANDALONE
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   769
     * @since 1.8
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   770
     */
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   771
    public static final int NARROW_STANDALONE = NARROW_FORMAT | STANDALONE_MASK;
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   772
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   773
    /**
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   774
     * A style specifier for {@link #getDisplayName(int, int, Locale)
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
   775
     * getDisplayName} and {@link #getDisplayNames(int, int, Locale)
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   776
     * getDisplayNames} indicating a short name used for format.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   777
     *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   778
     * @see #SHORT_STANDALONE
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   779
     * @see #LONG_FORMAT
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   780
     * @see #LONG_STANDALONE
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   781
     * @since 1.8
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   782
     */
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   783
    public static final int SHORT_FORMAT = 1;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   784
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   785
    /**
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   786
     * A style specifier for {@link #getDisplayName(int, int, Locale)
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   787
     * getDisplayName} and {@link #getDisplayNames(int, int, Locale)
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   788
     * getDisplayNames} indicating a long name used for format.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   789
     *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   790
     * @see #LONG_STANDALONE
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   791
     * @see #SHORT_FORMAT
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   792
     * @see #SHORT_STANDALONE
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   793
     * @since 1.8
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   794
     */
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   795
    public static final int LONG_FORMAT = 2;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   796
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   797
    /**
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   798
     * A style specifier for {@link #getDisplayName(int, int, Locale)
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   799
     * getDisplayName} and {@link #getDisplayNames(int, int, Locale)
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   800
     * getDisplayNames} indicating a short name used independently,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   801
     * such as a month abbreviation as calendar headers.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   802
     *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   803
     * @see #SHORT_FORMAT
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   804
     * @see #LONG_FORMAT
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   805
     * @see #LONG_STANDALONE
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   806
     * @since 1.8
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   807
     */
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   808
    public static final int SHORT_STANDALONE = SHORT | STANDALONE_MASK;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   809
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   810
    /**
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   811
     * A style specifier for {@link #getDisplayName(int, int, Locale)
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   812
     * getDisplayName} and {@link #getDisplayNames(int, int, Locale)
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   813
     * getDisplayNames} indicating a long name used independently,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   814
     * such as a month name as calendar headers.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   815
     *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   816
     * @see #LONG_FORMAT
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   817
     * @see #SHORT_FORMAT
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   818
     * @see #SHORT_STANDALONE
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   819
     * @since 1.8
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   820
     */
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   821
    public static final int LONG_STANDALONE = LONG | STANDALONE_MASK;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   822
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    // Internal notes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    // Calendar contains two kinds of time representations: current "time" in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    // milliseconds, and a set of calendar "fields" representing the current time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    // The two representations are usually in sync, but can get out of sync
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    // as follows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    // 1. Initially, no fields are set, and the time is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    // 2. If the time is set, all fields are computed and in sync.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    // 3. If a single field is set, the time is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    // Recomputation of the time and fields happens when the object needs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    // to return a result to the user, or use a result for a computation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * The calendar field values for the currently set time for this calendar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * This is an array of <code>FIELD_COUNT</code> integers, with index values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * <code>ERA</code> through <code>DST_OFFSET</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   840
    @SuppressWarnings("ProtectedField")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    protected int           fields[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * The flags which tell if a specified calendar field for the calendar is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * A new object has no fields set.  After the first call to a method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * which generates the fields, they all remain set after that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * This is an array of <code>FIELD_COUNT</code> booleans, with index values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * <code>ERA</code> through <code>DST_OFFSET</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   851
    @SuppressWarnings("ProtectedField")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    protected boolean       isSet[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * Pseudo-time-stamps which specify when each field was set. There
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * are two special values, UNSET and COMPUTED. Values from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * MINIMUM_USER_SET to Integer.MAX_VALUE are legal user set values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    transient private int   stamp[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * The currently set time for this calendar, expressed in milliseconds after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * January 1, 1970, 0:00:00 GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * @see #isTimeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   867
    @SuppressWarnings("ProtectedField")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    protected long          time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * True if then the value of <code>time</code> is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * The time is made invalid by a change to an item of <code>field[]</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * @see #time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   876
    @SuppressWarnings("ProtectedField")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    protected boolean       isTimeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * True if <code>fields[]</code> are in sync with the currently set time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * If false, then the next attempt to get the value of a field will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * force a recomputation of all fields from the current value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * <code>time</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   886
    @SuppressWarnings("ProtectedField")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    protected boolean       areFieldsSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * True if all fields have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    transient boolean       areAllFieldsSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * <code>True</code> if this calendar allows out-of-range field values during computation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * of <code>time</code> from <code>fields[]</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * @see #setLenient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * @see #isLenient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    private boolean         lenient = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * The <code>TimeZone</code> used by this calendar. <code>Calendar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * uses the time zone data to translate between locale and GMT time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    private TimeZone        zone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * <code>True</code> if zone references to a shared TimeZone object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    transient private boolean sharedZone = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * The first day of the week, with possible values <code>SUNDAY</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * <code>MONDAY</code>, etc.  This is a locale-dependent value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    private int             firstDayOfWeek;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * The number of days required for the first week in a month or year,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * with possible values from 1 to 7.  This is a locale-dependent value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    private int             minimalDaysInFirstWeek;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * Cache to hold the firstDayOfWeek and minimalDaysInFirstWeek
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * of a Locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     */
7003
7d8d9506b4ee 6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents: 6501
diff changeset
   934
    private static final ConcurrentMap<Locale, int[]> cachedLocaleData
12448
b95438b17098 7157893: Warnings Cleanup in java.util.*
khazra
parents: 11681
diff changeset
   935
        = new ConcurrentHashMap<>(3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    // Special values of stamp[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * The corresponding fields[] has no value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    private static final int        UNSET = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * The value of the corresponding fields[] has been calculated internally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    private static final int        COMPUTED = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * The value of the corresponding fields[] has been set externally. Stamp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * values which are greater than 1 represents the (pseudo) time when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * corresponding fields[] value was set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    private static final int        MINIMUM_USER_STAMP = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * The mask value that represents all of the fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    static final int ALL_FIELDS = (1 << FIELD_COUNT) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * The next available value for <code>stamp[]</code>, an internal array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * This actually should not be written out to the stream, and will probably
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * be removed from the stream in the near future.  In the meantime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * a value of <code>MINIMUM_USER_STAMP</code> should be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    private int             nextStamp = MINIMUM_USER_STAMP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    // the internal serial version which says which version was written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    // - 0 (default) for version up to JDK 1.1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    // - 1 for version from JDK 1.1.6, which writes a correct 'time' value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    //     as well as compatible values for other fields.  This is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    //     transitional format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    // - 2 (not implemented yet) a future version, in which fields[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    //     areFieldsSet, and isTimeSet become transient, and isSet[] is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    //     removed. In JDK 1.1.6 we write a format compatible with version 2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    static final int        currentSerialVersion = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * The version of the serialized data on the stream.  Possible values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * <dt><b>0</b> or not present on stream</dt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * <dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * JDK 1.1.5 or earlier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * </dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * <dt><b>1</b></dt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * <dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * JDK 1.1.6 or later.  Writes a correct 'time' value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * as well as compatible values for other fields.  This is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * transitional format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * </dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * When streaming out this class, the most recent format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * and the highest allowable <code>serialVersionOnStream</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * is written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * @serial
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 22078
diff changeset
   997
     * @since 1.1.6
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    private int             serialVersionOnStream = currentSerialVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    // Proclaim serialization compatibility with JDK 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
    static final long       serialVersionUID = -1807547505821590642L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    // Mask values for calendar fields
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1005
    @SuppressWarnings("PointlessBitwiseExpression")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    final static int ERA_MASK           = (1 << ERA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    final static int YEAR_MASK          = (1 << YEAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    final static int MONTH_MASK         = (1 << MONTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    final static int WEEK_OF_YEAR_MASK  = (1 << WEEK_OF_YEAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
    final static int WEEK_OF_MONTH_MASK = (1 << WEEK_OF_MONTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    final static int DAY_OF_MONTH_MASK  = (1 << DAY_OF_MONTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    final static int DATE_MASK          = DAY_OF_MONTH_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    final static int DAY_OF_YEAR_MASK   = (1 << DAY_OF_YEAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    final static int DAY_OF_WEEK_MASK   = (1 << DAY_OF_WEEK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    final static int DAY_OF_WEEK_IN_MONTH_MASK  = (1 << DAY_OF_WEEK_IN_MONTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    final static int AM_PM_MASK         = (1 << AM_PM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    final static int HOUR_MASK          = (1 << HOUR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    final static int HOUR_OF_DAY_MASK   = (1 << HOUR_OF_DAY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    final static int MINUTE_MASK        = (1 << MINUTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    final static int SECOND_MASK        = (1 << SECOND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    final static int MILLISECOND_MASK   = (1 << MILLISECOND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    final static int ZONE_OFFSET_MASK   = (1 << ZONE_OFFSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    final static int DST_OFFSET_MASK    = (1 << DST_OFFSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    /**
15280
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1026
     * {@code Calendar.Builder} is used for creating a {@code Calendar} from
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1027
     * various date-time parameters.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1028
     *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1029
     * <p>There are two ways to set a {@code Calendar} to a date-time value. One
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1030
     * is to set the instant parameter to a millisecond offset from the <a
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1031
     * href="Calendar.html#Epoch">Epoch</a>. The other is to set individual
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1032
     * field parameters, such as {@link Calendar#YEAR YEAR}, to their desired
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1033
     * values. These two ways can't be mixed. Trying to set both the instant and
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1034
     * individual fields will cause an {@link IllegalStateException} to be
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1035
     * thrown. However, it is permitted to override previous values of the
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1036
     * instant or field parameters.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1037
     *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1038
     * <p>If no enough field parameters are given for determining date and/or
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1039
     * time, calendar specific default values are used when building a
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1040
     * {@code Calendar}. For example, if the {@link Calendar#YEAR YEAR} value
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1041
     * isn't given for the Gregorian calendar, 1970 will be used. If there are
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1042
     * any conflicts among field parameters, the <a
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1043
     * href="Calendar.html#resolution"> resolution rules</a> are applied.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1044
     * Therefore, the order of field setting matters.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1045
     *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1046
     * <p>In addition to the date-time parameters,
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1047
     * the {@linkplain #setLocale(Locale) locale},
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1048
     * {@linkplain #setTimeZone(TimeZone) time zone},
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1049
     * {@linkplain #setWeekDefinition(int, int) week definition}, and
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1050
     * {@linkplain #setLenient(boolean) leniency mode} parameters can be set.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1051
     *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1052
     * <p><b>Examples</b>
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1053
     * <p>The following are sample usages. Sample code assumes that the
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1054
     * {@code Calendar} constants are statically imported.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1055
     *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1056
     * <p>The following code produces a {@code Calendar} with date 2012-12-31
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1057
     * (Gregorian) because Monday is the first day of a week with the <a
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1058
     * href="GregorianCalendar.html#iso8601_compatible_setting"> ISO 8601
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1059
     * compatible week parameters</a>.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1060
     * <pre>
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1061
     *   Calendar cal = new Calendar.Builder().setCalendarType("iso8601")
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1062
     *                        .setWeekDate(2013, 1, MONDAY).build();</pre>
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1063
     * <p>The following code produces a Japanese {@code Calendar} with date
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1064
     * 1989-01-08 (Gregorian), assuming that the default {@link Calendar#ERA ERA}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1065
     * is <em>Heisei</em> that started on that day.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1066
     * <pre>
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1067
     *   Calendar cal = new Calendar.Builder().setCalendarType("japanese")
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1068
     *                        .setFields(YEAR, 1, DAY_OF_YEAR, 1).build();</pre>
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1069
     *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1070
     * @since 1.8
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1071
     * @see Calendar#getInstance(TimeZone, Locale)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1072
     * @see Calendar#fields
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1073
     */
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1074
    public static class Builder {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1075
        private static final int NFIELDS = FIELD_COUNT + 1; // +1 for WEEK_YEAR
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1076
        private static final int WEEK_YEAR = FIELD_COUNT;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1077
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1078
        private long instant;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1079
        // Calendar.stamp[] (lower half) and Calendar.fields[] (upper half) combined
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1080
        private int[] fields;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1081
        // Pseudo timestamp starting from MINIMUM_USER_STAMP.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1082
        // (COMPUTED is used to indicate that the instant has been set.)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1083
        private int nextStamp;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1084
        // maxFieldIndex keeps the max index of fields which have been set.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1085
        // (WEEK_YEAR is never included.)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1086
        private int maxFieldIndex;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1087
        private String type;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1088
        private TimeZone zone;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1089
        private boolean lenient = true;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1090
        private Locale locale;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1091
        private int firstDayOfWeek, minimalDaysInFirstWeek;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1092
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1093
        /**
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1094
         * Constructs a {@code Calendar.Builder}.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1095
         */
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1096
        public Builder() {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1097
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1098
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1099
        /**
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1100
         * Sets the instant parameter to the given {@code instant} value that is
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1101
         * a millisecond offset from <a href="Calendar.html#Epoch">the
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1102
         * Epoch</a>.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1103
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1104
         * @param instant a millisecond offset from the Epoch
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1105
         * @return this {@code Calendar.Builder}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1106
         * @throws IllegalStateException if any of the field parameters have
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1107
         *                               already been set
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1108
         * @see Calendar#setTime(Date)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1109
         * @see Calendar#setTimeInMillis(long)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1110
         * @see Calendar#time
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1111
         */
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1112
        public Builder setInstant(long instant) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1113
            if (fields != null) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1114
                throw new IllegalStateException();
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1115
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1116
            this.instant = instant;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1117
            nextStamp = COMPUTED;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1118
            return this;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1119
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1120
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1121
        /**
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1122
         * Sets the instant parameter to the {@code instant} value given by a
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1123
         * {@link Date}. This method is equivalent to a call to
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1124
         * {@link #setInstant(long) setInstant(instant.getTime())}.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1125
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1126
         * @param instant a {@code Date} representing a millisecond offset from
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1127
         *                the Epoch
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1128
         * @return this {@code Calendar.Builder}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1129
         * @throws NullPointerException  if {@code instant} is {@code null}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1130
         * @throws IllegalStateException if any of the field parameters have
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1131
         *                               already been set
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1132
         * @see Calendar#setTime(Date)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1133
         * @see Calendar#setTimeInMillis(long)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1134
         * @see Calendar#time
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1135
         */
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1136
        public Builder setInstant(Date instant) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1137
            return setInstant(instant.getTime()); // NPE if instant == null
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1138
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1139
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1140
        /**
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1141
         * Sets the {@code field} parameter to the given {@code value}.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1142
         * {@code field} is an index to the {@link Calendar#fields}, such as
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1143
         * {@link Calendar#DAY_OF_MONTH DAY_OF_MONTH}. Field value validation is
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1144
         * not performed in this method. Any out of range values are either
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1145
         * normalized in lenient mode or detected as an invalid value in
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1146
         * non-lenient mode when building a {@code Calendar}.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1147
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1148
         * @param field an index to the {@code Calendar} fields
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1149
         * @param value the field value
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1150
         * @return this {@code Calendar.Builder}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1151
         * @throws IllegalArgumentException if {@code field} is invalid
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1152
         * @throws IllegalStateException if the instant value has already been set,
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1153
         *                      or if fields have been set too many
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1154
         *                      (approximately {@link Integer#MAX_VALUE}) times.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1155
         * @see Calendar#set(int, int)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1156
         */
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1157
        public Builder set(int field, int value) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1158
            // Note: WEEK_YEAR can't be set with this method.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1159
            if (field < 0 || field >= FIELD_COUNT) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1160
                throw new IllegalArgumentException("field is invalid");
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1161
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1162
            if (isInstantSet()) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1163
                throw new IllegalStateException("instant has been set");
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1164
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1165
            allocateFields();
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1166
            internalSet(field, value);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1167
            return this;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1168
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1169
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1170
        /**
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1171
         * Sets field parameters to their values given by
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1172
         * {@code fieldValuePairs} that are pairs of a field and its value.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1173
         * For example,
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1174
         * <pre>
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1175
         *   setFeilds(Calendar.YEAR, 2013,
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1176
         *             Calendar.MONTH, Calendar.DECEMBER,
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1177
         *             Calendar.DAY_OF_MONTH, 23);</pre>
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1178
         * is equivalent to the sequence of the following
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1179
         * {@link #set(int, int) set} calls:
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1180
         * <pre>
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1181
         *   set(Calendar.YEAR, 2013)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1182
         *   .set(Calendar.MONTH, Calendar.DECEMBER)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1183
         *   .set(Calendar.DAY_OF_MONTH, 23);</pre>
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1184
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1185
         * @param fieldValuePairs field-value pairs
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1186
         * @return this {@code Calendar.Builder}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1187
         * @throws NullPointerException if {@code fieldValuePairs} is {@code null}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1188
         * @throws IllegalArgumentException if any of fields are invalid,
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1189
         *             or if {@code fieldValuePairs.length} is an odd number.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1190
         * @throws IllegalStateException    if the instant value has been set,
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1191
         *             or if fields have been set too many (approximately
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1192
         *             {@link Integer#MAX_VALUE}) times.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1193
         */
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1194
        public Builder setFields(int... fieldValuePairs) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1195
            int len = fieldValuePairs.length;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1196
            if ((len % 2) != 0) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1197
                throw new IllegalArgumentException();
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1198
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1199
            if (isInstantSet()) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1200
                throw new IllegalStateException("instant has been set");
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1201
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1202
            if ((nextStamp + len / 2) < 0) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1203
                throw new IllegalStateException("stamp counter overflow");
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1204
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1205
            allocateFields();
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1206
            for (int i = 0; i < len; ) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1207
                int field = fieldValuePairs[i++];
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1208
                // Note: WEEK_YEAR can't be set with this method.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1209
                if (field < 0 || field >= FIELD_COUNT) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1210
                    throw new IllegalArgumentException("field is invalid");
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1211
                }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1212
                internalSet(field, fieldValuePairs[i++]);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1213
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1214
            return this;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1215
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1216
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1217
        /**
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1218
         * Sets the date field parameters to the values given by {@code year},
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1219
         * {@code month}, and {@code dayOfMonth}. This method is equivalent to
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1220
         * a call to:
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1221
         * <pre>
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1222
         *   setFields(Calendar.YEAR, year,
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1223
         *             Calendar.MONTH, month,
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1224
         *             Calendar.DAY_OF_MONTH, dayOfMonth);</pre>
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1225
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1226
         * @param year       the {@link Calendar#YEAR YEAR} value
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1227
         * @param month      the {@link Calendar#MONTH MONTH} value
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1228
         *                   (the month numbering is <em>0-based</em>).
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1229
         * @param dayOfMonth the {@link Calendar#DAY_OF_MONTH DAY_OF_MONTH} value
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1230
         * @return this {@code Calendar.Builder}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1231
         */
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1232
        public Builder setDate(int year, int month, int dayOfMonth) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1233
            return setFields(YEAR, year, MONTH, month, DAY_OF_MONTH, dayOfMonth);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1234
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1235
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1236
        /**
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1237
         * Sets the time of day field parameters to the values given by
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1238
         * {@code hourOfDay}, {@code minute}, and {@code second}. This method is
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1239
         * equivalent to a call to:
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1240
         * <pre>
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1241
         *   setTimeOfDay(hourOfDay, minute, second, 0);</pre>
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1242
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1243
         * @param hourOfDay the {@link Calendar#HOUR_OF_DAY HOUR_OF_DAY} value
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1244
         *                  (24-hour clock)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1245
         * @param minute    the {@link Calendar#MINUTE MINUTE} value
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1246
         * @param second    the {@link Calendar#SECOND SECOND} value
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1247
         * @return this {@code Calendar.Builder}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1248
         */
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1249
        public Builder setTimeOfDay(int hourOfDay, int minute, int second) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1250
            return setTimeOfDay(hourOfDay, minute, second, 0);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1251
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1252
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1253
        /**
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1254
         * Sets the time of day field parameters to the values given by
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1255
         * {@code hourOfDay}, {@code minute}, {@code second}, and
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1256
         * {@code millis}. This method is equivalent to a call to:
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1257
         * <pre>
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1258
         *   setFields(Calendar.HOUR_OF_DAY, hourOfDay,
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1259
         *             Calendar.MINUTE, minute,
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1260
         *             Calendar.SECOND, second,
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1261
         *             Calendar.MILLISECOND, millis);</pre>
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1262
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1263
         * @param hourOfDay the {@link Calendar#HOUR_OF_DAY HOUR_OF_DAY} value
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1264
         *                  (24-hour clock)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1265
         * @param minute    the {@link Calendar#MINUTE MINUTE} value
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1266
         * @param second    the {@link Calendar#SECOND SECOND} value
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1267
         * @param millis    the {@link Calendar#MILLISECOND MILLISECOND} value
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1268
         * @return this {@code Calendar.Builder}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1269
         */
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1270
        public Builder setTimeOfDay(int hourOfDay, int minute, int second, int millis) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1271
            return setFields(HOUR_OF_DAY, hourOfDay, MINUTE, minute,
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1272
                             SECOND, second, MILLISECOND, millis);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1273
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1274
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1275
        /**
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1276
         * Sets the week-based date parameters to the values with the given
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1277
         * date specifiers - week year, week of year, and day of week.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1278
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1279
         * <p>If the specified calendar doesn't support week dates, the
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1280
         * {@link #build() build} method will throw an {@link IllegalArgumentException}.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1281
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1282
         * @param weekYear   the week year
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1283
         * @param weekOfYear the week number based on {@code weekYear}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1284
         * @param dayOfWeek  the day of week value: one of the constants
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1285
         *     for the {@link Calendar#DAY_OF_WEEK DAY_OF_WEEK} field:
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1286
         *     {@link Calendar#SUNDAY SUNDAY}, ..., {@link Calendar#SATURDAY SATURDAY}.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1287
         * @return this {@code Calendar.Builder}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1288
         * @see Calendar#setWeekDate(int, int, int)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1289
         * @see Calendar#isWeekDateSupported()
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1290
         */
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1291
        public Builder setWeekDate(int weekYear, int weekOfYear, int dayOfWeek) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1292
            allocateFields();
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1293
            internalSet(WEEK_YEAR, weekYear);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1294
            internalSet(WEEK_OF_YEAR, weekOfYear);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1295
            internalSet(DAY_OF_WEEK, dayOfWeek);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1296
            return this;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1297
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1298
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1299
        /**
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1300
         * Sets the time zone parameter to the given {@code zone}. If no time
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1301
         * zone parameter is given to this {@code Caledar.Builder}, the
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1302
         * {@linkplain TimeZone#getDefault() default
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1303
         * <code>TimeZone</code>} will be used in the {@link #build() build}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1304
         * method.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1305
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1306
         * @param zone the {@link TimeZone}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1307
         * @return this {@code Calendar.Builder}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1308
         * @throws NullPointerException if {@code zone} is {@code null}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1309
         * @see Calendar#setTimeZone(TimeZone)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1310
         */
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1311
        public Builder setTimeZone(TimeZone zone) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1312
            if (zone == null) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1313
                throw new NullPointerException();
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1314
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1315
            this.zone = zone;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1316
            return this;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1317
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1318
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1319
        /**
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1320
         * Sets the lenient mode parameter to the value given by {@code lenient}.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1321
         * If no lenient parameter is given to this {@code Calendar.Builder},
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1322
         * lenient mode will be used in the {@link #build() build} method.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1323
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1324
         * @param lenient {@code true} for lenient mode;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1325
         *                {@code false} for non-lenient mode
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1326
         * @return this {@code Calendar.Builder}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1327
         * @see Calendar#setLenient(boolean)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1328
         */
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1329
        public Builder setLenient(boolean lenient) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1330
            this.lenient = lenient;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1331
            return this;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1332
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1333
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1334
        /**
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1335
         * Sets the calendar type parameter to the given {@code type}. The
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1336
         * calendar type given by this method has precedence over any explicit
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1337
         * or implicit calendar type given by the
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1338
         * {@linkplain #setLocale(Locale) locale}.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1339
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1340
         * <p>In addition to the available calendar types returned by the
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1341
         * {@link Calendar#getAvailableCalendarTypes() Calendar.getAvailableCalendarTypes}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1342
         * method, {@code "gregorian"} and {@code "iso8601"} as aliases of
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1343
         * {@code "gregory"} can be used with this method.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1344
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1345
         * @param type the calendar type
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1346
         * @return this {@code Calendar.Builder}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1347
         * @throws NullPointerException if {@code type} is {@code null}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1348
         * @throws IllegalArgumentException if {@code type} is unknown
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1349
         * @throws IllegalStateException if another calendar type has already been set
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1350
         * @see Calendar#getCalendarType()
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1351
         * @see Calendar#getAvailableCalendarTypes()
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1352
         */
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1353
        public Builder setCalendarType(String type) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1354
            if (type.equals("gregorian")) { // NPE if type == null
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1355
                type = "gregory";
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1356
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1357
            if (!Calendar.getAvailableCalendarTypes().contains(type)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1358
                    && !type.equals("iso8601")) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1359
                throw new IllegalArgumentException("unknown calendar type: " + type);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1360
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1361
            if (this.type == null) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1362
                this.type = type;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1363
            } else {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1364
                if (!this.type.equals(type)) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1365
                    throw new IllegalStateException("calendar type override");
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1366
                }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1367
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1368
            return this;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1369
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1370
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1371
        /**
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1372
         * Sets the locale parameter to the given {@code locale}. If no locale
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1373
         * is given to this {@code Calendar.Builder}, the {@linkplain
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1374
         * Locale#getDefault(Locale.Category) default <code>Locale</code>}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1375
         * for {@link Locale.Category#FORMAT} will be used.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1376
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1377
         * <p>If no calendar type is explicitly given by a call to the
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1378
         * {@link #setCalendarType(String) setCalendarType} method,
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1379
         * the {@code Locale} value is used to determine what type of
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1380
         * {@code Calendar} to be built.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1381
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1382
         * <p>If no week definition parameters are explicitly given by a call to
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1383
         * the {@link #setWeekDefinition(int,int) setWeekDefinition} method, the
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1384
         * {@code Locale}'s default values are used.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1385
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1386
         * @param locale the {@link Locale}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1387
         * @throws NullPointerException if {@code locale} is {@code null}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1388
         * @return this {@code Calendar.Builder}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1389
         * @see Calendar#getInstance(Locale)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1390
         */
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1391
        public Builder setLocale(Locale locale) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1392
            if (locale == null) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1393
                throw new NullPointerException();
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1394
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1395
            this.locale = locale;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1396
            return this;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1397
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1398
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1399
        /**
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1400
         * Sets the week definition parameters to the values given by
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1401
         * {@code firstDayOfWeek} and {@code minimalDaysInFirstWeek} that are
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1402
         * used to determine the <a href="Calendar.html#First_Week">first
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1403
         * week</a> of a year. The parameters given by this method have
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1404
         * precedence over the default values given by the
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1405
         * {@linkplain #setLocale(Locale) locale}.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1406
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1407
         * @param firstDayOfWeek the first day of a week; one of
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1408
         *                       {@link Calendar#SUNDAY} to {@link Calendar#SATURDAY}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1409
         * @param minimalDaysInFirstWeek the minimal number of days in the first
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1410
         *                               week (1..7)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1411
         * @return this {@code Calendar.Builder}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1412
         * @throws IllegalArgumentException if {@code firstDayOfWeek} or
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1413
         *                                  {@code minimalDaysInFirstWeek} is invalid
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1414
         * @see Calendar#getFirstDayOfWeek()
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1415
         * @see Calendar#getMinimalDaysInFirstWeek()
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1416
         */
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1417
        public Builder setWeekDefinition(int firstDayOfWeek, int minimalDaysInFirstWeek) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1418
            if (!isValidWeekParameter(firstDayOfWeek)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1419
                    || !isValidWeekParameter(minimalDaysInFirstWeek)) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1420
                throw new IllegalArgumentException();
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1421
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1422
            this.firstDayOfWeek = firstDayOfWeek;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1423
            this.minimalDaysInFirstWeek = minimalDaysInFirstWeek;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1424
            return this;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1425
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1426
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1427
        /**
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1428
         * Returns a {@code Calendar} built from the parameters set by the
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1429
         * setter methods. The calendar type given by the {@link #setCalendarType(String)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1430
         * setCalendarType} method or the {@linkplain #setLocale(Locale) locale} is
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1431
         * used to determine what {@code Calendar} to be created. If no explicit
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1432
         * calendar type is given, the locale's default calendar is created.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1433
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1434
         * <p>If the calendar type is {@code "iso8601"}, the
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1435
         * {@linkplain GregorianCalendar#setGregorianChange(Date) Gregorian change date}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1436
         * of a {@link GregorianCalendar} is set to {@code Date(Long.MIN_VALUE)}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1437
         * to be the <em>proleptic</em> Gregorian calendar. Its week definition
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1438
         * parameters are also set to be <a
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1439
         * href="GregorianCalendar.html#iso8601_compatible_setting">compatible
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1440
         * with the ISO 8601 standard</a>. Note that the
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1441
         * {@link GregorianCalendar#getCalendarType() getCalendarType} method of
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1442
         * a {@code GregorianCalendar} created with {@code "iso8601"} returns
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1443
         * {@code "gregory"}.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1444
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1445
         * <p>The default values are used for locale and time zone if these
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1446
         * parameters haven't been given explicitly.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1447
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1448
         * <p>Any out of range field values are either normalized in lenient
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1449
         * mode or detected as an invalid value in non-lenient mode.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1450
         *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1451
         * @return a {@code Calendar} built with parameters of this {@code
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1452
         *         Calendar.Builder}
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1453
         * @throws IllegalArgumentException if the calendar type is unknown, or
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1454
         *             if any invalid field values are given in non-lenient mode, or
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1455
         *             if a week date is given for the calendar type that doesn't
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1456
         *             support week dates.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1457
         * @see Calendar#getInstance(TimeZone, Locale)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1458
         * @see Locale#getDefault(Locale.Category)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1459
         * @see TimeZone#getDefault()
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1460
         */
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1461
        public Calendar build() {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1462
            if (locale == null) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1463
                locale = Locale.getDefault();
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1464
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1465
            if (zone == null) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1466
                zone = TimeZone.getDefault();
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1467
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1468
            Calendar cal;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1469
            if (type == null) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1470
                type = locale.getUnicodeLocaleType("ca");
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1471
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1472
            if (type == null) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1473
                if (locale.getCountry() == "TH"
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1474
                    && locale.getLanguage() == "th") {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1475
                    type = "buddhist";
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1476
                } else {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1477
                    type = "gregory";
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1478
                }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1479
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1480
            switch (type) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1481
            case "gregory":
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1482
                cal = new GregorianCalendar(zone, locale, true);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1483
                break;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1484
            case "iso8601":
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1485
                GregorianCalendar gcal = new GregorianCalendar(zone, locale, true);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1486
                // make gcal a proleptic Gregorian
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1487
                gcal.setGregorianChange(new Date(Long.MIN_VALUE));
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1488
                // and week definition to be compatible with ISO 8601
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1489
                setWeekDefinition(MONDAY, 4);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1490
                cal = gcal;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1491
                break;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1492
            case "buddhist":
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1493
                cal = new BuddhistCalendar(zone, locale);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1494
                cal.clear();
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1495
                break;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1496
            case "japanese":
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1497
                cal = new JapaneseImperialCalendar(zone, locale, true);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1498
                break;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1499
            default:
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1500
                throw new IllegalArgumentException("unknown calendar type: " + type);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1501
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1502
            cal.setLenient(lenient);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1503
            if (firstDayOfWeek != 0) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1504
                cal.setFirstDayOfWeek(firstDayOfWeek);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1505
                cal.setMinimalDaysInFirstWeek(minimalDaysInFirstWeek);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1506
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1507
            if (isInstantSet()) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1508
                cal.setTimeInMillis(instant);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1509
                cal.complete();
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1510
                return cal;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1511
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1512
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1513
            if (fields != null) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1514
                boolean weekDate = isSet(WEEK_YEAR)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1515
                                       && fields[WEEK_YEAR] > fields[YEAR];
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1516
                if (weekDate && !cal.isWeekDateSupported()) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1517
                    throw new IllegalArgumentException("week date is unsupported by " + type);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1518
                }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1519
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1520
                // Set the fields from the min stamp to the max stamp so that
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1521
                // the fields resolution works in the Calendar.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1522
                for (int stamp = MINIMUM_USER_STAMP; stamp < nextStamp; stamp++) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1523
                    for (int index = 0; index <= maxFieldIndex; index++) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1524
                        if (fields[index] == stamp) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1525
                            cal.set(index, fields[NFIELDS + index]);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1526
                            break;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1527
                        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1528
                    }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1529
                }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1530
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1531
                if (weekDate) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1532
                    int weekOfYear = isSet(WEEK_OF_YEAR) ? fields[NFIELDS + WEEK_OF_YEAR] : 1;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1533
                    int dayOfWeek = isSet(DAY_OF_WEEK)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1534
                                    ? fields[NFIELDS + DAY_OF_WEEK] : cal.getFirstDayOfWeek();
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1535
                    cal.setWeekDate(fields[NFIELDS + WEEK_YEAR], weekOfYear, dayOfWeek);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1536
                }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1537
                cal.complete();
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1538
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1539
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1540
            return cal;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1541
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1542
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1543
        private void allocateFields() {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1544
            if (fields == null) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1545
                fields = new int[NFIELDS * 2];
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1546
                nextStamp = MINIMUM_USER_STAMP;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1547
                maxFieldIndex = -1;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1548
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1549
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1550
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1551
        private void internalSet(int field, int value) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1552
            fields[field] = nextStamp++;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1553
            if (nextStamp < 0) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1554
                throw new IllegalStateException("stamp counter overflow");
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1555
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1556
            fields[NFIELDS + field] = value;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1557
            if (field > maxFieldIndex && field < WEEK_YEAR) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1558
                maxFieldIndex = field;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1559
            }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1560
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1561
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1562
        private boolean isInstantSet() {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1563
            return nextStamp == COMPUTED;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1564
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1565
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1566
        private boolean isSet(int index) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1567
            return fields != null && fields[index] > UNSET;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1568
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1569
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1570
        private boolean isValidWeekParameter(int value) {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1571
            return value > 0 && value <= 7;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1572
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1573
    }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1574
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1575
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
     * Constructs a Calendar with the default time zone
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  1577
     * and the default {@link java.util.Locale.Category#FORMAT FORMAT}
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  1578
     * locale.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
     * @see     TimeZone#getDefault
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
    protected Calendar()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
    {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
  1583
        this(TimeZone.getDefaultRef(), Locale.getDefault(Locale.Category.FORMAT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
        sharedZone = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     * Constructs a calendar with the specified time zone and locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
     * @param zone the time zone to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
     * @param aLocale the locale for the week data
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
    protected Calendar(TimeZone zone, Locale aLocale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        fields = new int[FIELD_COUNT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
        isSet = new boolean[FIELD_COUNT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
        stamp = new int[FIELD_COUNT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
        this.zone = zone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
        setWeekCountData(aLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
     * Gets a calendar using the default time zone and locale. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
     * <code>Calendar</code> returned is based on the current time
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  1606
     * in the default time zone with the default
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  1607
     * {@link Locale.Category#FORMAT FORMAT} locale.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
     * @return a Calendar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
    public static Calendar getInstance()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
    {
16481
8e30386cc014 8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents: 16010
diff changeset
  1613
        return createCalendar(TimeZone.getDefault(), Locale.getDefault(Locale.Category.FORMAT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
     * Gets a calendar using the specified time zone and default locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
     * The <code>Calendar</code> returned is based on the current time
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  1619
     * in the given time zone with the default
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15658
diff changeset
  1620
     * {@link Locale.Category#FORMAT FORMAT} locale.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
     * @param zone the time zone to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
     * @return a Calendar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
    public static Calendar getInstance(TimeZone zone)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
    {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
  1627
        return createCalendar(zone, Locale.getDefault(Locale.Category.FORMAT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
     * Gets a calendar using the default time zone and specified locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
     * The <code>Calendar</code> returned is based on the current time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
     * in the default time zone with the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
     * @param aLocale the locale for the week data
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
     * @return a Calendar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
    public static Calendar getInstance(Locale aLocale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
    {
16481
8e30386cc014 8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents: 16010
diff changeset
  1640
        return createCalendar(TimeZone.getDefault(), aLocale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
     * Gets a calendar with the specified time zone and locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
     * The <code>Calendar</code> returned is based on the current time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
     * in the given time zone with the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
     * @param zone the time zone to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
     * @param aLocale the locale for the week data
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
     * @return a Calendar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
    public static Calendar getInstance(TimeZone zone,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                                       Locale aLocale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
        return createCalendar(zone, aLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
    private static Calendar createCalendar(TimeZone zone,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
                                           Locale aLocale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
    {
16481
8e30386cc014 8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents: 16010
diff changeset
  1661
        CalendarProvider provider =
8e30386cc014 8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents: 16010
diff changeset
  1662
            LocaleProviderAdapter.getAdapter(CalendarProvider.class, aLocale)
8e30386cc014 8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents: 16010
diff changeset
  1663
                                 .getCalendarProvider();
8e30386cc014 8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents: 16010
diff changeset
  1664
        if (provider != null) {
8e30386cc014 8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents: 16010
diff changeset
  1665
            try {
8e30386cc014 8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents: 16010
diff changeset
  1666
                return provider.getInstance(zone, aLocale);
8e30386cc014 8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents: 16010
diff changeset
  1667
            } catch (IllegalArgumentException iae) {
8e30386cc014 8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents: 16010
diff changeset
  1668
                // fall back to the default instantiation
8e30386cc014 8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents: 16010
diff changeset
  1669
            }
8e30386cc014 8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents: 16010
diff changeset
  1670
        }
8e30386cc014 8008576: Calendar mismatch using Host LocaleProviderAdapter
naoto
parents: 16010
diff changeset
  1671
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 6491
diff changeset
  1672
        Calendar cal = null;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 6491
diff changeset
  1673
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1674
        if (aLocale.hasExtensions()) {
15280
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  1675
            String caltype = aLocale.getUnicodeLocaleType("ca");
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1676
            if (caltype != null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1677
                switch (caltype) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1678
                case "buddhist":
7003
7d8d9506b4ee 6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents: 6501
diff changeset
  1679
                cal = new BuddhistCalendar(zone, aLocale);
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1680
                    break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1681
                case "japanese":
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1682
                    cal = new JapaneseImperialCalendar(zone, aLocale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1683
                    break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1684
                case "gregory":
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1685
                    cal = new GregorianCalendar(zone, aLocale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1686
                    break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1687
                }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1688
            }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1689
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1690
        if (cal == null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1691
            // If no known calendar type is explicitly specified,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1692
            // perform the traditional way to create a Calendar:
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1693
            // create a BuddhistCalendar for th_TH locale,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1694
            // a JapaneseImperialCalendar for ja_JP_JP locale, or
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1695
            // a GregorianCalendar for any other locales.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1696
            // NOTE: The language, country and variant strings are interned.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1697
            if (aLocale.getLanguage() == "th" && aLocale.getCountry() == "TH") {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1698
                cal = new BuddhistCalendar(zone, aLocale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1699
            } else if (aLocale.getVariant() == "JP" && aLocale.getLanguage() == "ja"
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1700
                       && aLocale.getCountry() == "JP") {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  1701
                cal = new JapaneseImperialCalendar(zone, aLocale);
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 6491
diff changeset
  1702
            } else {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 6491
diff changeset
  1703
                cal = new GregorianCalendar(zone, aLocale);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 6491
diff changeset
  1704
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        }
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 6491
diff changeset
  1706
        return cal;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
     * Returns an array of all locales for which the <code>getInstance</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
     * methods of this class can return localized instances.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
     * The array returned must contain at least a <code>Locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
     * instance equal to {@link java.util.Locale#US Locale.US}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
     * @return An array of locales for which localized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
     *         <code>Calendar</code> instances are available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
    public static synchronized Locale[] getAvailableLocales()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
        return DateFormat.getAvailableLocales();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
     * Converts the current calendar field values in {@link #fields fields[]}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
     * to the millisecond time value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
     * {@link #time}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
     * @see #complete()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
     * @see #computeFields()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
    protected abstract void computeTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
     * Converts the current millisecond time value {@link #time}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
     * to calendar field values in {@link #fields fields[]}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
     * This allows you to sync up the calendar field values with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
     * a new time that is set for the calendar.  The time is <em>not</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
     * recomputed first; to recompute the time, then the fields, call the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
     * {@link #complete()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
     * @see #computeTime()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
    protected abstract void computeFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
     * Returns a <code>Date</code> object representing this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
     * <code>Calendar</code>'s time value (millisecond offset from the <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
     * href="#Epoch">Epoch</a>").
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
     * @return a <code>Date</code> representing the time value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
     * @see #setTime(Date)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
     * @see #getTimeInMillis()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
    public final Date getTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
        return new Date(getTimeInMillis());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
     * Sets this Calendar's time with the given <code>Date</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
     * Note: Calling <code>setTime()</code> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
     * <code>Date(Long.MAX_VALUE)</code> or <code>Date(Long.MIN_VALUE)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
     * may yield incorrect field values from <code>get()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
     * @param date the given Date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
     * @see #getTime()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
     * @see #setTimeInMillis(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
    public final void setTime(Date date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
        setTimeInMillis(date.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
     * Returns this Calendar's time value in milliseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
     * @return the current time as UTC milliseconds from the epoch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
     * @see #getTime()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
     * @see #setTimeInMillis(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
    public long getTimeInMillis() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
        if (!isTimeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
            updateTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
        return time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
     * Sets this Calendar's current time from the given long value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
     * @param millis the new time in UTC milliseconds from the epoch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
     * @see #setTime(Date)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
     * @see #getTimeInMillis()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
    public void setTimeInMillis(long millis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
        // If we don't need to recalculate the calendar field values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
        // do nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
        if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
            && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
        time = millis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
        isTimeSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
        areFieldsSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
        computeFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
        areAllFieldsSet = areFieldsSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
     * Returns the value of the given calendar field. In lenient mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
     * all calendar fields are normalized. In non-lenient mode, all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
     * calendar fields are validated and this method throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
     * exception if any calendar fields have out-of-range values. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
     * normalization and validation are handled by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
     * {@link #complete()} method, which process is calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
     * system dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
     * @param field the given calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
     * @return the value for the given calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
     * @throws ArrayIndexOutOfBoundsException if the specified field is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
     *             (<code>field &lt; 0 || field &gt;= FIELD_COUNT</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
     * @see #set(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
     * @see #complete()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
    public int get(int field)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
        complete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
        return internalGet(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
     * Returns the value of the given calendar field. This method does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
     * not involve normalization or validation of the field value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
     * @param field the given calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
     * @return the value for the given calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
     * @see #get(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
    protected final int internalGet(int field)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
        return fields[field];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
     * Sets the value of the given calendar field. This method does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
     * not affect any setting state of the field in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
     * <code>Calendar</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
     * @throws IndexOutOfBoundsException if the specified field is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
     *             (<code>field &lt; 0 || field &gt;= FIELD_COUNT</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
     * @see #areFieldsSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
     * @see #isTimeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
     * @see #areAllFieldsSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
     * @see #set(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
    final void internalSet(int field, int value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
        fields[field] = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
     * Sets the given calendar field to the given value. The value is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     * interpreted by this method regardless of the leniency mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
     * @param field the given calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
     * @param value the value to be set for the given calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
     * @throws ArrayIndexOutOfBoundsException if the specified field is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
     *             (<code>field &lt; 0 || field &gt;= FIELD_COUNT</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
     * in non-lenient mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
     * @see #set(int,int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
     * @see #set(int,int,int,int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
     * @see #set(int,int,int,int,int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
     * @see #get(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
    public void set(int field, int value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
    {
1828
26bee4a3a499 6645263: (cal) Calendar throw java.lang.IllegalArgumentException: WEEK_OF_MONTH
peytoia
parents: 2
diff changeset
  1876
        // If the fields are partially normalized, calculate all the
26bee4a3a499 6645263: (cal) Calendar throw java.lang.IllegalArgumentException: WEEK_OF_MONTH
peytoia
parents: 2
diff changeset
  1877
        // fields before changing any fields.
26bee4a3a499 6645263: (cal) Calendar throw java.lang.IllegalArgumentException: WEEK_OF_MONTH
peytoia
parents: 2
diff changeset
  1878
        if (areFieldsSet && !areAllFieldsSet) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
            computeFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
        internalSet(field, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
        isTimeSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
        areFieldsSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
        isSet[field] = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
        stamp[field] = nextStamp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
        if (nextStamp == Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
            adjustStamp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
     * Sets the values for the calendar fields <code>YEAR</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
     * <code>MONTH</code>, and <code>DAY_OF_MONTH</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
     * Previous values of other calendar fields are retained.  If this is not desired,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
     * call {@link #clear()} first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
     * @param year the value used to set the <code>YEAR</code> calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
     * @param month the value used to set the <code>MONTH</code> calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
     * Month value is 0-based. e.g., 0 for January.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
     * @param date the value used to set the <code>DAY_OF_MONTH</code> calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
     * @see #set(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
     * @see #set(int,int,int,int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
     * @see #set(int,int,int,int,int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
    public final void set(int year, int month, int date)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
        set(YEAR, year);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
        set(MONTH, month);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
        set(DATE, date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
     * Sets the values for the calendar fields <code>YEAR</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
     * <code>MONTH</code>, <code>DAY_OF_MONTH</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
     * <code>HOUR_OF_DAY</code>, and <code>MINUTE</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
     * Previous values of other fields are retained.  If this is not desired,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
     * call {@link #clear()} first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
     * @param year the value used to set the <code>YEAR</code> calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
     * @param month the value used to set the <code>MONTH</code> calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
     * Month value is 0-based. e.g., 0 for January.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
     * @param date the value used to set the <code>DAY_OF_MONTH</code> calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
     * @param hourOfDay the value used to set the <code>HOUR_OF_DAY</code> calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
     * @param minute the value used to set the <code>MINUTE</code> calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
     * @see #set(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
     * @see #set(int,int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
     * @see #set(int,int,int,int,int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
    public final void set(int year, int month, int date, int hourOfDay, int minute)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
        set(YEAR, year);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
        set(MONTH, month);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
        set(DATE, date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
        set(HOUR_OF_DAY, hourOfDay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
        set(MINUTE, minute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
     * Sets the values for the fields <code>YEAR</code>, <code>MONTH</code>,
20502
33bb53f4ec14 8022666: java.util.Calendar.set(int,int,int,int,int,int) documentation typo
okutsu
parents: 18829
diff changeset
  1940
     * <code>DAY_OF_MONTH</code>, <code>HOUR_OF_DAY</code>, <code>MINUTE</code>, and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
     * <code>SECOND</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
     * Previous values of other fields are retained.  If this is not desired,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
     * call {@link #clear()} first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
     * @param year the value used to set the <code>YEAR</code> calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
     * @param month the value used to set the <code>MONTH</code> calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
     * Month value is 0-based. e.g., 0 for January.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
     * @param date the value used to set the <code>DAY_OF_MONTH</code> calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
     * @param hourOfDay the value used to set the <code>HOUR_OF_DAY</code> calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
     * @param minute the value used to set the <code>MINUTE</code> calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
     * @param second the value used to set the <code>SECOND</code> calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
     * @see #set(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
     * @see #set(int,int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
     * @see #set(int,int,int,int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
    public final void set(int year, int month, int date, int hourOfDay, int minute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
                          int second)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
        set(YEAR, year);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
        set(MONTH, month);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
        set(DATE, date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
        set(HOUR_OF_DAY, hourOfDay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
        set(MINUTE, minute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
        set(SECOND, second);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
     * Sets all the calendar field values and the time value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
     * (millisecond offset from the <a href="#Epoch">Epoch</a>) of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
     * this <code>Calendar</code> undefined. This means that {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
     * #isSet(int) isSet()} will return <code>false</code> for all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
     * calendar fields, and the date and time calculations will treat
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
     * the fields as if they had never been set. A
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
     * <code>Calendar</code> implementation class may use its specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
     * default field values for date/time calculations. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
     * <code>GregorianCalendar</code> uses 1970 if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
     * <code>YEAR</code> field value is undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
     * @see #clear(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
    public final void clear()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
        for (int i = 0; i < fields.length; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
            stamp[i] = fields[i] = 0; // UNSET == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
            isSet[i++] = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
        areAllFieldsSet = areFieldsSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
        isTimeSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
     * Sets the given calendar field value and the time value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
     * (millisecond offset from the <a href="#Epoch">Epoch</a>) of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
     * this <code>Calendar</code> undefined. This means that {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
     * #isSet(int) isSet(field)} will return <code>false</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
     * the date and time calculations will treat the field as if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
     * had never been set. A <code>Calendar</code> implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
     * class may use the field's specific default value for date and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
     * time calculations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
     * <p>The {@link #HOUR_OF_DAY}, {@link #HOUR} and {@link #AM_PM}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
     * fields are handled independently and the <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
     * href="#time_resolution">the resolution rule for the time of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
     * day</a> is applied. Clearing one of the fields doesn't reset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
     * the hour of day value of this <code>Calendar</code>. Use {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
     * #set(int,int) set(Calendar.HOUR_OF_DAY, 0)} to reset the hour
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
     * value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
     * @param field the calendar field to be cleared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
     * @see #clear()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
    public final void clear(int field)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
        fields[field] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
        stamp[field] = UNSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
        isSet[field] = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
        areAllFieldsSet = areFieldsSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
        isTimeSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
     * Determines if the given calendar field has a value set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
     * including cases that the value has been set by internal fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
     * calculations triggered by a <code>get</code> method call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
     *
18829
ec84f0c313b0 8020409: Clean up doclint problems in java.util package, part 1
bpb
parents: 18156
diff changeset
  2027
     * @param field the calendar field to test
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
     * @return <code>true</code> if the given calendar field has a value set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
     * <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
    public final boolean isSet(int field)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
        return stamp[field] != UNSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
     * Returns the string representation of the calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
     * <code>field</code> value in the given <code>style</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
     * <code>locale</code>.  If no string representation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
     * applicable, <code>null</code> is returned. This method calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
     * {@link Calendar#get(int) get(field)} to get the calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
     * <code>field</code> value if the string representation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
     * applicable to the given calendar <code>field</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
     * <p>For example, if this <code>Calendar</code> is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
     * <code>GregorianCalendar</code> and its date is 2005-01-01, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
     * the string representation of the {@link #MONTH} field would be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
     * "January" in the long style in an English locale or "Jan" in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
     * the short style. However, no string representation would be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
     * available for the {@link #DAY_OF_MONTH} field, and this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
     * would return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
     * <p>The default implementation supports the calendar fields for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
     * which a {@link DateFormatSymbols} has names in the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
     * <code>locale</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
     * @param field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
     *        the calendar field for which the string representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
     *        is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
     * @param style
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2061
     *        the style applied to the string representation; one of {@link
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2062
     *        #SHORT_FORMAT} ({@link #SHORT}), {@link #SHORT_STANDALONE},
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2063
     *        {@link #LONG_FORMAT} ({@link #LONG}), {@link #LONG_STANDALONE},
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2064
     *        {@link #NARROW_FORMAT}, or {@link #NARROW_STANDALONE}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
     * @param locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
     *        the locale for the string representation
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2067
     *        (any calendar types specified by {@code locale} are ignored)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
     * @return the string representation of the given
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2069
     *        {@code field} in the given {@code style}, or
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2070
     *        {@code null} if no string representation is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
     *        applicable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
     * @exception IllegalArgumentException
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2073
     *        if {@code field} or {@code style} is invalid,
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2074
     *        or if this {@code Calendar} is non-lenient and any
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
     *        of the calendar fields have invalid values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
     * @exception NullPointerException
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2077
     *        if {@code locale} is null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
    public String getDisplayName(int field, int style, Locale locale) {
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2081
        if (!checkDisplayNameParams(field, style, SHORT, NARROW_FORMAT, locale,
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2082
                            ERA_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2086
        // the standalone and narrow styles are supported only through CalendarDataProviders.
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2087
        if (isStandaloneStyle(style) || isNarrowStyle(style)) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2088
            return CalendarDataUtility.retrieveFieldValueName(getCalendarType(),
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2089
                                                              field, get(field),
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2090
                                                              style, locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2091
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2092
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
        DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
        String[] strings = getFieldStrings(field, style, symbols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
        if (strings != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
            int fieldValue = get(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
            if (fieldValue < strings.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
                return strings[fieldValue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
    /**
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2105
     * Returns a {@code Map} containing all names of the calendar
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2106
     * {@code field} in the given {@code style} and
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2107
     * {@code locale} and their corresponding field values. For
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2108
     * example, if this {@code Calendar} is a {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
     * GregorianCalendar}, the returned map would contain "Jan" to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
     * {@link #JANUARY}, "Feb" to {@link #FEBRUARY}, and so on, in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
     * {@linkplain #SHORT short} style in an English locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
     *
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2113
     * <p>Narrow names may not be unique due to use of single characters,
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2114
     * such as "S" for Sunday and Saturday. In that case narrow names are not
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2115
     * included in the returned {@code Map}.
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2116
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
     * <p>The values of other calendar fields may be taken into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
     * account to determine a set of display names. For example, if
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2119
     * this {@code Calendar} is a lunisolar calendar system and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
     * the year value given by the {@link #YEAR} field has a leap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
     * month, this method would return month names containing the leap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
     * month name, and month names are mapped to their values specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
     * for the year.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
     * <p>The default implementation supports display names contained in
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2126
     * a {@link DateFormatSymbols}. For example, if {@code field}
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2127
     * is {@link #MONTH} and {@code style} is {@link
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2128
     * #ALL_STYLES}, this method returns a {@code Map} containing
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
     * all strings returned by {@link DateFormatSymbols#getShortMonths()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
     * and {@link DateFormatSymbols#getMonths()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
     * @param field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
     *        the calendar field for which the display names are returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
     * @param style
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2135
     *        the style applied to the string representation; one of {@link
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2136
     *        #SHORT_FORMAT} ({@link #SHORT}), {@link #SHORT_STANDALONE},
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2137
     *        {@link #LONG_FORMAT} ({@link #LONG}), {@link #LONG_STANDALONE},
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2138
     *        {@link #NARROW_FORMAT}, or {@link #NARROW_STANDALONE}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
     * @param locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
     *        the locale for the display names
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2141
     * @return a {@code Map} containing all display names in
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2142
     *        {@code style} and {@code locale} and their
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2143
     *        field values, or {@code null} if no display names
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2144
     *        are defined for {@code field}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
     * @exception IllegalArgumentException
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2146
     *        if {@code field} or {@code style} is invalid,
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2147
     *        or if this {@code Calendar} is non-lenient and any
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
     *        of the calendar fields have invalid values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
     * @exception NullPointerException
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2150
     *        if {@code locale} is null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
    public Map<String, Integer> getDisplayNames(int field, int style, Locale locale) {
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2154
        if (!checkDisplayNameParams(field, style, ALL_STYLES, NARROW_FORMAT, locale,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
                                    ERA_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
        }
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2158
        if (style == ALL_STYLES || isStandaloneStyle(style)) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2159
            return CalendarDataUtility.retrieveFieldValueNames(getCalendarType(), field, style, locale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
        }
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2161
        // SHORT, LONG, or NARROW
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
        return getDisplayNamesImpl(field, style, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
    private Map<String,Integer> getDisplayNamesImpl(int field, int style, Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
        DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
        String[] strings = getFieldStrings(field, style, symbols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
        if (strings != null) {
12448
b95438b17098 7157893: Warnings Cleanup in java.util.*
khazra
parents: 11681
diff changeset
  2169
            Map<String,Integer> names = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
            for (int i = 0; i < strings.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
                if (strings[i].length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
                names.put(strings[i], i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
            return names;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
    boolean checkDisplayNameParams(int field, int style, int minStyle, int maxStyle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
                                   Locale locale, int fieldMask) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2183
        int baseStyle = getBaseStyle(style); // Ignore the standalone mask
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
        if (field < 0 || field >= fields.length ||
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2185
            baseStyle < minStyle || baseStyle > maxStyle) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
        if (locale == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
        return isFieldSet(fieldMask, field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
    private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2195
        int baseStyle = getBaseStyle(style); // ignore the standalone mask
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2196
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2197
        // DateFormatSymbols doesn't support any narrow names.
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2198
        if (baseStyle == NARROW_FORMAT) {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2199
            return null;
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2200
        }
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2201
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
        String[] strings = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
        switch (field) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
        case ERA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
            strings = symbols.getEras();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
        case MONTH:
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2209
            strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
        case DAY_OF_WEEK:
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2213
            strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
        case AM_PM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
            strings = symbols.getAmPmStrings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
        return strings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
     * Fills in any unset fields in the calendar fields. First, the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
     * #computeTime()} method is called if the time value (millisecond offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
     * from the <a href="#Epoch">Epoch</a>) has not been calculated from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
     * calendar field values. Then, the {@link #computeFields()} method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
     * called to calculate all calendar field values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
    protected void complete()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
    {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2232
        if (!isTimeSet) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
            updateTime();
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2234
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
        if (!areFieldsSet || !areAllFieldsSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
            computeFields(); // fills in unset fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
            areAllFieldsSet = areFieldsSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
     * Returns whether the value of the specified calendar field has been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
     * externally by calling one of the setter methods rather than by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
     * internal time calculation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
     * @return <code>true</code> if the field has been set externally,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
     * <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
     * @exception IndexOutOfBoundsException if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
     *                <code>field</code> is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
     *               (<code>field &lt; 0 || field &gt;= FIELD_COUNT</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
     * @see #selectFields()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
     * @see #setFieldsComputed(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
    final boolean isExternallySet(int field) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
        return stamp[field] >= MINIMUM_USER_STAMP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
     * Returns a field mask (bit mask) indicating all calendar fields that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
     * have the state of externally or internally set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
     * @return a bit mask indicating set state fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
    final int getSetStateFields() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
        int mask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
        for (int i = 0; i < fields.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
            if (stamp[i] != UNSET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
                mask |= 1 << i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
        return mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
     * Sets the state of the specified calendar fields to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
     * <em>computed</em>. This state means that the specified calendar fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
     * have valid values that have been set by internal time calculation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
     * rather than by calling one of the setter methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
     * @param fieldMask the field to be marked as computed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
     * @exception IndexOutOfBoundsException if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
     *                <code>field</code> is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
     *               (<code>field &lt; 0 || field &gt;= FIELD_COUNT</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
     * @see #isExternallySet(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
     * @see #selectFields()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
    final void setFieldsComputed(int fieldMask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
        if (fieldMask == ALL_FIELDS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
            for (int i = 0; i < fields.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
                stamp[i] = COMPUTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
                isSet[i] = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
            areFieldsSet = areAllFieldsSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
            for (int i = 0; i < fields.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
                if ((fieldMask & 1) == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
                    stamp[i] = COMPUTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
                    isSet[i] = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
                    if (areAllFieldsSet && !isSet[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
                        areAllFieldsSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
                fieldMask >>>= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
     * Sets the state of the calendar fields that are <em>not</em> specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
     * by <code>fieldMask</code> to <em>unset</em>. If <code>fieldMask</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
     * specifies all the calendar fields, then the state of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
     * <code>Calendar</code> becomes that all the calendar fields are in sync
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
     * with the time value (millisecond offset from the Epoch).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
     * @param fieldMask the field mask indicating which calendar fields are in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
     * sync with the time value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
     * @exception IndexOutOfBoundsException if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
     *                <code>field</code> is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
     *               (<code>field &lt; 0 || field &gt;= FIELD_COUNT</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
     * @see #isExternallySet(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
     * @see #selectFields()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
    final void setFieldsNormalized(int fieldMask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
        if (fieldMask != ALL_FIELDS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
            for (int i = 0; i < fields.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
                if ((fieldMask & 1) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
                    stamp[i] = fields[i] = 0; // UNSET == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
                    isSet[i] = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
                fieldMask >>= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
        // Some or all of the fields are in sync with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
        // milliseconds, but the stamp values are not normalized yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
        areFieldsSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
        areAllFieldsSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
     * Returns whether the calendar fields are partially in sync with the time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
     * value or fully in sync but not stamp values are not normalized yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
    final boolean isPartiallyNormalized() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
        return areFieldsSet && !areAllFieldsSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
     * Returns whether the calendar fields are fully in sync with the time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
     * value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
    final boolean isFullyNormalized() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
        return areFieldsSet && areAllFieldsSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
     * Marks this Calendar as not sync'd.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
    final void setUnnormalized() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
        areFieldsSet = areAllFieldsSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
     * Returns whether the specified <code>field</code> is on in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
     * <code>fieldMask</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2368
    static boolean isFieldSet(int fieldMask, int field) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
        return (fieldMask & (1 << field)) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
     * Returns a field mask indicating which calendar field values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
     * to be used to calculate the time value. The calendar fields are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
     * returned as a bit mask, each bit of which corresponds to a field, i.e.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
     * the mask value of <code>field</code> is <code>(1 &lt;&lt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
     * field)</code>. For example, 0x26 represents the <code>YEAR</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
     * <code>MONTH</code>, and <code>DAY_OF_MONTH</code> fields (i.e., 0x26 is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
     * equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
     * <code>(1&lt;&lt;YEAR)|(1&lt;&lt;MONTH)|(1&lt;&lt;DAY_OF_MONTH))</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
     * <p>This method supports the calendar fields resolution as described in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
     * the class description. If the bit mask for a given field is on and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
     * field has not been set (i.e., <code>isSet(field)</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
     * <code>false</code>), then the default value of the field has to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
     * used, which case means that the field has been selected because the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
     * selected combination involves the field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
     * @return a bit mask of selected fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
     * @see #isExternallySet(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
    final int selectFields() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
        // This implementation has been taken from the GregorianCalendar class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
        // The YEAR field must always be used regardless of its SET
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
        // state because YEAR is a mandatory field to determine the date
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
        // and the default value (EPOCH_YEAR) may change through the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
        // normalization process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
        int fieldMask = YEAR_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
        if (stamp[ERA] != UNSET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
            fieldMask |= ERA_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
        // Find the most recent group of fields specifying the day within
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
        // the year.  These may be any of the following combinations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
        //   MONTH + DAY_OF_MONTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
        //   MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
        //   MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
        //   DAY_OF_YEAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
        //   WEEK_OF_YEAR + DAY_OF_WEEK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
        // We look for the most recent of the fields in each group to determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
        // the age of the group.  For groups involving a week-related field such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
        // as WEEK_OF_MONTH, DAY_OF_WEEK_IN_MONTH, or WEEK_OF_YEAR, both the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
        // week-related field and the DAY_OF_WEEK must be set for the group as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
        // whole to be considered.  (See bug 4153860 - liu 7/24/98.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
        int dowStamp = stamp[DAY_OF_WEEK];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
        int monthStamp = stamp[MONTH];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
        int domStamp = stamp[DAY_OF_MONTH];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
        int womStamp = aggregateStamp(stamp[WEEK_OF_MONTH], dowStamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
        int dowimStamp = aggregateStamp(stamp[DAY_OF_WEEK_IN_MONTH], dowStamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
        int doyStamp = stamp[DAY_OF_YEAR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
        int woyStamp = aggregateStamp(stamp[WEEK_OF_YEAR], dowStamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
        int bestStamp = domStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
        if (womStamp > bestStamp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
            bestStamp = womStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
        if (dowimStamp > bestStamp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
            bestStamp = dowimStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
        if (doyStamp > bestStamp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
            bestStamp = doyStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
        if (woyStamp > bestStamp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
            bestStamp = woyStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
        /* No complete combination exists.  Look for WEEK_OF_MONTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
         * DAY_OF_WEEK_IN_MONTH, or WEEK_OF_YEAR alone.  Treat DAY_OF_WEEK alone
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
         * as DAY_OF_WEEK_IN_MONTH.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
        if (bestStamp == UNSET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
            womStamp = stamp[WEEK_OF_MONTH];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
            dowimStamp = Math.max(stamp[DAY_OF_WEEK_IN_MONTH], dowStamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
            woyStamp = stamp[WEEK_OF_YEAR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
            bestStamp = Math.max(Math.max(womStamp, dowimStamp), woyStamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
            /* Treat MONTH alone or no fields at all as DAY_OF_MONTH.  This may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
             * result in bestStamp = domStamp = UNSET if no fields are set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
             * which indicates DAY_OF_MONTH.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
            if (bestStamp == UNSET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
                bestStamp = domStamp = monthStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
        if (bestStamp == domStamp ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
           (bestStamp == womStamp && stamp[WEEK_OF_MONTH] >= stamp[WEEK_OF_YEAR]) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
           (bestStamp == dowimStamp && stamp[DAY_OF_WEEK_IN_MONTH] >= stamp[WEEK_OF_YEAR])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
            fieldMask |= MONTH_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
            if (bestStamp == domStamp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
                fieldMask |= DAY_OF_MONTH_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
                assert (bestStamp == womStamp || bestStamp == dowimStamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
                if (dowStamp != UNSET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
                    fieldMask |= DAY_OF_WEEK_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
                if (womStamp == dowimStamp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
                    // When they are equal, give the priority to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
                    // WEEK_OF_MONTH for compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
                    if (stamp[WEEK_OF_MONTH] >= stamp[DAY_OF_WEEK_IN_MONTH]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
                        fieldMask |= WEEK_OF_MONTH_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
                        fieldMask |= DAY_OF_WEEK_IN_MONTH_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
                    if (bestStamp == womStamp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
                        fieldMask |= WEEK_OF_MONTH_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
                        assert (bestStamp == dowimStamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
                        if (stamp[DAY_OF_WEEK_IN_MONTH] != UNSET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
                            fieldMask |= DAY_OF_WEEK_IN_MONTH_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
            assert (bestStamp == doyStamp || bestStamp == woyStamp ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
                    bestStamp == UNSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
            if (bestStamp == doyStamp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
                fieldMask |= DAY_OF_YEAR_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
                assert (bestStamp == woyStamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
                if (dowStamp != UNSET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
                    fieldMask |= DAY_OF_WEEK_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
                fieldMask |= WEEK_OF_YEAR_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
        // Find the best set of fields specifying the time of day.  There
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
        // are only two possibilities here; the HOUR_OF_DAY or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
        // AM_PM and the HOUR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
        int hourOfDayStamp = stamp[HOUR_OF_DAY];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
        int hourStamp = aggregateStamp(stamp[HOUR], stamp[AM_PM]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
        bestStamp = (hourStamp > hourOfDayStamp) ? hourStamp : hourOfDayStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
        // if bestStamp is still UNSET, then take HOUR or AM_PM. (See 4846659)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
        if (bestStamp == UNSET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
            bestStamp = Math.max(stamp[HOUR], stamp[AM_PM]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
        // Hours
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
        if (bestStamp != UNSET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
            if (bestStamp == hourOfDayStamp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
                fieldMask |= HOUR_OF_DAY_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
                fieldMask |= HOUR_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
                if (stamp[AM_PM] != UNSET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
                    fieldMask |= AM_PM_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
        if (stamp[MINUTE] != UNSET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
            fieldMask |= MINUTE_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
        if (stamp[SECOND] != UNSET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
            fieldMask |= SECOND_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
        if (stamp[MILLISECOND] != UNSET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
            fieldMask |= MILLISECOND_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
        if (stamp[ZONE_OFFSET] >= MINIMUM_USER_STAMP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
                fieldMask |= ZONE_OFFSET_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
        if (stamp[DST_OFFSET] >= MINIMUM_USER_STAMP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
            fieldMask |= DST_OFFSET_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
        return fieldMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2543
    int getBaseStyle(int style) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2544
        return style & ~STANDALONE_MASK;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2545
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2546
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2547
    boolean isStandaloneStyle(int style) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2548
        return (style & STANDALONE_MASK) != 0;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2549
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2550
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2551
    boolean isNarrowStyle(int style) {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2552
        return style == NARROW_FORMAT || style == NARROW_STANDALONE;
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2553
    }
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14502
diff changeset
  2554
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
     * Returns the pseudo-time-stamp for two fields, given their
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
     * individual pseudo-time-stamps.  If either of the fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
     * is unset, then the aggregate is unset.  Otherwise, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
     * aggregate is the later of the two stamps.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2561
    private static int aggregateStamp(int stamp_a, int stamp_b) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
        if (stamp_a == UNSET || stamp_b == UNSET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
            return UNSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
        return (stamp_a > stamp_b) ? stamp_a : stamp_b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
    /**
15280
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2569
     * Returns an unmodifiable {@code Set} containing all calendar types
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2570
     * supported by {@code Calendar} in the runtime environment. The available
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2571
     * calendar types can be used for the <a
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2572
     * href="Locale.html#def_locale_extension">Unicode locale extensions</a>.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2573
     * The {@code Set} returned contains at least {@code "gregory"}. The
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2574
     * calendar types don't include aliases, such as {@code "gregorian"} for
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2575
     * {@code "gregory"}.
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2576
     *
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2577
     * @return an unmodifiable {@code Set} containing all available calendar types
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2578
     * @since 1.8
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2579
     * @see #getCalendarType()
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2580
     * @see Calendar.Builder#setCalendarType(String)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2581
     * @see Locale#getUnicodeLocaleType(String)
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2582
     */
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2583
    public static Set<String> getAvailableCalendarTypes() {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2584
        return AvailableCalendarTypes.SET;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2585
    }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2586
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2587
    private static class AvailableCalendarTypes {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2588
        private static final Set<String> SET;
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2589
        static {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2590
            Set<String> set = new HashSet<>(3);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2591
            set.add("gregory");
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2592
            set.add("buddhist");
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2593
            set.add("japanese");
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2594
            SET = Collections.unmodifiableSet(set);
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2595
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2596
        private AvailableCalendarTypes() {
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2597
        }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2598
    }
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2599
d9e473e85f3c 4745761: (cal) RFE: Support builder for constructing Calendar
okutsu
parents: 14928
diff changeset
  2600
    /**
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2601
     * Returns the calendar type of this {@code Calendar}. Calendar types are
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2602
     * defined by the <em>Unicode Locale Data Markup Language (LDML)</em>
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2603
     * specification.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2604
     *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2605
     * <p>The default implementation of this method returns the class name of
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2606
     * this {@code Calendar} instance. Any subclasses that implement
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2607
     * LDML-defined calendar systems should override this method to return
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2608
     * appropriate calendar types.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2609
     *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2610
     * @return the LDML-defined calendar type or the class name of this
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2611
     *         {@code Calendar} instance
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2612
     * @since 1.8
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2613
     * @see <a href="Locale.html#def_extensions">Locale extensions</a>
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2614
     * @see Locale.Builder#setLocale(Locale)
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2615
     * @see Locale.Builder#setUnicodeLocaleKeyword(String, String)
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2616
     */
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2617
    public String getCalendarType() {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2618
        return this.getClass().getName();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2619
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2620
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2621
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
     * Compares this <code>Calendar</code> to the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
     * <code>Object</code>.  The result is <code>true</code> if and only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
     * the argument is a <code>Calendar</code> object of the same calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
     * system that represents the same time value (millisecond offset from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
     * <a href="#Epoch">Epoch</a>) under the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
     * <code>Calendar</code> parameters as this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
     * <p>The <code>Calendar</code> parameters are the values represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
     * by the <code>isLenient</code>, <code>getFirstDayOfWeek</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
     * <code>getMinimalDaysInFirstWeek</code> and <code>getTimeZone</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
     * methods. If there is any difference in those parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
     * between the two <code>Calendar</code>s, this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
     * <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
     * <p>Use the {@link #compareTo(Calendar) compareTo} method to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
     * compare only the time values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
     * @param obj the object to compare with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
     * @return <code>true</code> if this object is equal to <code>obj</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
     * <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2643
    @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2644
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
    public boolean equals(Object obj) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2646
        if (this == obj) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
            return true;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2648
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
            Calendar that = (Calendar)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
            return compareTo(getMillisOf(that)) == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
                lenient == that.lenient &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
                firstDayOfWeek == that.firstDayOfWeek &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
                minimalDaysInFirstWeek == that.minimalDaysInFirstWeek &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
                zone.equals(that.zone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
            // Note: GregorianCalendar.computeTime throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
            // IllegalArgumentException if the ERA value is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
            // even it's in lenient mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
     * Returns a hash code for this calendar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
     * @return a hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2670
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
        // 'otheritems' represents the hash code for the previous versions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
        int otheritems = (lenient ? 1 : 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
            | (firstDayOfWeek << 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
            | (minimalDaysInFirstWeek << 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
            | (zone.hashCode() << 7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
        long t = getMillisOf(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
        return (int) t ^ (int)(t >> 32) ^ otheritems;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
     * Returns whether this <code>Calendar</code> represents a time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
     * before the time represented by the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
     * <code>Object</code>. This method is equivalent to:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 16481
diff changeset
  2685
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
     *         compareTo(when) < 0
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 16481
diff changeset
  2687
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
     * if and only if <code>when</code> is a <code>Calendar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
     * instance. Otherwise, the method returns <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
     * @param when the <code>Object</code> to be compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
     * @return <code>true</code> if the time of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
     * <code>Calendar</code> is before the time represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
     * <code>when</code>; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
     * @see     #compareTo(Calendar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
    public boolean before(Object when) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
        return when instanceof Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
            && compareTo((Calendar)when) < 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
     * Returns whether this <code>Calendar</code> represents a time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
     * after the time represented by the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
     * <code>Object</code>. This method is equivalent to:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 16481
diff changeset
  2706
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
     *         compareTo(when) > 0
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 16481
diff changeset
  2708
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
     * if and only if <code>when</code> is a <code>Calendar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
     * instance. Otherwise, the method returns <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
     * @param when the <code>Object</code> to be compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
     * @return <code>true</code> if the time of this <code>Calendar</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
     * after the time represented by <code>when</code>; <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
     * otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
     * @see     #compareTo(Calendar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
    public boolean after(Object when) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
        return when instanceof Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
            && compareTo((Calendar)when) > 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
     * Compares the time values (millisecond offsets from the <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
     * href="#Epoch">Epoch</a>) represented by two
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
     * <code>Calendar</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
     * @param anotherCalendar the <code>Calendar</code> to be compared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
     * @return the value <code>0</code> if the time represented by the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
     * is equal to the time represented by this <code>Calendar</code>; a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
     * less than <code>0</code> if the time of this <code>Calendar</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
     * before the time represented by the argument; and a value greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
     * <code>0</code> if the time of this <code>Calendar</code> is after the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
     * time represented by the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
     * @exception NullPointerException if the specified <code>Calendar</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
     *            <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
     * @exception IllegalArgumentException if the time value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
     * specified <code>Calendar</code> object can't be obtained due to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
     * any invalid calendar values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
     * @since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  2742
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
    public int compareTo(Calendar anotherCalendar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
        return compareTo(getMillisOf(anotherCalendar));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
     * Adds or subtracts the specified amount of time to the given calendar field,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
     * based on the calendar's rules. For example, to subtract 5 days from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
     * the current time of the calendar, you can achieve it by calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
     * <p><code>add(Calendar.DAY_OF_MONTH, -5)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
     * @param field the calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
     * @param amount the amount of date or time to be added to the field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
     * @see #roll(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
     * @see #set(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
    abstract public void add(int field, int amount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
     * Adds or subtracts (up/down) a single unit of time on the given time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
     * field without changing larger fields. For example, to roll the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
     * date up by one day, you can achieve it by calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
     * <p>roll(Calendar.DATE, true).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
     * When rolling on the year or Calendar.YEAR field, it will roll the year
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
     * value in the range between 1 and the value returned by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
     * <code>getMaximum(Calendar.YEAR)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
     * When rolling on the month or Calendar.MONTH field, other fields like
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
     * date might conflict and, need to be changed. For instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
     * rolling the month on the date 01/31/96 will result in 02/29/96.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
     * When rolling on the hour-in-day or Calendar.HOUR_OF_DAY field, it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
     * roll the hour value in the range between 0 and 23, which is zero-based.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
     * @param field the time field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
     * @param up indicates if the value of the specified time field is to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
     * rolled up or rolled down. Use true if rolling up, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
     * @see Calendar#add(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
     * @see Calendar#set(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
    abstract public void roll(int field, boolean up);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
     * Adds the specified (signed) amount to the specified calendar field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
     * without changing larger fields.  A negative amount means to roll
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
     * down.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
     * <p>NOTE:  This default implementation on <code>Calendar</code> just repeatedly calls the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
     * version of {@link #roll(int,boolean) roll()} that rolls by one unit.  This may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
     * always do the right thing.  For example, if the <code>DAY_OF_MONTH</code> field is 31,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
     * rolling through February will leave it set to 28.  The <code>GregorianCalendar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
     * version of this function takes care of this problem.  Other subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
     * should also provide overrides of this function that do the right thing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
     * @param field the calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
     * @param amount the signed amount to add to the calendar <code>field</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
     * @see #roll(int,boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
     * @see #add(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
     * @see #set(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
    public void roll(int field, int amount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
        while (amount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
            roll(field, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
            amount--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
        while (amount < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
            roll(field, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
            amount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
     * Sets the time zone with the given time zone value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
     * @param value the given time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
    public void setTimeZone(TimeZone value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
        zone = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
        sharedZone = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
        /* Recompute the fields from the time using the new zone.  This also
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
         * works if isTimeSet is false (after a call to set()).  In that case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
         * the time will be computed from the fields using the new zone, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
         * the fields will get recomputed from that.  Consider the sequence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
         * calls: cal.setTimeZone(EST); cal.set(HOUR, 1); cal.setTimeZone(PST).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
         * Is cal set to 1 o'clock EST or 1 o'clock PST?  Answer: PST.  More
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
         * generally, a call to setTimeZone() affects calls to set() BEFORE AND
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
         * AFTER it up to the next call to complete().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
        areAllFieldsSet = areFieldsSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
     * Gets the time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
     * @return the time zone object associated with this calendar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
    public TimeZone getTimeZone()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
        // If the TimeZone object is shared by other Calendar instances, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
        // create a clone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
        if (sharedZone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
            zone = (TimeZone) zone.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
            sharedZone = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
        return zone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
     * Returns the time zone (without cloning).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
    TimeZone getZone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
        return zone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
     * Sets the sharedZone flag to <code>shared</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
    void setZoneShared(boolean shared) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
        sharedZone = shared;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
     * Specifies whether or not date/time interpretation is to be lenient.  With
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
     * lenient interpretation, a date such as "February 942, 1996" will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
     * treated as being equivalent to the 941st day after February 1, 1996.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
     * With strict (non-lenient) interpretation, such dates will cause an exception to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
     * thrown. The default is lenient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
     * @param lenient <code>true</code> if the lenient mode is to be turned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
     * on; <code>false</code> if it is to be turned off.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
     * @see #isLenient()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
     * @see java.text.DateFormat#setLenient
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
    public void setLenient(boolean lenient)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
        this.lenient = lenient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
     * Tells whether date/time interpretation is to be lenient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
     * @return <code>true</code> if the interpretation mode of this calendar is lenient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
     * <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
     * @see #setLenient(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
    public boolean isLenient()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
        return lenient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
     * Sets what the first day of the week is; e.g., <code>SUNDAY</code> in the U.S.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
     * <code>MONDAY</code> in France.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
     * @param value the given first day of the week.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
     * @see #getFirstDayOfWeek()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
     * @see #getMinimalDaysInFirstWeek()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
    public void setFirstDayOfWeek(int value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
        if (firstDayOfWeek == value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
        firstDayOfWeek = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
        invalidateWeekFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
     * Gets what the first day of the week is; e.g., <code>SUNDAY</code> in the U.S.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
     * <code>MONDAY</code> in France.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
     * @return the first day of the week.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
     * @see #setFirstDayOfWeek(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
     * @see #getMinimalDaysInFirstWeek()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
    public int getFirstDayOfWeek()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
        return firstDayOfWeek;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
     * Sets what the minimal days required in the first week of the year are;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
     * For example, if the first week is defined as one that contains the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
     * day of the first month of a year, call this method with value 1. If it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
     * must be a full week, use value 7.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
     * @param value the given minimal days required in the first week
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
     * of the year.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
     * @see #getMinimalDaysInFirstWeek()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
    public void setMinimalDaysInFirstWeek(int value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
        if (minimalDaysInFirstWeek == value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
        minimalDaysInFirstWeek = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
        invalidateWeekFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
     * Gets what the minimal days required in the first week of the year are;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
     * e.g., if the first week is defined as one that contains the first day
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
     * of the first month of a year, this method returns 1. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
     * the minimal days required must be a full week, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
     * returns 7.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
     * @return the minimal days required in the first week of the year.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
     * @see #setMinimalDaysInFirstWeek(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
    public int getMinimalDaysInFirstWeek()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
        return minimalDaysInFirstWeek;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
    /**
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2958
     * Returns whether this {@code Calendar} supports week dates.
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2959
     *
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2960
     * <p>The default implementation of this method returns {@code false}.
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2961
     *
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2962
     * @return {@code true} if this {@code Calendar} supports week dates;
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2963
     *         {@code false} otherwise.
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2964
     * @see #getWeekYear()
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2965
     * @see #setWeekDate(int,int,int)
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2966
     * @see #getWeeksInWeekYear()
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2967
     * @since 1.7
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2968
     */
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2969
    public boolean isWeekDateSupported() {
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2970
        return false;
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2971
    }
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2972
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2973
    /**
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2974
     * Returns the week year represented by this {@code Calendar}. The
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2975
     * week year is in sync with the week cycle. The {@linkplain
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2976
     * #getFirstDayOfWeek() first day of the first week} is the first
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2977
     * day of the week year.
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2978
     *
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2979
     * <p>The default implementation of this method throws an
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2980
     * {@link UnsupportedOperationException}.
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2981
     *
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2982
     * @return the week year of this {@code Calendar}
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2983
     * @exception UnsupportedOperationException
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2984
     *            if any week year numbering isn't supported
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2985
     *            in this {@code Calendar}.
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2986
     * @see #isWeekDateSupported()
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2987
     * @see #getFirstDayOfWeek()
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2988
     * @see #getMinimalDaysInFirstWeek()
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2989
     * @since 1.7
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2990
     */
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2991
    public int getWeekYear() {
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2992
        throw new UnsupportedOperationException();
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2993
    }
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2994
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2995
    /**
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2996
     * Sets the date of this {@code Calendar} with the the given date
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2997
     * specifiers - week year, week of year, and day of week.
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2998
     *
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2999
     * <p>Unlike the {@code set} method, all of the calendar fields
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3000
     * and {@code time} values are calculated upon return.
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3001
     *
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3002
     * <p>If {@code weekOfYear} is out of the valid week-of-year range
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3003
     * in {@code weekYear}, the {@code weekYear} and {@code
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3004
     * weekOfYear} values are adjusted in lenient mode, or an {@code
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3005
     * IllegalArgumentException} is thrown in non-lenient mode.
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3006
     *
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3007
     * <p>The default implementation of this method throws an
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3008
     * {@code UnsupportedOperationException}.
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3009
     *
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3010
     * @param weekYear   the week year
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3011
     * @param weekOfYear the week number based on {@code weekYear}
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3012
     * @param dayOfWeek  the day of week value: one of the constants
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3013
     *                   for the {@link #DAY_OF_WEEK} field: {@link
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3014
     *                   #SUNDAY}, ..., {@link #SATURDAY}.
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3015
     * @exception IllegalArgumentException
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3016
     *            if any of the given date specifiers is invalid
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3017
     *            or any of the calendar fields are inconsistent
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3018
     *            with the given date specifiers in non-lenient mode
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3019
     * @exception UnsupportedOperationException
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3020
     *            if any week year numbering isn't supported in this
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3021
     *            {@code Calendar}.
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3022
     * @see #isWeekDateSupported()
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3023
     * @see #getFirstDayOfWeek()
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3024
     * @see #getMinimalDaysInFirstWeek()
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3025
     * @since 1.7
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3026
     */
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3027
    public void setWeekDate(int weekYear, int weekOfYear, int dayOfWeek) {
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3028
        throw new UnsupportedOperationException();
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3029
    }
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3030
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3031
    /**
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3032
     * Returns the number of weeks in the week year represented by this
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3033
     * {@code Calendar}.
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3034
     *
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3035
     * <p>The default implementation of this method throws an
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3036
     * {@code UnsupportedOperationException}.
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3037
     *
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3038
     * @return the number of weeks in the week year.
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3039
     * @exception UnsupportedOperationException
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3040
     *            if any week year numbering isn't supported in this
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3041
     *            {@code Calendar}.
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3042
     * @see #WEEK_OF_YEAR
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3043
     * @see #isWeekDateSupported()
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3044
     * @see #getWeekYear()
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3045
     * @see #getActualMaximum(int)
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3046
     * @since 1.7
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3047
     */
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3048
    public int getWeeksInWeekYear() {
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3049
        throw new UnsupportedOperationException();
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3050
    }
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3051
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  3052
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
     * Returns the minimum value for the given calendar field of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
     * <code>Calendar</code> instance. The minimum value is defined as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
     * the smallest value returned by the {@link #get(int) get} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
     * for any possible time value.  The minimum value depends on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
     * calendar system specific parameters of the instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
     * @param field the calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
     * @return the minimum value for the given calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
     * @see #getMaximum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
     * @see #getGreatestMinimum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
     * @see #getLeastMaximum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
     * @see #getActualMinimum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
     * @see #getActualMaximum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
    abstract public int getMinimum(int field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
     * Returns the maximum value for the given calendar field of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
     * <code>Calendar</code> instance. The maximum value is defined as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
     * the largest value returned by the {@link #get(int) get} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
     * for any possible time value. The maximum value depends on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
     * calendar system specific parameters of the instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
     * @param field the calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
     * @return the maximum value for the given calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
     * @see #getMinimum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
     * @see #getGreatestMinimum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
     * @see #getLeastMaximum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
     * @see #getActualMinimum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
     * @see #getActualMaximum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
    abstract public int getMaximum(int field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
     * Returns the highest minimum value for the given calendar field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
     * of this <code>Calendar</code> instance. The highest minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
     * value is defined as the largest value returned by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
     * #getActualMinimum(int)} for any possible time value. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
     * greatest minimum value depends on calendar system specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
     * parameters of the instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
     * @param field the calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
     * @return the highest minimum value for the given calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
     * @see #getMinimum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
     * @see #getMaximum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
     * @see #getLeastMaximum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
     * @see #getActualMinimum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
     * @see #getActualMaximum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
    abstract public int getGreatestMinimum(int field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
     * Returns the lowest maximum value for the given calendar field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
     * of this <code>Calendar</code> instance. The lowest maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
     * value is defined as the smallest value returned by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
     * #getActualMaximum(int)} for any possible time value. The least
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
     * maximum value depends on calendar system specific parameters of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
     * the instance. For example, a <code>Calendar</code> for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
     * Gregorian calendar system returns 28 for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
     * <code>DAY_OF_MONTH</code> field, because the 28th is the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
     * day of the shortest month of this calendar, February in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
     * common year.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
     * @param field the calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
     * @return the lowest maximum value for the given calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
     * @see #getMinimum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
     * @see #getMaximum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
     * @see #getGreatestMinimum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
     * @see #getActualMinimum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
     * @see #getActualMaximum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
    abstract public int getLeastMaximum(int field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
     * Returns the minimum value that the specified calendar field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
     * could have, given the time value of this <code>Calendar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
     * <p>The default implementation of this method uses an iterative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
     * algorithm to determine the actual minimum value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
     * calendar field. Subclasses should, if possible, override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
     * with a more efficient implementation - in many cases, they can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
     * simply return <code>getMinimum()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
     * @param field the calendar field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
     * @return the minimum of the given calendar field for the time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
     * value of this <code>Calendar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
     * @see #getMinimum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
     * @see #getMaximum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
     * @see #getGreatestMinimum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
     * @see #getLeastMaximum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
     * @see #getActualMaximum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
    public int getActualMinimum(int field) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
        int fieldValue = getGreatestMinimum(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
        int endValue = getMinimum(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
        // if we know that the minimum value is always the same, just return it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
        if (fieldValue == endValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
            return fieldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
        // clone the calendar so we don't mess with the real one, and set it to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
        // accept anything for the field values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
        Calendar work = (Calendar)this.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
        work.setLenient(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
        // now try each value from getLeastMaximum() to getMaximum() one by one until
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
        // we get a value that normalizes to another value.  The last value that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
        // normalizes to itself is the actual minimum for the current date
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
        int result = fieldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
            work.set(field, fieldValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
            if (work.get(field) != fieldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
                result = fieldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
                fieldValue--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
        } while (fieldValue >= endValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
     * Returns the maximum value that the specified calendar field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
     * could have, given the time value of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
     * <code>Calendar</code>. For example, the actual maximum value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
     * the <code>MONTH</code> field is 12 in some years, and 13 in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
     * other years in the Hebrew calendar system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
     * <p>The default implementation of this method uses an iterative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
     * algorithm to determine the actual maximum value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
     * calendar field. Subclasses should, if possible, override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
     * with a more efficient implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
     * @param field the calendar field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
     * @return the maximum of the given calendar field for the time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
     * value of this <code>Calendar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
     * @see #getMinimum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
     * @see #getMaximum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
     * @see #getGreatestMinimum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
     * @see #getLeastMaximum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
     * @see #getActualMinimum(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3198
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
    public int getActualMaximum(int field) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
        int fieldValue = getLeastMaximum(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
        int endValue = getMaximum(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
        // if we know that the maximum value is always the same, just return it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
        if (fieldValue == endValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
            return fieldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
        // clone the calendar so we don't mess with the real one, and set it to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
        // accept anything for the field values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
        Calendar work = (Calendar)this.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
        work.setLenient(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
        // if we're counting weeks, set the day of the week to Sunday.  We know the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
        // last week of a month or year will contain the first day of the week.
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3216
        if (field == WEEK_OF_YEAR || field == WEEK_OF_MONTH) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
            work.set(DAY_OF_WEEK, firstDayOfWeek);
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3218
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
        // now try each value from getLeastMaximum() to getMaximum() one by one until
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
        // we get a value that normalizes to another value.  The last value that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
        // normalizes to itself is the actual maximum for the current date
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
        int result = fieldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
            work.set(field, fieldValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
            if (work.get(field) != fieldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
                result = fieldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
                fieldValue++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
        } while (fieldValue <= endValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
     * Creates and returns a copy of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
     * @return a copy of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3243
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
    public Object clone()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
            Calendar other = (Calendar) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
            other.fields = new int[FIELD_COUNT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
            other.isSet = new boolean[FIELD_COUNT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
            other.stamp = new int[FIELD_COUNT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
            for (int i = 0; i < FIELD_COUNT; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
                other.fields[i] = fields[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
                other.stamp[i] = stamp[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
                other.isSet[i] = isSet[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
            other.zone = (TimeZone) zone.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
            return other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
        catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
            // this shouldn't happen, since we are Cloneable
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 8521
diff changeset
  3262
            throw new InternalError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
    private static final String[] FIELD_NAME = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
        "ERA", "YEAR", "MONTH", "WEEK_OF_YEAR", "WEEK_OF_MONTH", "DAY_OF_MONTH",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
        "DAY_OF_YEAR", "DAY_OF_WEEK", "DAY_OF_WEEK_IN_MONTH", "AM_PM", "HOUR",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
        "HOUR_OF_DAY", "MINUTE", "SECOND", "MILLISECOND", "ZONE_OFFSET",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
        "DST_OFFSET"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
     * Returns the name of the specified calendar field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
     * @param field the calendar field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
     * @return the calendar field name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
     * @exception IndexOutOfBoundsException if <code>field</code> is negative,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
     * equal to or greater then <code>FIELD_COUNT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3281
    static String getFieldName(int field) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
        return FIELD_NAME[field];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
     * Return a string representation of this calendar. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
     * format of the returned string may vary between implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
     * The returned string may be empty but may not be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
     * @return  a string representation of this calendar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3293
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
        // NOTE: BuddhistCalendar.toString() interprets the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
        // produced by this method so that the Gregorian year number
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
        // is substituted by its B.E. year value. It relies on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
        // "...,YEAR=<year>,..." or "...,YEAR=?,...".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
        StringBuilder buffer = new StringBuilder(800);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
        buffer.append(getClass().getName()).append('[');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
        appendValue(buffer, "time", isTimeSet, time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
        buffer.append(",areFieldsSet=").append(areFieldsSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
        buffer.append(",areAllFieldsSet=").append(areAllFieldsSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
        buffer.append(",lenient=").append(lenient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
        buffer.append(",zone=").append(zone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
        appendValue(buffer, ",firstDayOfWeek", true, (long) firstDayOfWeek);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
        appendValue(buffer, ",minimalDaysInFirstWeek", true, (long) minimalDaysInFirstWeek);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
        for (int i = 0; i < FIELD_COUNT; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
            buffer.append(',');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
            appendValue(buffer, FIELD_NAME[i], isSet(i), (long) fields[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
        buffer.append(']');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
        return buffer.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
    // =======================privates===============================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3318
    private static void appendValue(StringBuilder sb, String item, boolean valid, long value) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
        sb.append(item).append('=');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
        if (valid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
            sb.append(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
            sb.append('?');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
     * Both firstDayOfWeek and minimalDaysInFirstWeek are locale-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
     * They are used to figure out the week count for a specific date for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
     * a given locale. These must be set when a Calendar is constructed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
     * @param desiredLocale the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
    private void setWeekCountData(Locale desiredLocale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
        /* try to get the Locale data from the cache */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
        int[] data = cachedLocaleData.get(desiredLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
        if (data == null) {  /* cache miss */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
            data = new int[2];
14502
d63fed06fed4 8000986: Split java.util.spi.CalendarDataProvider into week parameters and field names portions
okutsu
parents: 14342
diff changeset
  3339
            data[0] = CalendarDataUtility.retrieveFirstDayOfWeek(desiredLocale);
d63fed06fed4 8000986: Split java.util.spi.CalendarDataProvider into week parameters and field names portions
okutsu
parents: 14342
diff changeset
  3340
            data[1] = CalendarDataUtility.retrieveMinimalDaysInFirstWeek(desiredLocale);
7003
7d8d9506b4ee 6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents: 6501
diff changeset
  3341
            cachedLocaleData.putIfAbsent(desiredLocale, data);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
        firstDayOfWeek = data[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
        minimalDaysInFirstWeek = data[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
     * Recomputes the time and updates the status fields isTimeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
     * and areFieldsSet.  Callers should check isTimeSet and only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
     * call this method if isTimeSet is false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
    private void updateTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
        computeTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
        // The areFieldsSet and areAllFieldsSet values are no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
        // controlled here (as of 1.5).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
        isTimeSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
    private int compareTo(long t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
        long thisTime = getMillisOf(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
        return (thisTime > t) ? 1 : (thisTime == t) ? 0 : -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3364
    private static long getMillisOf(Calendar calendar) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
        if (calendar.isTimeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
            return calendar.time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
        Calendar cal = (Calendar) calendar.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
        cal.setLenient(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
        return cal.getTimeInMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3373
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
     * Adjusts the stamp[] values before nextStamp overflow. nextStamp
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
     * is set to the next stamp value upon the return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3377
    private void adjustStamp() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
        int max = MINIMUM_USER_STAMP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
        int newStamp = MINIMUM_USER_STAMP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
        for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
            int min = Integer.MAX_VALUE;
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 20502
diff changeset
  3383
            for (int v : stamp) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
                if (v >= newStamp && min > v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
                    min = v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
                if (max < v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
                    max = v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
            if (max != min && min == Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
            for (int i = 0; i < stamp.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
                if (stamp[i] == min) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
                    stamp[i] = newStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
            newStamp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
            if (min == max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
        nextStamp = newStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
     * Sets the WEEK_OF_MONTH and WEEK_OF_YEAR fields to new values with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
     * new parameter value if they have been calculated internally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
    private void invalidateWeekFields()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
        if (stamp[WEEK_OF_MONTH] != COMPUTED &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
            stamp[WEEK_OF_YEAR] != COMPUTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
        // We have to check the new values of these fields after changing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
        // firstDayOfWeek and/or minimalDaysInFirstWeek. If the field values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
        // have been changed, then set the new values. (4822110)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
        Calendar cal = (Calendar) clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
        cal.setLenient(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
        cal.clear(WEEK_OF_MONTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
        cal.clear(WEEK_OF_YEAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
        if (stamp[WEEK_OF_MONTH] == COMPUTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
            int weekOfMonth = cal.get(WEEK_OF_MONTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
            if (fields[WEEK_OF_MONTH] != weekOfMonth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
                fields[WEEK_OF_MONTH] = weekOfMonth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
        if (stamp[WEEK_OF_YEAR] == COMPUTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
            int weekOfYear = cal.get(WEEK_OF_YEAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
            if (fields[WEEK_OF_YEAR] != weekOfYear) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
                fields[WEEK_OF_YEAR] = weekOfYear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
     * Save the state of this object to a stream (i.e., serialize it).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
     * Ideally, <code>Calendar</code> would only write out its state data and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
     * the current time, and not write any field data out, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
     * <code>fields[]</code>, <code>isTimeSet</code>, <code>areFieldsSet</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
     * and <code>isSet[]</code>.  <code>nextStamp</code> also should not be part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
     * of the persistent state. Unfortunately, this didn't happen before JDK 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
     * shipped. To be compatible with JDK 1.1, we will always have to write out
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
     * the field values and state flags.  However, <code>nextStamp</code> can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
     * removed from the serialization stream; this will probably happen in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
     * near future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
     */
11681
9a1076231db7 7017458: (cal) Multithreaded deserialization of Calendar leads to ClassCastException
peytoia
parents: 10419
diff changeset
  3454
    private synchronized void writeObject(ObjectOutputStream stream)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
         throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
        // Try to compute the time correctly, for the future (stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
        // version 2) in which we don't write out fields[] or isSet[].
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
        if (!isTimeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
                updateTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
            catch (IllegalArgumentException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
        // If this Calendar has a ZoneInfo, save it and set a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
        // SimpleTimeZone equivalent (as a single DST schedule) for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
        // backward compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
        TimeZone savedZone = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
        if (zone instanceof ZoneInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
            SimpleTimeZone stz = ((ZoneInfo)zone).getLastRuleInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
            if (stz == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
                stz = new SimpleTimeZone(zone.getRawOffset(), zone.getID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
            savedZone = zone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
            zone = stz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
        // Write out the 1.1 FCS object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
        stream.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
        // Write out the ZoneInfo object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
        // 4802409: we write out even if it is null, a temporary workaround
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
        // the real fix for bug 4844924 in corba-iiop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
        stream.writeObject(savedZone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
        if (savedZone != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
            zone = savedZone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
2599
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3491
    private static class CalendarAccessControlContext {
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3492
        private static final AccessControlContext INSTANCE;
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3493
        static {
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3494
            RuntimePermission perm = new RuntimePermission("accessClassInPackage.sun.util.calendar");
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3495
            PermissionCollection perms = perm.newPermissionCollection();
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3496
            perms.add(perm);
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3497
            INSTANCE = new AccessControlContext(new ProtectionDomain[] {
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3498
                                                    new ProtectionDomain(null, perms)
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3499
                                                });
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3500
        }
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3501
        private CalendarAccessControlContext() {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3502
        }
2599
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3503
    }
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3504
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
     * Reconstitutes this object from a stream (i.e., deserialize it).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
    private void readObject(ObjectInputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
         throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
        final ObjectInputStream input = stream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
        input.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
        stamp = new int[FIELD_COUNT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
        // Starting with version 2 (not implemented yet), we expect that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
        // fields[], isSet[], isTimeSet, and areFieldsSet may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
        // streamed out anymore.  We expect 'time' to be correct.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
        if (serialVersionOnStream >= 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
            isTimeSet = true;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3522
            if (fields == null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3523
                fields = new int[FIELD_COUNT];
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3524
            }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3525
            if (isSet == null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3526
                isSet = new boolean[FIELD_COUNT];
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3527
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
        else if (serialVersionOnStream >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
        {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3531
            for (int i=0; i<FIELD_COUNT; ++i) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
                stamp[i] = isSet[i] ? COMPUTED : UNSET;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3533
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
        serialVersionOnStream = currentSerialVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
        // If there's a ZoneInfo object, use it for zone.
2599
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3539
        ZoneInfo zi = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
        try {
2599
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3541
            zi = AccessController.doPrivileged(
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3542
                    new PrivilegedExceptionAction<ZoneInfo>() {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
  3543
                        @Override
2599
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3544
                        public ZoneInfo run() throws Exception {
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3545
                            return (ZoneInfo) input.readObject();
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3546
                        }
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3547
                    },
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3548
                    CalendarAccessControlContext.INSTANCE);
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3549
        } catch (PrivilegedActionException pae) {
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3550
            Exception e = pae.getException();
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3551
            if (!(e instanceof OptionalDataException)) {
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3552
                if (e instanceof RuntimeException) {
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3553
                    throw (RuntimeException) e;
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3554
                } else if (e instanceof IOException) {
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3555
                    throw (IOException) e;
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3556
                } else if (e instanceof ClassNotFoundException) {
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3557
                    throw (ClassNotFoundException) e;
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3558
                }
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3559
                throw new RuntimeException(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
            }
2599
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3561
        }
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3562
        if (zi != null) {
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3563
            zone = zi;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
        // If the deserialized object has a SimpleTimeZone, try to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
        // replace it with a ZoneInfo equivalent (as of 1.4) in order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
        // to be compatible with the SimpleTimeZone-based
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
        // implementation as much as possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
        if (zone instanceof SimpleTimeZone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
            String id = zone.getID();
2599
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3572
            TimeZone tz = TimeZone.getTimeZone(id);
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3573
            if (tz != null && tz.hasSameRules(zone) && tz.getID().equals(id)) {
593d7b0502e2 6734167: Calendar.readObject allows elevation of privileges
okutsu
parents: 2
diff changeset
  3574
                zone = tz;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
    }
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15280
diff changeset
  3578
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15280
diff changeset
  3579
    /**
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15280
diff changeset
  3580
     * Converts this object to an {@link Instant}.
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15280
diff changeset
  3581
     * <p>
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15280
diff changeset
  3582
     * The conversion creates an {@code Instant} that represents the
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15280
diff changeset
  3583
     * same point on the time-line as this {@code Calendar}.
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15280
diff changeset
  3584
     *
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15280
diff changeset
  3585
     * @return the instant representing the same point on the time-line
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15280
diff changeset
  3586
     * @since 1.8
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15280
diff changeset
  3587
     */
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15280
diff changeset
  3588
    public final Instant toInstant() {
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15280
diff changeset
  3589
        return Instant.ofEpochMilli(getTimeInMillis());
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 15280
diff changeset
  3590
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3591
}