93 *
94 * <p>
95 * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
96 * class; use of identity-sensitive operations (including reference equality
97 * ({@code ==}), identity hash code, or synchronization) on instances of
98 * {@code MinguoDate} may have unpredictable results and should be avoided.
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 public final class MinguoDate
107 extends ChronoLocalDateImpl<MinguoDate>
108 implements ChronoLocalDate, Serializable {
109
110 /**
111 * Serialization version.
112 */
113 private static final long serialVersionUID = 1300372329181994526L;
114
115 /**
116 * The underlying date.
117 */
118 private final transient LocalDate isoDate;
119
120 //-----------------------------------------------------------------------
121 /**
122 * Obtains the current {@code MinguoDate} from the system clock in the default time-zone.
123 * <p>
124 * This will query the {@link Clock#systemDefaultZone() system clock} in the default
125 * time-zone to obtain the current date.
126 * <p>
127 * Using this method will prevent the ability to use an alternate clock for testing
128 * because the clock is hard-coded.
129 *
130 * @return the current date using the system clock and default time-zone, not null
131 */
132 public static MinguoDate now() {
464 return false;
465 }
466
467 /**
468 * A hash code for this date.
469 *
470 * @return a suitable hash code based only on the Chronology and the date
471 */
472 @Override // override for performance
473 public int hashCode() {
474 return getChronology().getId().hashCode() ^ isoDate.hashCode();
475 }
476
477 //-----------------------------------------------------------------------
478 /**
479 * Defend against malicious streams.
480 *
481 * @param s the stream to read
482 * @throws InvalidObjectException always
483 */
484 private void readObject(ObjectInputStream s) throws InvalidObjectException {
485 throw new InvalidObjectException("Deserialization via serialization delegate");
486 }
487
488 /**
489 * Writes the object using a
490 * <a href="{@docRoot}/serialized-form.html#java.time.chrono.Ser">dedicated serialized form</a>.
491 * @serialData
492 * <pre>
493 * out.writeByte(8); // identifies a MinguoDate
494 * out.writeInt(get(YEAR));
495 * out.writeByte(get(MONTH_OF_YEAR));
496 * out.writeByte(get(DAY_OF_MONTH));
497 * </pre>
498 *
499 * @return the instance of {@code Ser}, not null
500 */
501 private Object writeReplace() {
502 return new Ser(Ser.MINGUO_DATE_TYPE, this);
503 }
504
505 void writeExternal(DataOutput out) throws IOException {
506 // MinguoChronology is implicit in the MINGUO_DATE_TYPE
507 out.writeInt(get(YEAR));
508 out.writeByte(get(MONTH_OF_YEAR));
509 out.writeByte(get(DAY_OF_MONTH));
510 }
511
512 static MinguoDate readExternal(DataInput in) throws IOException {
513 int year = in.readInt();
514 int month = in.readByte();
515 int dayOfMonth = in.readByte();
516 return MinguoChronology.INSTANCE.date(year, month, dayOfMonth);
517 }
518
519 }
|
93 *
94 * <p>
95 * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
96 * class; use of identity-sensitive operations (including reference equality
97 * ({@code ==}), identity hash code, or synchronization) on instances of
98 * {@code MinguoDate} may have unpredictable results and should be avoided.
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 public final class MinguoDate
107 extends ChronoLocalDateImpl<MinguoDate>
108 implements ChronoLocalDate, Serializable {
109
110 /**
111 * Serialization version.
112 */
113 @java.io.Serial
114 private static final long serialVersionUID = 1300372329181994526L;
115
116 /**
117 * The underlying date.
118 */
119 private final transient LocalDate isoDate;
120
121 //-----------------------------------------------------------------------
122 /**
123 * Obtains the current {@code MinguoDate} from the system clock in the default time-zone.
124 * <p>
125 * This will query the {@link Clock#systemDefaultZone() system clock} in the default
126 * time-zone to obtain the current date.
127 * <p>
128 * Using this method will prevent the ability to use an alternate clock for testing
129 * because the clock is hard-coded.
130 *
131 * @return the current date using the system clock and default time-zone, not null
132 */
133 public static MinguoDate now() {
465 return false;
466 }
467
468 /**
469 * A hash code for this date.
470 *
471 * @return a suitable hash code based only on the Chronology and the date
472 */
473 @Override // override for performance
474 public int hashCode() {
475 return getChronology().getId().hashCode() ^ isoDate.hashCode();
476 }
477
478 //-----------------------------------------------------------------------
479 /**
480 * Defend against malicious streams.
481 *
482 * @param s the stream to read
483 * @throws InvalidObjectException always
484 */
485 @java.io.Serial
486 private void readObject(ObjectInputStream s) throws InvalidObjectException {
487 throw new InvalidObjectException("Deserialization via serialization delegate");
488 }
489
490 /**
491 * Writes the object using a
492 * <a href="{@docRoot}/serialized-form.html#java.time.chrono.Ser">dedicated serialized form</a>.
493 * @serialData
494 * <pre>
495 * out.writeByte(8); // identifies a MinguoDate
496 * out.writeInt(get(YEAR));
497 * out.writeByte(get(MONTH_OF_YEAR));
498 * out.writeByte(get(DAY_OF_MONTH));
499 * </pre>
500 *
501 * @return the instance of {@code Ser}, not null
502 */
503 @java.io.Serial
504 private Object writeReplace() {
505 return new Ser(Ser.MINGUO_DATE_TYPE, this);
506 }
507
508 void writeExternal(DataOutput out) throws IOException {
509 // MinguoChronology is implicit in the MINGUO_DATE_TYPE
510 out.writeInt(get(YEAR));
511 out.writeByte(get(MONTH_OF_YEAR));
512 out.writeByte(get(DAY_OF_MONTH));
513 }
514
515 static MinguoDate readExternal(DataInput in) throws IOException {
516 int year = in.readInt();
517 int month = in.readByte();
518 int dayOfMonth = in.readByte();
519 return MinguoChronology.INSTANCE.date(year, month, dayOfMonth);
520 }
521
522 }
|