jdk/src/java.base/share/classes/sun/util/calendar/CalendarSystem.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 27286 8299f6b0c5fc
child 34774 03b4e6dc367b
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
     2
 * Copyright (c) 2000, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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
package sun.util.calendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
15658
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
    28
import java.io.File;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
    29
import java.io.FileInputStream;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
    30
import java.io.IOException;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
    31
import java.security.AccessController;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
    32
import java.security.PrivilegedActionException;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
    33
import java.security.PrivilegedExceptionAction;
55b829ca2334 8007392: JSR 310: DateTime API Updates
sherman
parents: 11130
diff changeset
    34
import java.util.Properties;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.TimeZone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.concurrent.ConcurrentHashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.concurrent.ConcurrentMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <code>CalendarSystem</code> is an abstract class that defines the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * programming interface to deal with calendar date and time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p><code>CalendarSystem</code> instances are singletons. For
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * example, there exists only one Gregorian calendar instance in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Java runtime environment. A singleton instance can be obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * calling one of the static factory methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <h4>CalendarDate</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>For the methods in a <code>CalendarSystem</code> that manipulate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * a <code>CalendarDate</code>, <code>CalendarDate</code>s that have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * been created by the <code>CalendarSystem</code> must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * specified. Otherwise, the methods throw an exception. This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * because, for example, a Chinese calendar date can't be understood
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * by the Hebrew calendar system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <h4>Calendar names</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * Each calendar system has a unique name to be identified. The Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * runtime in this release supports the following calendar systems.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *  Name          Calendar System
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *  ---------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *  gregorian     Gregorian Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *  julian        Julian Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *  japanese      Japanese Imperial Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @see CalendarDate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * @author Masayoshi Okutsu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
public abstract class CalendarSystem {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /////////////////////// Calendar Factory Methods /////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 27286
diff changeset
    79
    private static volatile boolean initialized = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    // Map of calendar names and calendar class names
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static ConcurrentMap<String, String> names;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // Map of calendar names and CalendarSystem instances
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static ConcurrentMap<String,CalendarSystem> calendars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private static final String PACKAGE_NAME = "sun.util.calendar.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static final String[] namePairs = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        "gregorian", "Gregorian",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        "japanese", "LocalGregorianCalendar",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        "julian", "JulianCalendar",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        "hebrew", "HebrewCalendar",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        "iso8601", "ISOCalendar",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        "taiwanese", "LocalGregorianCalendar",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        "thaibuddhist", "LocalGregorianCalendar",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private static void initNames() {
11130
c7093e306a34 7117487: Warnings Cleanup: some i18n classes in java.util and sun.util
okutsu
parents: 5506
diff changeset
   102
        ConcurrentMap<String,String> nameMap = new ConcurrentHashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        // Associate a calendar name with its class name and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        // calendar class name with its date class name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        StringBuilder clName = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        for (int i = 0; i < namePairs.length; i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            clName.setLength(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            String cl = clName.append(PACKAGE_NAME).append(namePairs[i+1]).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            nameMap.put(namePairs[i], cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        synchronized (CalendarSystem.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            if (!initialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                names = nameMap;
11130
c7093e306a34 7117487: Warnings Cleanup: some i18n classes in java.util and sun.util
okutsu
parents: 5506
diff changeset
   115
                calendars = new ConcurrentHashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                initialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 27286
diff changeset
   121
    private static final Gregorian GREGORIAN_INSTANCE = new Gregorian();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Returns the singleton instance of the <code>Gregorian</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * calendar system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @return the <code>Gregorian</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public static Gregorian getGregorianCalendar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return GREGORIAN_INSTANCE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Returns a <code>CalendarSystem</code> specified by the calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * name. The calendar name has to be one of the supported calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param calendarName the calendar name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @return the <code>CalendarSystem</code> specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * <code>calendarName</code>, or null if there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * <code>CalendarSystem</code> associated with the given calendar name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public static CalendarSystem forName(String calendarName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if ("gregorian".equals(calendarName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            return GREGORIAN_INSTANCE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        if (!initialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            initNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        CalendarSystem cal = calendars.get(calendarName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (cal != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            return cal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        String className = names.get(calendarName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (className == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            return null; // Unknown calendar name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        if (className.endsWith("LocalGregorianCalendar")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            // Create the specific kind of local Gregorian calendar system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            cal = LocalGregorianCalendar.getLocalGregorianCalendar(calendarName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            try {
11130
c7093e306a34 7117487: Warnings Cleanup: some i18n classes in java.util and sun.util
okutsu
parents: 5506
diff changeset
   167
                Class<?> cl = Class.forName(className);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                cal = (CalendarSystem) cl.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            } catch (Exception e) {
11130
c7093e306a34 7117487: Warnings Cleanup: some i18n classes in java.util and sun.util
okutsu
parents: 5506
diff changeset
   170
                throw new InternalError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if (cal == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        CalendarSystem cs =  calendars.putIfAbsent(calendarName, cal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        return (cs == null) ? cal : cs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    //////////////////////////////// Calendar API //////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Returns the name of this calendar system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public abstract String getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public abstract CalendarDate getCalendarDate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Calculates calendar fields from the specified number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * milliseconds since the Epoch, January 1, 1970 00:00:00 UTC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * (Gregorian). This method doesn't check overflow or underflow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * when adjusting the millisecond value (representing UTC) with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * the time zone offsets (i.e., the GMT offset and amount of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * daylight saving).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param millis the offset value in milliseconds from January 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * 1970 00:00:00 UTC (Gregorian).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @return a <code>CalendarDate</code> instance that contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * calculated calendar field values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public abstract CalendarDate getCalendarDate(long millis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public abstract CalendarDate getCalendarDate(long millis, CalendarDate date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public abstract CalendarDate getCalendarDate(long millis, TimeZone zone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Constructs a <code>CalendarDate</code> that is specific to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * calendar system. All calendar fields have their initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * values. The {@link TimeZone#getDefault() default time zone} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * set to the instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @return a <code>CalendarDate</code> instance that contains the initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * calendar field values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public abstract CalendarDate newCalendarDate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public abstract CalendarDate newCalendarDate(TimeZone zone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Returns the number of milliseconds since the Epoch, January 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * 1970 00:00:00 UTC (Gregorian), represented by the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * <code>CalendarDate</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param date the <code>CalendarDate</code> from which the time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * value is calculated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @return the number of milliseconds since the Epoch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public abstract long getTime(CalendarDate date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Returns the length in days of the specified year by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * <code>date</code>. This method does not perform the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * normalization with the specified <code>CalendarDate</code>. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * <code>CalendarDate</code> must be normalized to get a correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public abstract int getYearLength(CalendarDate date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Returns the number of months of the specified year. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * does not perform the normalization with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * <code>CalendarDate</code>. The <code>CalendarDate</code> must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * be normalized to get a correct value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public abstract int getYearLengthInMonths(CalendarDate date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Returns the length in days of the month specified by the calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * date. This method does not perform the normalization with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * specified calendar date. The <code>CalendarDate</code> must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * be normalized to get a correct value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @param date the date from which the month value is obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @return the number of days in the month
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @exception IllegalArgumentException if the specified calendar date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * doesn't have a valid month value in this calendar system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public abstract int getMonthLength(CalendarDate date); // no setter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Returns the length in days of a week in this calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * system. If this calendar system has multiple radix weeks, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * method returns only one of them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public abstract int getWeekLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * Returns the <code>Era</code> designated by the era name that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * has to be known to this calendar system. If no Era is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * applicable to this calendar system, null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @param eraName the name of the era
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @return the <code>Era</code> designated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * <code>eraName</code>, or <code>null</code> if no Era is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * applicable to this calendar system or the specified era name is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * not known to this calendar system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public abstract Era getEra(String eraName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Returns valid <code>Era</code>s of this calendar system. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * return value is sorted in the descendant order. (i.e., the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * element of the returned array is the oldest era.) If no era is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * applicable to this calendar system, <code>null</code> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @return an array of valid <code>Era</code>s, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * <code>null</code> if no era is applicable to this calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public abstract Era[] getEras();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @throws IllegalArgumentException if the specified era name is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * unknown to this calendar system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @see Era
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    public abstract void setEra(CalendarDate date, String eraName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Returns a <code>CalendarDate</code> of the n-th day of week
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * which is on, after or before the specified date. For example, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * first Sunday in April 2002 (Gregorian) can be obtained as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * below:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * <pre><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Gregorian cal = CalendarSystem.getGregorianCalendar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * CalendarDate date = cal.newCalendarDate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * date.setDate(2004, cal.APRIL, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * CalendarDate firstSun = cal.getNthDayOfWeek(1, cal.SUNDAY, date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * // firstSun represents April 4, 2004.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * </code></pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * This method returns a new <code>CalendarDate</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * and doesn't modify the original date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @param nth specifies the n-th one. A positive number specifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * <em>on or after</em> the <code>date</code>. A non-positive number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * specifies <em>on or before</em> the <code>date</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @param dayOfWeek the day of week
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @param date the date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @return the date of the nth <code>dayOfWeek</code> after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * or before the specified <code>CalendarDate</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public abstract CalendarDate getNthDayOfWeek(int nth, int dayOfWeek,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                                                 CalendarDate date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    public abstract CalendarDate setTimeOfDay(CalendarDate date, int timeOfDay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * Checks whether the calendar fields specified by <code>date</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * represents a valid date and time in this calendar system. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * given date is valid, <code>date</code> is marked as <em>normalized</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @param date the <code>CalendarDate</code> to be validated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @return <code>true</code> if all the calendar fields are consistent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * otherwise, <code>false</code> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @exception NullPointerException if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * <code>date</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    public abstract boolean validate(CalendarDate date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * Normalizes calendar fields in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * <code>date</code>. Also all {@link CalendarDate#FIELD_UNDEFINED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * undefined} fields are set to correct values. The actual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * normalization process is calendar system dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @param date the calendar date to be validated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @return <code>true</code> if all fields have been normalized;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @exception NullPointerException if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * <code>date</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public abstract boolean normalize(CalendarDate date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
}