< prev index next >

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

Print this page




 149      * The singleton instance for the 'Heisei' era (1989-01-08 - 2019-04-30)
 150      * which has the value 2.
 151      */
 152     public static final JapaneseEra HEISEI = new JapaneseEra(2, LocalDate.of(1989, 1, 8));
 153     /**
 154      * The singleton instance for the 'Reiwa' era (2019-05-01 - )
 155      * which has the value 3. The end date of this era is not specified, unless
 156      * the Japanese Government defines it.
 157      *
 158      * @since 13
 159      */
 160     public static final JapaneseEra REIWA = new JapaneseEra(3, LocalDate.of(2019, 5, 1));
 161 
 162     // The number of predefined JapaneseEra constants.
 163     // There may be a supplemental era defined by the property.
 164     private static final int N_ERA_CONSTANTS = REIWA.getValue() + ERA_OFFSET;
 165 
 166     /**
 167      * Serialization version.
 168      */

 169     private static final long serialVersionUID = 1466499369062886794L;
 170 
 171     // array for the singleton JapaneseEra instances
 172     private static final JapaneseEra[] KNOWN_ERAS;
 173 
 174     static {
 175         ERA_CONFIG = JapaneseChronology.JCAL.getEras();
 176 
 177         KNOWN_ERAS = new JapaneseEra[ERA_CONFIG.length];
 178         KNOWN_ERAS[0] = MEIJI;
 179         KNOWN_ERAS[1] = TAISHO;
 180         KNOWN_ERAS[2] = SHOWA;
 181         KNOWN_ERAS[3] = HEISEI;
 182         KNOWN_ERAS[4] = REIWA;
 183         for (int i = N_ERA_CONSTANTS; i < ERA_CONFIG.length; i++) {
 184             CalendarDate date = ERA_CONFIG[i].getSinceDate();
 185             LocalDate isoDate = LocalDate.of(date.getYear(), date.getMonth(), date.getDayOfMonth());
 186             KNOWN_ERAS[i] = new JapaneseEra(i - ERA_OFFSET + 1, isoDate);
 187         }
 188     };


 409     String getAbbreviation() {
 410         return ERA_CONFIG[ordinal(getValue())].getAbbreviation();
 411     }
 412 
 413     String getName() {
 414         return ERA_CONFIG[ordinal(getValue())].getName();
 415     }
 416 
 417     @Override
 418     public String toString() {
 419         return getName();
 420     }
 421 
 422     //-----------------------------------------------------------------------
 423     /**
 424      * Defend against malicious streams.
 425      *
 426      * @param s the stream to read
 427      * @throws InvalidObjectException always
 428      */

 429     private void readObject(ObjectInputStream s) throws InvalidObjectException {
 430         throw new InvalidObjectException("Deserialization via serialization delegate");
 431     }
 432 
 433     //-----------------------------------------------------------------------
 434     /**
 435      * Writes the object using a
 436      * <a href="{@docRoot}/serialized-form.html#java.time.chrono.Ser">dedicated serialized form</a>.
 437      * @serialData
 438      * <pre>
 439      *  out.writeByte(5);        // identifies a JapaneseEra
 440      *  out.writeInt(getValue());
 441      * </pre>
 442      *
 443      * @return the instance of {@code Ser}, not null
 444      */

 445     private Object writeReplace() {
 446         return new Ser(Ser.JAPANESE_ERA_TYPE, this);
 447     }
 448 
 449     void writeExternal(DataOutput out) throws IOException {
 450         out.writeByte(this.getValue());
 451     }
 452 
 453     static JapaneseEra readExternal(DataInput in) throws IOException {
 454         byte eraValue = in.readByte();
 455         return JapaneseEra.of(eraValue);
 456     }
 457 
 458 }


 149      * The singleton instance for the 'Heisei' era (1989-01-08 - 2019-04-30)
 150      * which has the value 2.
 151      */
 152     public static final JapaneseEra HEISEI = new JapaneseEra(2, LocalDate.of(1989, 1, 8));
 153     /**
 154      * The singleton instance for the 'Reiwa' era (2019-05-01 - )
 155      * which has the value 3. The end date of this era is not specified, unless
 156      * the Japanese Government defines it.
 157      *
 158      * @since 13
 159      */
 160     public static final JapaneseEra REIWA = new JapaneseEra(3, LocalDate.of(2019, 5, 1));
 161 
 162     // The number of predefined JapaneseEra constants.
 163     // There may be a supplemental era defined by the property.
 164     private static final int N_ERA_CONSTANTS = REIWA.getValue() + ERA_OFFSET;
 165 
 166     /**
 167      * Serialization version.
 168      */
 169     @java.io.Serial
 170     private static final long serialVersionUID = 1466499369062886794L;
 171 
 172     // array for the singleton JapaneseEra instances
 173     private static final JapaneseEra[] KNOWN_ERAS;
 174 
 175     static {
 176         ERA_CONFIG = JapaneseChronology.JCAL.getEras();
 177 
 178         KNOWN_ERAS = new JapaneseEra[ERA_CONFIG.length];
 179         KNOWN_ERAS[0] = MEIJI;
 180         KNOWN_ERAS[1] = TAISHO;
 181         KNOWN_ERAS[2] = SHOWA;
 182         KNOWN_ERAS[3] = HEISEI;
 183         KNOWN_ERAS[4] = REIWA;
 184         for (int i = N_ERA_CONSTANTS; i < ERA_CONFIG.length; i++) {
 185             CalendarDate date = ERA_CONFIG[i].getSinceDate();
 186             LocalDate isoDate = LocalDate.of(date.getYear(), date.getMonth(), date.getDayOfMonth());
 187             KNOWN_ERAS[i] = new JapaneseEra(i - ERA_OFFSET + 1, isoDate);
 188         }
 189     };


 410     String getAbbreviation() {
 411         return ERA_CONFIG[ordinal(getValue())].getAbbreviation();
 412     }
 413 
 414     String getName() {
 415         return ERA_CONFIG[ordinal(getValue())].getName();
 416     }
 417 
 418     @Override
 419     public String toString() {
 420         return getName();
 421     }
 422 
 423     //-----------------------------------------------------------------------
 424     /**
 425      * Defend against malicious streams.
 426      *
 427      * @param s the stream to read
 428      * @throws InvalidObjectException always
 429      */
 430     @java.io.Serial
 431     private void readObject(ObjectInputStream s) throws InvalidObjectException {
 432         throw new InvalidObjectException("Deserialization via serialization delegate");
 433     }
 434 
 435     //-----------------------------------------------------------------------
 436     /**
 437      * Writes the object using a
 438      * <a href="{@docRoot}/serialized-form.html#java.time.chrono.Ser">dedicated serialized form</a>.
 439      * @serialData
 440      * <pre>
 441      *  out.writeByte(5);        // identifies a JapaneseEra
 442      *  out.writeInt(getValue());
 443      * </pre>
 444      *
 445      * @return the instance of {@code Ser}, not null
 446      */
 447     @java.io.Serial
 448     private Object writeReplace() {
 449         return new Ser(Ser.JAPANESE_ERA_TYPE, this);
 450     }
 451 
 452     void writeExternal(DataOutput out) throws IOException {
 453         out.writeByte(this.getValue());
 454     }
 455 
 456     static JapaneseEra readExternal(DataInput in) throws IOException {
 457         byte eraValue = in.readByte();
 458         return JapaneseEra.of(eraValue);
 459     }
 460 
 461 }
< prev index next >