mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8269124: Update java.time to use switch expressions (part II)
Reviewed-by: dfuchs, vtewari, aefimov, iris, lancea, naoto
This commit is contained in:
parent
675a9520b2
commit
8a7b380ebb
16 changed files with 322 additions and 370 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue