jdk/src/share/classes/java/time/calendar/ThaiBuddhistChrono.java
author sherman
Tue, 22 Jan 2013 20:59:21 -0800
changeset 15289 3ac550392e43
permissions -rw-r--r--
8003680: JSR 310 Date/Time API Summary: Integration of JSR310 Date/Time API for M6 Reviewed-by: alanb, naoto, dholmes Contributed-by: scolebourne@joda.org, roger.riggs@oracle.com, richard.warburton@gmail.com, misterm@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     1
/*
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     4
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    10
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    15
 * accompanied this code).
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    16
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    20
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    23
 * questions.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    24
 */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    25
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    26
/*
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    27
 * Copyright (c) 2012, Stephen Colebourne & Michael Nascimento Santos
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    28
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    29
 * All rights reserved.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    30
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    31
 * Redistribution and use in source and binary forms, with or without
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    32
 * modification, are permitted provided that the following conditions are met:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    33
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    34
 *  * Redistributions of source code must retain the above copyright notice,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    35
 *    this list of conditions and the following disclaimer.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    36
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    37
 *  * Redistributions in binary form must reproduce the above copyright notice,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    38
 *    this list of conditions and the following disclaimer in the documentation
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    39
 *    and/or other materials provided with the distribution.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    40
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    41
 *  * Neither the name of JSR-310 nor the names of its contributors
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    42
 *    may be used to endorse or promote products derived from this software
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    43
 *    without specific prior written permission.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    44
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    45
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    46
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    47
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    48
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    49
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    50
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    51
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    52
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    53
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    54
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    55
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    56
 */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    57
package java.time.calendar;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    58
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    59
import static java.time.temporal.ChronoField.YEAR;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    60
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    61
import java.io.Serializable;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    62
import java.time.DateTimeException;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    63
import java.time.LocalDate;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    64
import java.time.temporal.Chrono;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    65
import java.time.temporal.ChronoField;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    66
import java.time.temporal.ChronoLocalDate;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    67
import java.time.temporal.Era;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    68
import java.time.temporal.ISOChrono;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    69
import java.time.temporal.TemporalAccessor;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    70
import java.time.temporal.ValueRange;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    71
import java.util.Arrays;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    72
import java.util.HashMap;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    73
import java.util.List;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    74
import java.util.Locale;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    75
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    76
/**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    77
 * The Thai Buddhist calendar system.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    78
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    79
 * This chronology defines the rules of the Thai Buddhist calendar system.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    80
 * This calendar system is primarily used in Thailand.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    81
 * Dates are aligned such that {@code 2484-01-01 (Buddhist)} is {@code 1941-01-01 (ISO)}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    82
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    83
 * The fields are defined as follows:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    84
 * <p><ul>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    85
 * <li>era - There are two eras, the current 'Buddhist' (ERA_BE) and the previous era (ERA_BEFORE_BE).
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    86
 * <li>year-of-era - The year-of-era for the current era increases uniformly from the epoch at year one.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    87
 *  For the previous era the year increases from one as time goes backwards.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    88
 *  The value for the current era is equal to the ISO proleptic-year plus 543.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    89
 * <li>proleptic-year - The proleptic year is the same as the year-of-era for the
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    90
 *  current era. For the previous era, years have zero, then negative values.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    91
 *  The value is equal to the ISO proleptic-year plus 543.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    92
 * <li>month-of-year - The ThaiBuddhist month-of-year exactly matches ISO.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    93
 * <li>day-of-month - The ThaiBuddhist day-of-month exactly matches ISO.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    94
 * <li>day-of-year - The ThaiBuddhist day-of-year exactly matches ISO.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    95
 * <li>leap-year - The ThaiBuddhist leap-year pattern exactly matches ISO, such that the two calendars
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    96
 *  are never out of step.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    97
 * </ul><p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    98
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    99
 * <h3>Specification for implementors</h3>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   100
 * This class is immutable and thread-safe.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   101
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   102
 * @since 1.8
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   103
 */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   104
