< prev index next >

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

Print this page

 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 Minguo calendar system.
 89  * <p>
 90  * This date operates using the {@linkplain MinguoChronology Minguo calendar}.
 91  * This calendar system is primarily used in the Republic of China, often known as Taiwan.
 92  * Dates are aligned such that {@code 0001-01-01 (Minguo)} is {@code 1912-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 MinguoDate
108         extends ChronoLocalDateImpl<MinguoDate>
109         implements ChronoLocalDate, Serializable {
110 
111     /**
112      * Serialization version.
113      */
114     @java.io.Serial
115     private static final long serialVersionUID = 1300372329181994526L;
116 
117     /**
118      * The underlying date.
119      */
120     private final transient LocalDate isoDate;
121 
122     //-----------------------------------------------------------------------
123     /**
124      * Obtains the current {@code MinguoDate} from the system clock in the default time-zone.
125      * <p>
126      * This will query the {@link Clock#systemDefaultZone() system clock} in the default

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

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

 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 Minguo calendar system.
 89  * <p>
 90  * This date operates using the {@linkplain MinguoChronology Minguo calendar}.
 91  * This calendar system is primarily used in the Republic of China, often known as Taiwan.
 92  * Dates are aligned such that {@code 0001-01-01 (Minguo)} is {@code 1912-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, mutexes, 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 MinguoDate} is a {@linkplain Class#isValue value class}.
102  *          Use of value class instances for synchronization, mutexes, 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 @jdk.internal.MigratedValueClass
115 public final class MinguoDate
116         extends ChronoLocalDateImpl<MinguoDate>
117         implements ChronoLocalDate, Serializable {
118 
119     /**
120      * Serialization version.
121      */
122     @java.io.Serial
123     private static final long serialVersionUID = 1300372329181994526L;
124 
125     /**
126      * The underlying date.
127      */
128     private final transient LocalDate isoDate;
129 
130     //-----------------------------------------------------------------------
131     /**
132      * Obtains the current {@code MinguoDate} from the system clock in the default time-zone.
133      * <p>
134      * This will query the {@link Clock#systemDefaultZone() system clock} in the default

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