95 * A date in the Japanese Imperial calendar system.
96 * <p>
97 * This date operates using the {@linkplain JapaneseChronology Japanese Imperial calendar}.
98 * This calendar system is primarily used in Japan.
99 * <p>
100 * The Japanese Imperial calendar system is the same as the ISO calendar system
101 * apart from the era-based year numbering. The proleptic-year is defined to be
102 * equal to the ISO proleptic-year.
103 * <p>
104 * Japan introduced the Gregorian calendar starting with Meiji 6.
105 * Only Meiji and later eras are supported;
106 * dates before Meiji 6, January 1 are not supported.
107 * <p>
108 * For example, the Japanese year "Heisei 24" corresponds to ISO year "2012".<br>
109 * Calling {@code japaneseDate.get(YEAR_OF_ERA)} will return 24.<br>
110 * Calling {@code japaneseDate.get(YEAR)} will return 2012.<br>
111 * Calling {@code japaneseDate.get(ERA)} will return 2, corresponding to
112 * {@code JapaneseChronology.ERA_HEISEI}.<br>
113 * <p>
114 * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
115 * class; programmers should treat instances that are
116 * {@linkplain #equals(Object) equal} as interchangeable and should not
117 * use instances for synchronization, or unpredictable behavior may
118 * occur. For example, in a future release, synchronization may fail.
119 * The {@code equals} method should be used for comparisons.
120 *
121 * @implSpec
122 * This class is immutable and thread-safe.
123 *
124 * @since 1.8
125 */
126 @jdk.internal.ValueBased
127 public final class JapaneseDate
128 extends ChronoLocalDateImpl<JapaneseDate>
129 implements ChronoLocalDate, Serializable {
130
131 /**
132 * Serialization version.
133 */
134 @java.io.Serial
135 private static final long serialVersionUID = -305327627230580483L;
136
137 /**
138 * The underlying ISO local date.
139 */
140 private final transient LocalDate isoDate;
141 /**
142 * The JapaneseEra of this date.
143 */
144 private final transient JapaneseEra era;
145 /**
146 * The Japanese imperial calendar year of this date.
700 }
701
702 /**
703 * A hash code for this date.
704 *
705 * @return a suitable hash code based only on the Chronology and the date
706 */
707 @Override // override for performance
708 public int hashCode() {
709 return getChronology().getId().hashCode() ^ isoDate.hashCode();
710 }
711
712 //-----------------------------------------------------------------------
713 /**
714 * Defend against malicious streams.
715 *
716 * @param s the stream to read
717 * @throws InvalidObjectException always
718 */
719 @java.io.Serial
720 private void readObject(ObjectInputStream s) throws InvalidObjectException {
721 throw new InvalidObjectException("Deserialization via serialization delegate");
722 }
723
724 /**
725 * Writes the object using a
726 * <a href="{@docRoot}/serialized-form.html#java.time.chrono.Ser">dedicated serialized form</a>.
727 * @serialData
728 * <pre>
729 * out.writeByte(4); // identifies a JapaneseDate
730 * out.writeInt(get(YEAR));
731 * out.writeByte(get(MONTH_OF_YEAR));
732 * out.writeByte(get(DAY_OF_MONTH));
733 * </pre>
734 *
735 * @return the instance of {@code Ser}, not null
736 */
737 @java.io.Serial
738 private Object writeReplace() {
739 return new Ser(Ser.JAPANESE_DATE_TYPE, this);
|
95 * A date in the Japanese Imperial calendar system.
96 * <p>
97 * This date operates using the {@linkplain JapaneseChronology Japanese Imperial calendar}.
98 * This calendar system is primarily used in Japan.
99 * <p>
100 * The Japanese Imperial calendar system is the same as the ISO calendar system
101 * apart from the era-based year numbering. The proleptic-year is defined to be
102 * equal to the ISO proleptic-year.
103 * <p>
104 * Japan introduced the Gregorian calendar starting with Meiji 6.
105 * Only Meiji and later eras are supported;
106 * dates before Meiji 6, January 1 are not supported.
107 * <p>
108 * For example, the Japanese year "Heisei 24" corresponds to ISO year "2012".<br>
109 * Calling {@code japaneseDate.get(YEAR_OF_ERA)} will return 24.<br>
110 * Calling {@code japaneseDate.get(YEAR)} will return 2012.<br>
111 * Calling {@code japaneseDate.get(ERA)} will return 2, corresponding to
112 * {@code JapaneseChronology.ERA_HEISEI}.<br>
113 * <p>
114 * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
115 * class; programmers should treat instances that are {@linkplain #equals(Object) equal}
116 * as interchangeable and should not use instances for synchronization, mutexes, or
117 * with {@linkplain java.lang.ref.Reference object references}.
118 *
119 * <div class="preview-block">
120 * <div class="preview-comment">
121 * When preview features are enabled, {@code JapaneseDate} is a {@linkplain Class#isValue value class}.
122 * Use of value class instances for synchronization, mutexes, or with
123 * {@linkplain java.lang.ref.Reference object references} result in
124 * {@link IdentityException}.
125 * </div>
126 * </div>
127 *
128 * @implSpec
129 * This class is immutable and thread-safe.
130 *
131 * @since 1.8
132 */
133 @jdk.internal.ValueBased
134 @jdk.internal.MigratedValueClass
135 public final class JapaneseDate
136 extends ChronoLocalDateImpl<JapaneseDate>
137 implements ChronoLocalDate, Serializable {
138
139 /**
140 * Serialization version.
141 */
142 @java.io.Serial
143 private static final long serialVersionUID = -305327627230580483L;
144
145 /**
146 * The underlying ISO local date.
147 */
148 private final transient LocalDate isoDate;
149 /**
150 * The JapaneseEra of this date.
151 */
152 private final transient JapaneseEra era;
153 /**
154 * The Japanese imperial calendar year of this date.
708 }
709
710 /**
711 * A hash code for this date.
712 *
713 * @return a suitable hash code based only on the Chronology and the date
714 */
715 @Override // override for performance
716 public int hashCode() {
717 return getChronology().getId().hashCode() ^ isoDate.hashCode();
718 }
719
720 //-----------------------------------------------------------------------
721 /**
722 * Defend against malicious streams.
723 *
724 * @param s the stream to read
725 * @throws InvalidObjectException always
726 */
727 @java.io.Serial
728 @SuppressWarnings("serial") // this method is not invoked for value classes
729 private void readObject(ObjectInputStream s) throws InvalidObjectException {
730 throw new InvalidObjectException("Deserialization via serialization delegate");
731 }
732
733 /**
734 * Writes the object using a
735 * <a href="{@docRoot}/serialized-form.html#java.time.chrono.Ser">dedicated serialized form</a>.
736 * @serialData
737 * <pre>
738 * out.writeByte(4); // identifies a JapaneseDate
739 * out.writeInt(get(YEAR));
740 * out.writeByte(get(MONTH_OF_YEAR));
741 * out.writeByte(get(DAY_OF_MONTH));
742 * </pre>
743 *
744 * @return the instance of {@code Ser}, not null
745 */
746 @java.io.Serial
747 private Object writeReplace() {
748 return new Ser(Ser.JAPANESE_DATE_TYPE, this);
|