src/java.base/share/classes/sun/util/BuddhistCalendar.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 31471 jdk/src/java.base/share/classes/sun/util/BuddhistCalendar.java@ae27c6f1d8bf
child 57956 e0b8b019d2f5
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
     2
 * Copyright (c) 2000, 2012, 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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
7504
e490ef909bf5 6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents: 5506
diff changeset
    28
import java.io.IOException;
e490ef909bf5 6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents: 5506
diff changeset
    29
import java.io.ObjectInputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.GregorianCalendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.TimeZone;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
    34
import sun.util.locale.provider.CalendarDataUtility;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public class BuddhistCalendar extends GregorianCalendar {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
//////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
// Class Variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
//////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static final long serialVersionUID = -8527488697350388578L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
7504
e490ef909bf5 6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents: 5506
diff changeset
    44
    private static final int BUDDHIST_YEAR_OFFSET = 543;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
///////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
// Constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
///////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * Constructs a default BuddhistCalendar using the current time
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * in the default time zone with the default locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public BuddhistCalendar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * Constructs a BuddhistCalendar based on the current time
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * in the given time zone with the default locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @param zone the given time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public BuddhistCalendar(TimeZone zone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        super(zone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Constructs a BuddhistCalendar based on the current time
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * in the default time zone with the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @param aLocale the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public BuddhistCalendar(Locale aLocale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        super(aLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Constructs a BuddhistCalendar based on the current time
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * in the given time zone with the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param zone the given time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param aLocale the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public BuddhistCalendar(TimeZone zone, Locale aLocale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        super(zone, aLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
// Public methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
    91
     * Returns {@code "buddhist"} as the calendar type of this Calendar.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
    92
     */
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
    93
    @Override
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
    94
    public String getCalendarType() {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
    95
        return "buddhist";
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
    96
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
    97
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
    98
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * Compares this BuddhistCalendar to an object reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @param obj the object reference with which to compare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @return true if this object is equal to <code>obj</code>; false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   103
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return obj instanceof BuddhistCalendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            && super.equals(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Override hashCode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Generates the hash code for the BuddhistCalendar object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   113
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public int hashCode() {
7504
e490ef909bf5 6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents: 5506
diff changeset
   115
        return super.hashCode() ^ BUDDHIST_YEAR_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Gets the value for a given time field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param field the given time field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @return the value for the given time field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   123
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public int get(int field)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if (field == YEAR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            return super.get(field) + yearOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return super.get(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Sets the time field with the given value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @param field the given time field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @param value the value to be set for the given time field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   137
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public void set(int field, int value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if (field == YEAR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            super.set(field, value - yearOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            super.set(field, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Adds the specified (signed) amount of time to the given time field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param field the time field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @param amount the amount of date or time to be added to the field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   152
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public void add(int field, int amount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        int savedYearOffset = yearOffset;
7504
e490ef909bf5 6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents: 5506
diff changeset
   156
        // To let the superclass calculate date-time values correctly,
e490ef909bf5 6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents: 5506
diff changeset
   157
        // temporarily make this GregorianCalendar.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        yearOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            super.add(field, amount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            yearOffset = savedYearOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Add to field a signed amount without changing larger fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * A negative roll amount means to subtract from field without changing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * larger fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @param field the time field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @param amount the signed amount to add to <code>field</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   173
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public void roll(int field, int amount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        int savedYearOffset = yearOffset;
7504
e490ef909bf5 6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents: 5506
diff changeset
   177
        // To let the superclass calculate date-time values correctly,
e490ef909bf5 6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents: 5506
diff changeset
   178
        // temporarily make this GregorianCalendar.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        yearOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            super.roll(field, amount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            yearOffset = savedYearOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   187
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public String getDisplayName(int field, int style, Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (field != ERA) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            return super.getDisplayName(field, style, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   193
        return CalendarDataUtility.retrieveFieldValueName("buddhist", field, get(field), style, locale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   196
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public Map<String,Integer> getDisplayNames(int field, int style, Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (field != ERA) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            return super.getDisplayNames(field, style, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   201
        return CalendarDataUtility.retrieveFieldValueNames("buddhist", field, style, locale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Returns the maximum value that this field could have, given the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * current date.  For example, with the date "Feb 3, 2540" and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * <code>DAY_OF_MONTH</code> field, the actual maximum is 28; for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * "Feb 3, 2539" it is 29.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @param field the field to determine the maximum of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @return the maximum of the given field for the current date of this Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   213
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public int getActualMaximum(int field) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        int savedYearOffset = yearOffset;
7504
e490ef909bf5 6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents: 5506
diff changeset
   216
        // To let the superclass calculate date-time values correctly,
e490ef909bf5 6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents: 5506
diff changeset
   217
        // temporarily make this GregorianCalendar.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        yearOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            return super.getActualMaximum(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            yearOffset = savedYearOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   226
    @Override
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 7668
diff changeset
   227
    @SuppressWarnings("empty-statement")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        // The super class produces a String with the Gregorian year
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        // value (or '?')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        String s = super.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        // If the YEAR field is UNSET, then return the Gregorian string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (!isSet(YEAR)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        final String yearField = "YEAR=";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        int p = s.indexOf(yearField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        // If the string doesn't include the year value for some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        // reason, then return the Gregorian string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        if (p == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        p += yearField.length();
31471
ae27c6f1d8bf 8077242: (str) Optimize AbstractStringBuilder.append(CharSequence, int, int) for String argument
igerasim
parents: 25859
diff changeset
   245
        StringBuilder sb = new StringBuilder(s.length() + 10);
ae27c6f1d8bf 8077242: (str) Optimize AbstractStringBuilder.append(CharSequence, int, int) for String argument
igerasim
parents: 25859
diff changeset
   246
        sb.append(s, 0, p);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        // Skip the year number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        while (Character.isDigit(s.charAt(p++)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            ;
7504
e490ef909bf5 6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents: 5506
diff changeset
   250
        int year = internalGet(YEAR) + BUDDHIST_YEAR_OFFSET;
31471
ae27c6f1d8bf 8077242: (str) Optimize AbstractStringBuilder.append(CharSequence, int, int) for String argument
igerasim
parents: 25859
diff changeset
   251
        sb.append(year).append(s, p - 1, s.length());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
7504
e490ef909bf5 6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents: 5506
diff changeset
   255
    private transient int yearOffset = BUDDHIST_YEAR_OFFSET;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
7504
e490ef909bf5 6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents: 5506
diff changeset
   257
    private void readObject(ObjectInputStream stream)
e490ef909bf5 6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents: 5506
diff changeset
   258
        throws IOException, ClassNotFoundException {
e490ef909bf5 6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents: 5506
diff changeset
   259
        stream.defaultReadObject();
e490ef909bf5 6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents: 5506
diff changeset
   260
        yearOffset = BUDDHIST_YEAR_OFFSET;
e490ef909bf5 6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
okutsu
parents: 5506
diff changeset
   261
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
}