public final class ThaiBuddhistChrono extends Chrono<ThaiBuddhistChrono> implements Serializable {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   105
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   106
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   107
     * Singleton instance of the Buddhist chronology.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   108
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   109
    public static final ThaiBuddhistChrono INSTANCE = new ThaiBuddhistChrono();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   110
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   111
     * The singleton instance for the era before the current one - Before Buddhist -
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   112
     * which has the value 0.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   113
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   114
    public static final Era<ThaiBuddhistChrono> ERA_BEFORE_BE = ThaiBuddhistEra.BEFORE_BE;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   115
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   116
     * The singleton instance for the current era - Buddhist - which has the value 1.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   117
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   118
    public static final Era<ThaiBuddhistChrono> ERA_BE = ThaiBuddhistEra.BE;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   119
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   120
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   121
     * Serialization version.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   122
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   123
    private static final long serialVersionUID = 2775954514031616474L;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   124
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   125
     * Containing the offset to add to the ISO year.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   126
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   127
    static final int YEARS_DIFFERENCE = 543;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   128
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   129
     * Narrow names for eras.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   130
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   131
    private static final HashMap<String, String[]> ERA_NARROW_NAMES = new HashMap<>();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   132
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   133
     * Short names for eras.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   134
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   135
    private static final HashMap<String, String[]> ERA_SHORT_NAMES = new HashMap<>();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   136
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   137
     * Full names for eras.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   138
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   139
    private static final HashMap<String, String[]> ERA_FULL_NAMES = new HashMap<>();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   140
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   141
     * Fallback language for the era names.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   142
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   143
    private static final String FALLBACK_LANGUAGE = "en";
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   144
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   145
     * Language that has the era names.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   146
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   147
    private static final String TARGET_LANGUAGE = "th";
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   148
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   149
     * Name data.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   150
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   151
    static {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   152
        ERA_NARROW_NAMES.put(FALLBACK_LANGUAGE, new String[]{"BB", "BE"});
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   153
        ERA_NARROW_NAMES.put(TARGET_LANGUAGE, new String[]{"BB", "BE"});
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   154
        ERA_SHORT_NAMES.put(FALLBACK_LANGUAGE, new String[]{"B.B.", "B.E."});
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   155
        ERA_SHORT_NAMES.put(TARGET_LANGUAGE,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   156
                new String[]{"\u0e1e.\u0e28.",
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   157
                "\u0e1b\u0e35\u0e01\u0e48\u0e2d\u0e19\u0e04\u0e23\u0e34\u0e2a\u0e15\u0e4c\u0e01\u0e32\u0e25\u0e17\u0e35\u0e48"});
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   158
        ERA_FULL_NAMES.put(FALLBACK_LANGUAGE, new String[]{"Before Buddhist", "Budhhist Era"});
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   159
        ERA_FULL_NAMES.put(TARGET_LANGUAGE,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   160
                new String[]{"\u0e1e\u0e38\u0e17\u0e18\u0e28\u0e31\u0e01\u0e23\u0e32\u0e0a",
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   161
                "\u0e1b\u0e35\u0e01\u0e48\u0e2d\u0e19\u0e04\u0e23\u0e34\u0e2a\u0e15\u0e4c\u0e01\u0e32\u0e25\u0e17\u0e35\u0e48"});
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   162
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   163
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   164
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   165
     * Restricted constructor.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   166
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   167
    private ThaiBuddhistChrono() {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   168
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   169
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   170
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   171
     * Resolve singleton.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   172
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   173
     * @return the singleton instance, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   174
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   175
    private Object readResolve() {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   176
        return INSTANCE;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   177
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   178
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   179
    //-----------------------------------------------------------------------
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   180
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   181
     * Gets the ID of the chronology - 'ThaiBuddhist'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   182
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   183
     * The ID uniquely identifies the {@code Chrono}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   184
     * It can be used to lookup the {@code Chrono} using {@link #of(String)}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   185
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   186
     * @return the chronology ID - 'ThaiBuddhist'
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   187
     * @see #getCalendarType()
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   188
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   189
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   190
    public String getId() {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   191
        return "ThaiBuddhist";
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   192
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   193
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   194
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   195
     * Gets the calendar type of the underlying calendar system - 'buddhist'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   196
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   197
     * The calendar type is an identifier defined by the
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   198
     * <em>Unicode Locale Data Markup Language (LDML)</em> specification.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   199
     * It can be used to lookup the {@code Chrono} using {@link #of(String)}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   200
     * It can also be used as part of a locale, accessible via
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   201
     * {@link Locale#getUnicodeLocaleType(String)} with the key 'ca'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   202
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   203
     * @return the calendar system type - 'buddhist'
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   204
     * @see #getId()
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   205
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   206
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   207
    public String getCalendarType() {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   208
        return "buddhist";
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   209
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   210
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   211
    //-----------------------------------------------------------------------
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   212
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   213
    public ChronoLocalDate<ThaiBuddhistChrono> date(int prolepticYear, int month, int dayOfMonth) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   214
        return new ThaiBuddhistDate(LocalDate.of(prolepticYear - YEARS_DIFFERENCE, month, dayOfMonth));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   215
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   216
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   217
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   218
    public ChronoLocalDate<ThaiBuddhistChrono> dateYearDay(int prolepticYear, int dayOfYear) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   219
        return new ThaiBuddhistDate(LocalDate.ofYearDay(prolepticYear - YEARS_DIFFERENCE, dayOfYear));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   220
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   221
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   222
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   223
    public ChronoLocalDate<ThaiBuddhistChrono> date(TemporalAccessor temporal) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   224
        if (temporal instanceof ThaiBuddhistDate) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   225
            return (ThaiBuddhistDate) temporal;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   226
        }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   227
        return new ThaiBuddhistDate(LocalDate.from(temporal));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   228
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   229
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   230
    //-----------------------------------------------------------------------
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   231
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   232
     * Checks if the specified year is a leap year.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   233
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   234
     * Thai Buddhist leap years occur exactly in line with ISO leap years.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   235
     * This method does not validate the year passed in, and only has a
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   236
     * well-defined result for years in the supported range.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   237
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   238
     * @param prolepticYear  the proleptic-year to check, not validated for range
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   239
     * @return true if the year is a leap year
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   240
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   241
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   242
    public boolean isLeapYear(long prolepticYear) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   243
        return ISOChrono.INSTANCE.isLeapYear(prolepticYear - YEARS_DIFFERENCE);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   244
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   245
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   246
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   247
    public int prolepticYear(Era<ThaiBuddhistChrono> era, int yearOfEra) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   248
        if (era instanceof ThaiBuddhistEra == false) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   249
            throw new DateTimeException("Era must be BuddhistEra");
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   250
        }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   251
        return (era == ThaiBuddhistEra.BE ? yearOfEra : 1 - yearOfEra);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   252
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   253
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   254
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   255
    public Era<ThaiBuddhistChrono> eraOf(int eraValue) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   256
        return ThaiBuddhistEra.of(eraValue);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   257
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   258
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   259
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   260
    public List<Era<ThaiBuddhistChrono>> eras() {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   261
        return Arrays.<Era<ThaiBuddhistChrono>>asList(ThaiBuddhistEra.values());
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   262
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   263
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   264
    //-----------------------------------------------------------------------
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   265
    @Override
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   266
    public ValueRange range(ChronoField field) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   267
        switch (field) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   268
            case YEAR_OF_ERA: {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   269
                ValueRange range = YEAR.range();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   270
                return ValueRange.of(1, -(range.getMinimum() + YEARS_DIFFERENCE) + 1, range.getMaximum() + YEARS_DIFFERENCE);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   271
            }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   272
            case YEAR: {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   273
                ValueRange range = YEAR.range();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   274
                return ValueRange.of(range.getMinimum() + YEARS_DIFFERENCE, range.getMaximum() + YEARS_DIFFERENCE);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   275
            }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   276
        }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   277
        return field.range();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   278
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   279
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   280
}