/** * Returns the calendar system era object from the given numeric value. * * See the description of each Era for the numeric values of: * {@link JapaneseEra#HEISEI}, {@link JapaneseEra#SHOWA},{@link JapaneseEra#TAISHO}, * {@link JapaneseEra#MEIJI}), only Meiji and later eras are supported. * * @param eraValue the era value * @return the Japanese {@code Era} for the given numeric era value * @throws DateTimeException if {@code eraValue} is invalid */ @Override public JapaneseEra eraOf(int eraValue) { return JapaneseEra.of(eraValue); }
static JapaneseEra readExternal(DataInput in) throws IOException { byte eraValue = in.readByte(); return JapaneseEra.of(eraValue); }
/** * Returns the singleton {@code JapaneseEra} corresponding to this object. * It's possible that this version of {@code JapaneseEra} doesn't support the latest era value. * In that case, this method throws an {@code ObjectStreamException}. * * @return the singleton {@code JapaneseEra} for this object * @throws ObjectStreamException if the deserialized object has any unknown numeric era value. */ private Object readResolve() throws ObjectStreamException { try { return of(eraValue); } catch (DateTimeException e) { InvalidObjectException ex = new InvalidObjectException("Invalid era"); ex.initCause(e); throw ex; } }
@Override public JapaneseDate with(TemporalField field, long newValue) { if (field instanceof ChronoField) { ChronoField f = (ChronoField) field; if (getLong(f) == newValue) { // validates unsupported fields return this; } switch (f) { case DAY_OF_YEAR: case YEAR_OF_ERA: case ERA: { int nvalue = getChronology().range(f).checkValidIntValue(newValue, f); switch (f) { case DAY_OF_YEAR: return with(isoDate.plusDays(nvalue - getDayOfYear())); case YEAR_OF_ERA: return this.withYear(nvalue); case ERA: { return this.withYear(JapaneseEra.of(nvalue), yearOfEra); } } } } return with(isoDate.with(field, newValue)); } return field.adjustInto(this, newValue); }