/** * Returns a copy of this date with the year-of-era altered. * <p> * This method changes the year-of-era of the date. * If the month-day is invalid for the year, then the previous valid day * will be selected instead. * <p> * This instance is immutable and unaffected by this method call. * * @param year the year to set in the returned date * @return a {@code JapaneseDate} based on this date with the requested year-of-era, never null * @throws DateTimeException if {@code year} is invalid */ private JapaneseDate withYear(int year) { return withYear(getEra(), year); }
@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); }