< prev index next >

src/java.base/share/classes/java/time/chrono/ThaiBuddhistDate.java

Print this page

  1 /*
  2  * Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

 75 import java.time.ZoneId;
 76 import java.time.temporal.ChronoField;
 77 import java.time.temporal.TemporalAccessor;
 78 import java.time.temporal.TemporalAdjuster;
 79 import java.time.temporal.TemporalAmount;
 80 import java.time.temporal.TemporalField;
 81 import java.time.temporal.TemporalQuery;
 82 import java.time.temporal.TemporalUnit;
 83 import java.time.temporal.UnsupportedTemporalTypeException;
 84 import java.time.temporal.ValueRange;
 85 import java.util.Objects;
 86 
 87 /**
 88  * A date in the Thai Buddhist calendar system.
 89  * <p>
 90  * This date operates using the {@linkplain ThaiBuddhistChronology Thai Buddhist calendar}.
 91  * This calendar system is primarily used in Thailand.
 92  * Dates are aligned such that {@code 2484-01-01 (Buddhist)} is {@code 1941-01-01 (ISO)}.
 93  * <p>
 94  * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
 95  * class; programmers should treat instances that are
 96  * {@linkplain #equals(Object) equal} as interchangeable and should not
 97  * use instances for synchronization, or unpredictable behavior may
 98  * occur. For example, in a future release, synchronization may fail.
 99  * The {@code equals} method should be used for comparisons.







100  *
101  * @implSpec
102  * This class is immutable and thread-safe.
103  *
104  * @since 1.8
105  */
106 @jdk.internal.ValueBased
107 public final class ThaiBuddhistDate
108         extends ChronoLocalDateImpl<ThaiBuddhistDate>
109         implements ChronoLocalDate, Serializable {
110 
111     /**
112      * Serialization version.
113      */
114     @java.io.Serial
115     private static final long serialVersionUID = -8722293800195731463L;
116 
117     /**
118      * The underlying date.
119      */
120     private final transient LocalDate isoDate;
121 
122     //-----------------------------------------------------------------------
123     /**
124      * Obtains the current {@code ThaiBuddhistDate} from the system clock in the default time-zone.
125      * <p>
126      * This will query the {@link Clock#systemDefaultZone() system clock} in the default
127      * time-zone to obtain the current date.

463     }
464 
465     /**
466      * A hash code for this date.
467      *
468      * @return a suitable hash code based only on the Chronology and the date
469      */
470     @Override  // override for performance
471     public int hashCode() {
472         return getChronology().getId().hashCode() ^ isoDate.hashCode();
473     }
474 
475     //-----------------------------------------------------------------------
476     /**
477      * Defend against malicious streams.
478      *
479      * @param s the stream to read
480      * @throws InvalidObjectException always
481      */
482     @java.io.Serial

483     private void readObject(ObjectInputStream s) throws InvalidObjectException {
484         throw new InvalidObjectException("Deserialization via serialization delegate");
485     }
486 
487     /**
488      * Writes the object using a
489      * <a href="{@docRoot}/serialized-form.html#java.time.chrono.Ser">dedicated serialized form</a>.
490      * @serialData
491      * <pre>
492      *  out.writeByte(10);                // identifies a ThaiBuddhistDate
493      *  out.writeInt(get(YEAR));
494      *  out.writeByte(get(MONTH_OF_YEAR));
495      *  out.writeByte(get(DAY_OF_MONTH));
496      * </pre>
497      *
498      * @return the instance of {@code Ser}, not null
499      */
500     @java.io.Serial
501     private Object writeReplace() {
502         return new Ser(Ser.THAIBUDDHIST_DATE_TYPE, this);

  1 /*
  2  * Copyright (c) 2012, 2026, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

 75 import java.time.ZoneId;
 76 import java.time.temporal.ChronoField;
 77 import java.time.temporal.TemporalAccessor;
 78 import java.time.temporal.TemporalAdjuster;
 79 import java.time.temporal.TemporalAmount;
 80 import java.time.temporal.TemporalField;
 81 import java.time.temporal.TemporalQuery;
 82 import java.time.temporal.TemporalUnit;
 83 import java.time.temporal.UnsupportedTemporalTypeException;
 84 import java.time.temporal.ValueRange;
 85 import java.util.Objects;
 86 
 87 /**
 88  * A date in the Thai Buddhist calendar system.
 89  * <p>
 90  * This date operates using the {@linkplain ThaiBuddhistChronology Thai Buddhist calendar}.
 91  * This calendar system is primarily used in Thailand.
 92  * Dates are aligned such that {@code 2484-01-01 (Buddhist)} is {@code 1941-01-01 (ISO)}.
 93  * <p>
 94  * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
 95  * class; programmers should treat instances that are {@linkplain #equals(Object) equal}
 96  * as interchangeable and should not use instances for synchronization or
 97  * with {@linkplain java.lang.ref.Reference object references}.
 98  *
 99  * <div class="preview-block">
100  *      <div class="preview-comment">
101  *          When preview features are enabled, {@code ThaiBuddhistDate} is a {@linkplain Class#isValue value class}.
102  *          Use of value class instances for synchronization or with
103  *          {@linkplain java.lang.ref.Reference object references} result in
104  *          {@link IdentityException}.
105  *      </div>
106  * </div>
107  *
108  * @implSpec
109  * This class is immutable and thread-safe.
110  *
111  * @since 1.8
112  */
113 @jdk.internal.ValueBased
114 public final /*value*/ class ThaiBuddhistDate
115         extends ChronoLocalDateImpl<ThaiBuddhistDate>
116         implements ChronoLocalDate, Serializable {
117 
118     /**
119      * Serialization version.
120      */
121     @java.io.Serial
122     private static final long serialVersionUID = -8722293800195731463L;
123 
124     /**
125      * The underlying date.
126      */
127     private final transient LocalDate isoDate;
128 
129     //-----------------------------------------------------------------------
130     /**
131      * Obtains the current {@code ThaiBuddhistDate} from the system clock in the default time-zone.
132      * <p>
133      * This will query the {@link Clock#systemDefaultZone() system clock} in the default
134      * time-zone to obtain the current date.

470     }
471 
472     /**
473      * A hash code for this date.
474      *
475      * @return a suitable hash code based only on the Chronology and the date
476      */
477     @Override  // override for performance
478     public int hashCode() {
479         return getChronology().getId().hashCode() ^ isoDate.hashCode();
480     }
481 
482     //-----------------------------------------------------------------------
483     /**
484      * Defend against malicious streams.
485      *
486      * @param s the stream to read
487      * @throws InvalidObjectException always
488      */
489     @java.io.Serial
490     @SuppressWarnings("serial") // this method is not invoked for value classes
491     private void readObject(ObjectInputStream s) throws InvalidObjectException {
492         throw new InvalidObjectException("Deserialization via serialization delegate");
493     }
494 
495     /**
496      * Writes the object using a
497      * <a href="{@docRoot}/serialized-form.html#java.time.chrono.Ser">dedicated serialized form</a>.
498      * @serialData
499      * <pre>
500      *  out.writeByte(10);                // identifies a ThaiBuddhistDate
501      *  out.writeInt(get(YEAR));
502      *  out.writeByte(get(MONTH_OF_YEAR));
503      *  out.writeByte(get(DAY_OF_MONTH));
504      * </pre>
505      *
506      * @return the instance of {@code Ser}, not null
507      */
508     @java.io.Serial
509     private Object writeReplace() {
510         return new Ser(Ser.THAIBUDDHIST_DATE_TYPE, this);
< prev index next >