< prev index next >

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

Print this page

 88 /**
 89  * A date in the Hijrah calendar system.
 90  * <p>
 91  * This date operates using one of several variants of the
 92  * {@linkplain HijrahChronology Hijrah calendar}.
 93  * <p>
 94  * The Hijrah calendar has a different total of days in a year than
 95  * Gregorian calendar, and the length of each month is based on the period
 96  * of a complete revolution of the moon around the earth
 97  * (as between successive new moons).
 98  * Refer to the {@link HijrahChronology} for details of supported variants.
 99  * <p>
100  * Each HijrahDate is created bound to a particular HijrahChronology,
101  * The same chronology is propagated to each HijrahDate computed from the date.
102  * To use a different Hijrah variant, its HijrahChronology can be used
103  * to create new HijrahDate instances.
104  * Alternatively, the {@link #withVariant} method can be used to convert
105  * to a new HijrahChronology.
106  * <p>
107  * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
108  * class; programmers should treat instances that are
109  * {@linkplain #equals(Object) equal} as interchangeable and should not
110  * use instances for synchronization, or unpredictable behavior may
111  * occur. For example, in a future release, synchronization may fail.
112  * The {@code equals} method should be used for comparisons.







113  *
114  * @implSpec
115  * This class is immutable and thread-safe.
116  *
117  * @since 1.8
118  */
119 @jdk.internal.ValueBased

120 public final class HijrahDate
121         extends ChronoLocalDateImpl<HijrahDate>
122         implements ChronoLocalDate, Serializable {
123 
124     /**
125      * Serialization version.
126      */
127     @java.io.Serial
128     private static final long serialVersionUID = -5207853542612002020L;
129     /**
130      * The Chronology of this HijrahDate.
131      */
132     private final transient HijrahChronology chrono;
133     /**
134      * The proleptic year.
135      */
136     private final transient int prolepticYear;
137     /**
138      * The month-of-year.
139      */

639      *
640      * @return a suitable hash code based only on the Chronology and the date
641      */
642     @Override  // override for performance
643     public int hashCode() {
644         int yearValue = prolepticYear;
645         int monthValue = monthOfYear;
646         int dayValue = dayOfMonth;
647         return getChronology().getId().hashCode() ^ (yearValue & 0xFFFFF800)
648                 ^ ((yearValue << 11) + (monthValue << 6) + (dayValue));
649     }
650 
651     //-----------------------------------------------------------------------
652     /**
653      * Defend against malicious streams.
654      *
655      * @param s the stream to read
656      * @throws InvalidObjectException always
657      */
658     @java.io.Serial

659     private void readObject(ObjectInputStream s) throws InvalidObjectException {
660         throw new InvalidObjectException("Deserialization via serialization delegate");
661     }
662 
663     /**
664      * Writes the object using a
665      * <a href="{@docRoot}/serialized-form.html#java.time.chrono.Ser">dedicated serialized form</a>.
666      * @serialData
667      * <pre>
668      *  out.writeByte(6);                 // identifies a HijrahDate
669      *  out.writeObject(chrono);          // the HijrahChronology variant
670      *  out.writeInt(get(YEAR));
671      *  out.writeByte(get(MONTH_OF_YEAR));
672      *  out.writeByte(get(DAY_OF_MONTH));
673      * </pre>
674      *
675      * @return the instance of {@code Ser}, not null
676      */
677     @java.io.Serial
678     private Object writeReplace() {

 88 /**
 89  * A date in the Hijrah calendar system.
 90  * <p>
 91  * This date operates using one of several variants of the
 92  * {@linkplain HijrahChronology Hijrah calendar}.
 93  * <p>
 94  * The Hijrah calendar has a different total of days in a year than
 95  * Gregorian calendar, and the length of each month is based on the period
 96  * of a complete revolution of the moon around the earth
 97  * (as between successive new moons).
 98  * Refer to the {@link HijrahChronology} for details of supported variants.
 99  * <p>
100  * Each HijrahDate is created bound to a particular HijrahChronology,
101  * The same chronology is propagated to each HijrahDate computed from the date.
102  * To use a different Hijrah variant, its HijrahChronology can be used
103  * to create new HijrahDate instances.
104  * Alternatively, the {@link #withVariant} method can be used to convert
105  * to a new HijrahChronology.
106  * <p>
107  * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
108  * class; programmers should treat instances that are {@linkplain #equals(Object) equal}
109  * as interchangeable and should not use instances for synchronization, mutexes, or
110  * with {@linkplain java.lang.ref.Reference object references}.
111  *
112  * <div class="preview-block">
113  *      <div class="preview-comment">
114  *          When preview features are enabled, {@code HijrahDate} is a {@linkplain Class#isValue value class}.
115  *          Use of value class instances for synchronization, mutexes, or with
116  *          {@linkplain java.lang.ref.Reference object references} result in
117  *          {@link IdentityException}.
118  *      </div>
119  * </div>
120  *
121  * @implSpec
122  * This class is immutable and thread-safe.
123  *
124  * @since 1.8
125  */
126 @jdk.internal.ValueBased
127 @jdk.internal.MigratedValueClass
128 public final class HijrahDate
129         extends ChronoLocalDateImpl<HijrahDate>
130         implements ChronoLocalDate, Serializable {
131 
132     /**
133      * Serialization version.
134      */
135     @java.io.Serial
136     private static final long serialVersionUID = -5207853542612002020L;
137     /**
138      * The Chronology of this HijrahDate.
139      */
140     private final transient HijrahChronology chrono;
141     /**
142      * The proleptic year.
143      */
144     private final transient int prolepticYear;
145     /**
146      * The month-of-year.
147      */

647      *
648      * @return a suitable hash code based only on the Chronology and the date
649      */
650     @Override  // override for performance
651     public int hashCode() {
652         int yearValue = prolepticYear;
653         int monthValue = monthOfYear;
654         int dayValue = dayOfMonth;
655         return getChronology().getId().hashCode() ^ (yearValue & 0xFFFFF800)
656                 ^ ((yearValue << 11) + (monthValue << 6) + (dayValue));
657     }
658 
659     //-----------------------------------------------------------------------
660     /**
661      * Defend against malicious streams.
662      *
663      * @param s the stream to read
664      * @throws InvalidObjectException always
665      */
666     @java.io.Serial
667     @SuppressWarnings("serial") // this method is not invoked for value classes
668     private void readObject(ObjectInputStream s) throws InvalidObjectException {
669         throw new InvalidObjectException("Deserialization via serialization delegate");
670     }
671 
672     /**
673      * Writes the object using a
674      * <a href="{@docRoot}/serialized-form.html#java.time.chrono.Ser">dedicated serialized form</a>.
675      * @serialData
676      * <pre>
677      *  out.writeByte(6);                 // identifies a HijrahDate
678      *  out.writeObject(chrono);          // the HijrahChronology variant
679      *  out.writeInt(get(YEAR));
680      *  out.writeByte(get(MONTH_OF_YEAR));
681      *  out.writeByte(get(DAY_OF_MONTH));
682      * </pre>
683      *
684      * @return the instance of {@code Ser}, not null
685      */
686     @java.io.Serial
687     private Object writeReplace() {
< prev index next >