8269124: Update java.time to use switch expressions (part II)

Reviewed-by: dfuchs, vtewari, aefimov, iris, lancea, naoto
This commit is contained in:
Patrick Concannon 2021-07-05 09:08:13 +00:00
parent 675a9520b2
commit 8a7b380ebb
16 changed files with 322 additions and 370 deletions

View file

@ -967,13 +967,12 @@ public final class OffsetDateTime
@Override
public OffsetDateTime with(TemporalField field, long newValue) {
if (field instanceof ChronoField chronoField) {
switch (chronoField) {
case INSTANT_SECONDS: return ofInstant(Instant.ofEpochSecond(newValue, getNano()), offset);
case OFFSET_SECONDS: {
return with(dateTime, ZoneOffset.ofTotalSeconds(chronoField.checkValidIntValue(newValue)));
}
}
return with(dateTime.with(field, newValue), offset);
return switch (chronoField) {
case INSTANT_SECONDS -> ofInstant(Instant.ofEpochSecond(newValue, getNano()), offset);
case OFFSET_SECONDS ->
with(dateTime, ZoneOffset.ofTotalSeconds(chronoField.checkValidIntValue(newValue)));
default -> with(dateTime.with(field, newValue), offset);
};
}
return field.adjustInto(this, newValue);
}