Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/time/chrono/HijrahDate.java
38918 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* Copyright (c) 2012, Stephen Colebourne & Michael Nascimento Santos27*28* All rights reserved.29*30* Redistribution and use in source and binary forms, with or without31* modification, are permitted provided that the following conditions are met:32*33* * Redistributions of source code must retain the above copyright notice,34* this list of conditions and the following disclaimer.35*36* * Redistributions in binary form must reproduce the above copyright notice,37* this list of conditions and the following disclaimer in the documentation38* and/or other materials provided with the distribution.39*40* * Neither the name of JSR-310 nor the names of its contributors41* may be used to endorse or promote products derived from this software42* without specific prior written permission.43*44* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS45* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT46* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR47* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR48* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,49* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,50* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR51* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF52* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING53* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS54* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.55*/56package java.time.chrono;5758import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH;59import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR;60import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH;61import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR;62import static java.time.temporal.ChronoField.DAY_OF_MONTH;63import static java.time.temporal.ChronoField.MONTH_OF_YEAR;64import static java.time.temporal.ChronoField.YEAR;6566import java.io.IOException;67import java.io.InvalidObjectException;68import java.io.ObjectInput;69import java.io.ObjectInputStream;70import java.io.ObjectOutput;71import java.io.Serializable;72import java.time.Clock;73import java.time.DateTimeException;74import java.time.LocalDate;75import java.time.LocalTime;76import java.time.ZoneId;77import java.time.temporal.ChronoField;78import java.time.temporal.TemporalAccessor;79import java.time.temporal.TemporalAdjuster;80import java.time.temporal.TemporalAmount;81import java.time.temporal.TemporalField;82import java.time.temporal.TemporalQuery;83import java.time.temporal.TemporalUnit;84import java.time.temporal.UnsupportedTemporalTypeException;85import java.time.temporal.ValueRange;8687/**88* A date in the Hijrah calendar system.89* <p>90* This date operates using one of several variants of the91* {@linkplain HijrahChronology Hijrah calendar}.92* <p>93* The Hijrah calendar has a different total of days in a year than94* Gregorian calendar, and the length of each month is based on the period95* of a complete revolution of the moon around the earth96* (as between successive new moons).97* Refer to the {@link HijrahChronology} for details of supported variants.98* <p>99* Each HijrahDate is created bound to a particular HijrahChronology,100* The same chronology is propagated to each HijrahDate computed from the date.101* To use a different Hijrah variant, its HijrahChronology can be used102* to create new HijrahDate instances.103* Alternatively, the {@link #withVariant} method can be used to convert104* to a new HijrahChronology.105*106* <p>107* This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>108* class; use of identity-sensitive operations (including reference equality109* ({@code ==}), identity hash code, or synchronization) on instances of110* {@code HijrahDate} may have unpredictable results and should be avoided.111* The {@code equals} method should be used for comparisons.112*113* @implSpec114* This class is immutable and thread-safe.115*116* @since 1.8117*/118public final class HijrahDate119extends ChronoLocalDateImpl<HijrahDate>120implements ChronoLocalDate, Serializable {121122/**123* Serialization version.124*/125private static final long serialVersionUID = -5207853542612002020L;126/**127* The Chronology of this HijrahDate.128*/129private final transient HijrahChronology chrono;130/**131* The proleptic year.132*/133private final transient int prolepticYear;134/**135* The month-of-year.136*/137private final transient int monthOfYear;138/**139* The day-of-month.140*/141private final transient int dayOfMonth;142143//-------------------------------------------------------------------------144/**145* Obtains an instance of {@code HijrahDate} from the Hijrah proleptic year,146* month-of-year and day-of-month.147*148* @param prolepticYear the proleptic year to represent in the Hijrah calendar149* @param monthOfYear the month-of-year to represent, from 1 to 12150* @param dayOfMonth the day-of-month to represent, from 1 to 30151* @return the Hijrah date, never null152* @throws DateTimeException if the value of any field is out of range153*/154static HijrahDate of(HijrahChronology chrono, int prolepticYear, int monthOfYear, int dayOfMonth) {155return new HijrahDate(chrono, prolepticYear, monthOfYear, dayOfMonth);156}157158/**159* Returns a HijrahDate for the chronology and epochDay.160* @param chrono The Hijrah chronology161* @param epochDay the epoch day162* @return a HijrahDate for the epoch day; non-null163*/164static HijrahDate ofEpochDay(HijrahChronology chrono, long epochDay) {165return new HijrahDate(chrono, epochDay);166}167168//-----------------------------------------------------------------------169/**170* Obtains the current {@code HijrahDate} of the Islamic Umm Al-Qura calendar171* in the default time-zone.172* <p>173* This will query the {@link Clock#systemDefaultZone() system clock} in the default174* time-zone to obtain the current date.175* <p>176* Using this method will prevent the ability to use an alternate clock for testing177* because the clock is hard-coded.178*179* @return the current date using the system clock and default time-zone, not null180*/181public static HijrahDate now() {182return now(Clock.systemDefaultZone());183}184185/**186* Obtains the current {@code HijrahDate} of the Islamic Umm Al-Qura calendar187* in the specified time-zone.188* <p>189* This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date.190* Specifying the time-zone avoids dependence on the default time-zone.191* <p>192* Using this method will prevent the ability to use an alternate clock for testing193* because the clock is hard-coded.194*195* @param zone the zone ID to use, not null196* @return the current date using the system clock, not null197*/198public static HijrahDate now(ZoneId zone) {199return now(Clock.system(zone));200}201202/**203* Obtains the current {@code HijrahDate} of the Islamic Umm Al-Qura calendar204* from the specified clock.205* <p>206* This will query the specified clock to obtain the current date - today.207* Using this method allows the use of an alternate clock for testing.208* The alternate clock may be introduced using {@linkplain Clock dependency injection}.209*210* @param clock the clock to use, not null211* @return the current date, not null212* @throws DateTimeException if the current date cannot be obtained213*/214public static HijrahDate now(Clock clock) {215return HijrahDate.ofEpochDay(HijrahChronology.INSTANCE, LocalDate.now(clock).toEpochDay());216}217218/**219* Obtains a {@code HijrahDate} of the Islamic Umm Al-Qura calendar220* from the proleptic-year, month-of-year and day-of-month fields.221* <p>222* This returns a {@code HijrahDate} with the specified fields.223* The day must be valid for the year and month, otherwise an exception will be thrown.224*225* @param prolepticYear the Hijrah proleptic-year226* @param month the Hijrah month-of-year, from 1 to 12227* @param dayOfMonth the Hijrah day-of-month, from 1 to 30228* @return the date in Hijrah calendar system, not null229* @throws DateTimeException if the value of any field is out of range,230* or if the day-of-month is invalid for the month-year231*/232public static HijrahDate of(int prolepticYear, int month, int dayOfMonth) {233return HijrahChronology.INSTANCE.date(prolepticYear, month, dayOfMonth);234}235236/**237* Obtains a {@code HijrahDate} of the Islamic Umm Al-Qura calendar from a temporal object.238* <p>239* This obtains a date in the Hijrah calendar system based on the specified temporal.240* A {@code TemporalAccessor} represents an arbitrary set of date and time information,241* which this factory converts to an instance of {@code HijrahDate}.242* <p>243* The conversion typically uses the {@link ChronoField#EPOCH_DAY EPOCH_DAY}244* field, which is standardized across calendar systems.245* <p>246* This method matches the signature of the functional interface {@link TemporalQuery}247* allowing it to be used as a query via method reference, {@code HijrahDate::from}.248*249* @param temporal the temporal object to convert, not null250* @return the date in Hijrah calendar system, not null251* @throws DateTimeException if unable to convert to a {@code HijrahDate}252*/253public static HijrahDate from(TemporalAccessor temporal) {254return HijrahChronology.INSTANCE.date(temporal);255}256257//-----------------------------------------------------------------------258/**259* Constructs an {@code HijrahDate} with the proleptic-year, month-of-year and260* day-of-month fields.261*262* @param chrono The chronology to create the date with263* @param prolepticYear the proleptic year264* @param monthOfYear the month of year265* @param dayOfMonth the day of month266*/267private HijrahDate(HijrahChronology chrono, int prolepticYear, int monthOfYear, int dayOfMonth) {268// Computing the Gregorian day checks the valid ranges269chrono.getEpochDay(prolepticYear, monthOfYear, dayOfMonth);270271this.chrono = chrono;272this.prolepticYear = prolepticYear;273this.monthOfYear = monthOfYear;274this.dayOfMonth = dayOfMonth;275}276277/**278* Constructs an instance with the Epoch Day.279*280* @param epochDay the epochDay281*/282private HijrahDate(HijrahChronology chrono, long epochDay) {283int[] dateInfo = chrono.getHijrahDateInfo((int)epochDay);284285this.chrono = chrono;286this.prolepticYear = dateInfo[0];287this.monthOfYear = dateInfo[1];288this.dayOfMonth = dateInfo[2];289}290291//-----------------------------------------------------------------------292/**293* Gets the chronology of this date, which is the Hijrah calendar system.294* <p>295* The {@code Chronology} represents the calendar system in use.296* The era and other fields in {@link ChronoField} are defined by the chronology.297*298* @return the Hijrah chronology, not null299*/300@Override301public HijrahChronology getChronology() {302return chrono;303}304305/**306* Gets the era applicable at this date.307* <p>308* The Hijrah calendar system has one era, 'AH',309* defined by {@link HijrahEra}.310*311* @return the era applicable at this date, not null312*/313@Override314public HijrahEra getEra() {315return HijrahEra.AH;316}317318/**319* Returns the length of the month represented by this date.320* <p>321* This returns the length of the month in days.322* Month lengths in the Hijrah calendar system vary between 29 and 30 days.323*324* @return the length of the month in days325*/326@Override327public int lengthOfMonth() {328return chrono.getMonthLength(prolepticYear, monthOfYear);329}330331/**332* Returns the length of the year represented by this date.333* <p>334* This returns the length of the year in days.335* A Hijrah calendar system year is typically shorter than336* that of the ISO calendar system.337*338* @return the length of the year in days339*/340@Override341public int lengthOfYear() {342return chrono.getYearLength(prolepticYear);343}344345//-----------------------------------------------------------------------346@Override347public ValueRange range(TemporalField field) {348if (field instanceof ChronoField) {349if (isSupported(field)) {350ChronoField f = (ChronoField) field;351switch (f) {352case DAY_OF_MONTH: return ValueRange.of(1, lengthOfMonth());353case DAY_OF_YEAR: return ValueRange.of(1, lengthOfYear());354case ALIGNED_WEEK_OF_MONTH: return ValueRange.of(1, 5); // TODO355// TODO does the limited range of valid years cause years to356// start/end part way through? that would affect range357}358return getChronology().range(f);359}360throw new UnsupportedTemporalTypeException("Unsupported field: " + field);361}362return field.rangeRefinedBy(this);363}364365@Override366public long getLong(TemporalField field) {367if (field instanceof ChronoField) {368switch ((ChronoField) field) {369case DAY_OF_WEEK: return getDayOfWeek();370case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((getDayOfWeek() - 1) % 7) + 1;371case ALIGNED_DAY_OF_WEEK_IN_YEAR: return ((getDayOfYear() - 1) % 7) + 1;372case DAY_OF_MONTH: return this.dayOfMonth;373case DAY_OF_YEAR: return this.getDayOfYear();374case EPOCH_DAY: return toEpochDay();375case ALIGNED_WEEK_OF_MONTH: return ((dayOfMonth - 1) / 7) + 1;376case ALIGNED_WEEK_OF_YEAR: return ((getDayOfYear() - 1) / 7) + 1;377case MONTH_OF_YEAR: return monthOfYear;378case PROLEPTIC_MONTH: return getProlepticMonth();379case YEAR_OF_ERA: return prolepticYear;380case YEAR: return prolepticYear;381case ERA: return getEraValue();382}383throw new UnsupportedTemporalTypeException("Unsupported field: " + field);384}385return field.getFrom(this);386}387388private long getProlepticMonth() {389return prolepticYear * 12L + monthOfYear - 1;390}391392@Override393public HijrahDate with(TemporalField field, long newValue) {394if (field instanceof ChronoField) {395ChronoField f = (ChronoField) field;396// not using checkValidIntValue so EPOCH_DAY and PROLEPTIC_MONTH work397chrono.range(f).checkValidValue(newValue, f); // TODO: validate value398int nvalue = (int) newValue;399switch (f) {400case DAY_OF_WEEK: return plusDays(newValue - getDayOfWeek());401case ALIGNED_DAY_OF_WEEK_IN_MONTH: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_MONTH));402case ALIGNED_DAY_OF_WEEK_IN_YEAR: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_YEAR));403case DAY_OF_MONTH: return resolvePreviousValid(prolepticYear, monthOfYear, nvalue);404case DAY_OF_YEAR: return plusDays(Math.min(nvalue, lengthOfYear()) - getDayOfYear());405case EPOCH_DAY: return new HijrahDate(chrono, newValue);406case ALIGNED_WEEK_OF_MONTH: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_MONTH)) * 7);407case ALIGNED_WEEK_OF_YEAR: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_YEAR)) * 7);408case MONTH_OF_YEAR: return resolvePreviousValid(prolepticYear, nvalue, dayOfMonth);409case PROLEPTIC_MONTH: return plusMonths(newValue - getProlepticMonth());410case YEAR_OF_ERA: return resolvePreviousValid(prolepticYear >= 1 ? nvalue : 1 - nvalue, monthOfYear, dayOfMonth);411case YEAR: return resolvePreviousValid(nvalue, monthOfYear, dayOfMonth);412case ERA: return resolvePreviousValid(1 - prolepticYear, monthOfYear, dayOfMonth);413}414throw new UnsupportedTemporalTypeException("Unsupported field: " + field);415}416return super.with(field, newValue);417}418419private HijrahDate resolvePreviousValid(int prolepticYear, int month, int day) {420int monthDays = chrono.getMonthLength(prolepticYear, month);421if (day > monthDays) {422day = monthDays;423}424return HijrahDate.of(chrono, prolepticYear, month, day);425}426427/**428* {@inheritDoc}429* @throws DateTimeException if unable to make the adjustment.430* For example, if the adjuster requires an ISO chronology431* @throws ArithmeticException {@inheritDoc}432*/433@Override434public HijrahDate with(TemporalAdjuster adjuster) {435return super.with(adjuster);436}437438/**439* Returns a {@code HijrahDate} with the Chronology requested.440* <p>441* The year, month, and day are checked against the new requested442* HijrahChronology. If the chronology has a shorter month length443* for the month, the day is reduced to be the last day of the month.444*445* @param chronology the new HijrahChonology, non-null446* @return a HijrahDate with the requested HijrahChronology, non-null447*/448public HijrahDate withVariant(HijrahChronology chronology) {449if (chrono == chronology) {450return this;451}452// Like resolvePreviousValid the day is constrained to stay in the same month453int monthDays = chronology.getDayOfYear(prolepticYear, monthOfYear);454return HijrahDate.of(chronology, prolepticYear, monthOfYear,(dayOfMonth > monthDays) ? monthDays : dayOfMonth );455}456457/**458* {@inheritDoc}459* @throws DateTimeException {@inheritDoc}460* @throws ArithmeticException {@inheritDoc}461*/462@Override463public HijrahDate plus(TemporalAmount amount) {464return super.plus(amount);465}466467/**468* {@inheritDoc}469* @throws DateTimeException {@inheritDoc}470* @throws ArithmeticException {@inheritDoc}471*/472@Override473public HijrahDate minus(TemporalAmount amount) {474return super.minus(amount);475}476477@Override478public long toEpochDay() {479return chrono.getEpochDay(prolepticYear, monthOfYear, dayOfMonth);480}481482/**483* Gets the day-of-year field.484* <p>485* This method returns the primitive {@code int} value for the day-of-year.486*487* @return the day-of-year488*/489private int getDayOfYear() {490return chrono.getDayOfYear(prolepticYear, monthOfYear) + dayOfMonth;491}492493/**494* Gets the day-of-week value.495*496* @return the day-of-week; computed from the epochday497*/498private int getDayOfWeek() {499int dow0 = (int)Math.floorMod(toEpochDay() + 3, 7);500return dow0 + 1;501}502503/**504* Gets the Era of this date.505*506* @return the Era of this date; computed from epochDay507*/508private int getEraValue() {509return (prolepticYear > 1 ? 1 : 0);510}511512//-----------------------------------------------------------------------513/**514* Checks if the year is a leap year, according to the Hijrah calendar system rules.515*516* @return true if this date is in a leap year517*/518@Override519public boolean isLeapYear() {520return chrono.isLeapYear(prolepticYear);521}522523//-----------------------------------------------------------------------524@Override525HijrahDate plusYears(long years) {526if (years == 0) {527return this;528}529int newYear = Math.addExact(this.prolepticYear, (int)years);530return resolvePreviousValid(newYear, monthOfYear, dayOfMonth);531}532533@Override534HijrahDate plusMonths(long monthsToAdd) {535if (monthsToAdd == 0) {536return this;537}538long monthCount = prolepticYear * 12L + (monthOfYear - 1);539long calcMonths = monthCount + monthsToAdd; // safe overflow540int newYear = chrono.checkValidYear(Math.floorDiv(calcMonths, 12L));541int newMonth = (int)Math.floorMod(calcMonths, 12L) + 1;542return resolvePreviousValid(newYear, newMonth, dayOfMonth);543}544545@Override546HijrahDate plusWeeks(long weeksToAdd) {547return super.plusWeeks(weeksToAdd);548}549550@Override551HijrahDate plusDays(long days) {552return new HijrahDate(chrono, toEpochDay() + days);553}554555@Override556public HijrahDate plus(long amountToAdd, TemporalUnit unit) {557return super.plus(amountToAdd, unit);558}559560@Override561public HijrahDate minus(long amountToSubtract, TemporalUnit unit) {562return super.minus(amountToSubtract, unit);563}564565@Override566HijrahDate minusYears(long yearsToSubtract) {567return super.minusYears(yearsToSubtract);568}569570@Override571HijrahDate minusMonths(long monthsToSubtract) {572return super.minusMonths(monthsToSubtract);573}574575@Override576HijrahDate minusWeeks(long weeksToSubtract) {577return super.minusWeeks(weeksToSubtract);578}579580@Override581HijrahDate minusDays(long daysToSubtract) {582return super.minusDays(daysToSubtract);583}584585@Override // for javadoc and covariant return type586@SuppressWarnings("unchecked")587public final ChronoLocalDateTime<HijrahDate> atTime(LocalTime localTime) {588return (ChronoLocalDateTime<HijrahDate>)super.atTime(localTime);589}590591@Override592public ChronoPeriod until(ChronoLocalDate endDate) {593// TODO: untested594HijrahDate end = getChronology().date(endDate);595long totalMonths = (end.prolepticYear - this.prolepticYear) * 12 + (end.monthOfYear - this.monthOfYear); // safe596int days = end.dayOfMonth - this.dayOfMonth;597if (totalMonths > 0 && days < 0) {598totalMonths--;599HijrahDate calcDate = this.plusMonths(totalMonths);600days = (int) (end.toEpochDay() - calcDate.toEpochDay()); // safe601} else if (totalMonths < 0 && days > 0) {602totalMonths++;603days -= end.lengthOfMonth();604}605long years = totalMonths / 12; // safe606int months = (int) (totalMonths % 12); // safe607return getChronology().period(Math.toIntExact(years), months, days);608}609610//-------------------------------------------------------------------------611/**612* Compares this date to another date, including the chronology.613* <p>614* Compares this {@code HijrahDate} with another ensuring that the date is the same.615* <p>616* Only objects of type {@code HijrahDate} are compared, other types return false.617* To compare the dates of two {@code TemporalAccessor} instances, including dates618* in two different chronologies, use {@link ChronoField#EPOCH_DAY} as a comparator.619*620* @param obj the object to check, null returns false621* @return true if this is equal to the other date and the Chronologies are equal622*/623@Override // override for performance624public boolean equals(Object obj) {625if (this == obj) {626return true;627}628if (obj instanceof HijrahDate) {629HijrahDate otherDate = (HijrahDate) obj;630return prolepticYear == otherDate.prolepticYear631&& this.monthOfYear == otherDate.monthOfYear632&& this.dayOfMonth == otherDate.dayOfMonth633&& getChronology().equals(otherDate.getChronology());634}635return false;636}637638/**639* A hash code for this date.640*641* @return a suitable hash code based only on the Chronology and the date642*/643@Override // override for performance644public int hashCode() {645int yearValue = prolepticYear;646int monthValue = monthOfYear;647int dayValue = dayOfMonth;648return getChronology().getId().hashCode() ^ (yearValue & 0xFFFFF800)649^ ((yearValue << 11) + (monthValue << 6) + (dayValue));650}651652//-----------------------------------------------------------------------653/**654* Defend against malicious streams.655*656* @param s the stream to read657* @throws InvalidObjectException always658*/659private void readObject(ObjectInputStream s) throws InvalidObjectException {660throw new InvalidObjectException("Deserialization via serialization delegate");661}662663/**664* Writes the object using a665* <a href="../../../serialized-form.html#java.time.chrono.Ser">dedicated serialized form</a>.666* @serialData667* <pre>668* out.writeByte(6); // identifies a HijrahDate669* out.writeObject(chrono); // the HijrahChronology variant670* 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 null676*/677private Object writeReplace() {678return new Ser(Ser.HIJRAH_DATE_TYPE, this);679}680681void writeExternal(ObjectOutput out) throws IOException {682// HijrahChronology is implicit in the Hijrah_DATE_TYPE683out.writeObject(getChronology());684out.writeInt(get(YEAR));685out.writeByte(get(MONTH_OF_YEAR));686out.writeByte(get(DAY_OF_MONTH));687}688689static HijrahDate readExternal(ObjectInput in) throws IOException, ClassNotFoundException {690HijrahChronology chrono = (HijrahChronology) in.readObject();691int year = in.readInt();692int month = in.readByte();693int dayOfMonth = in.readByte();694return chrono.date(year, month, dayOfMonth);695}696697}698699700