8268469: Update java.time to use switch expressions

Reviewed-by: lancea, naoto, dfuchs, iris, chegar
This commit is contained in:
Patrick Concannon 2021-06-25 15:42:38 +00:00
parent ffa34ed429
commit 1d167978e5
22 changed files with 256 additions and 337 deletions

View file

@ -814,13 +814,12 @@ public final class ZonedDateTime
@Override // override for Javadoc and performance
public int get(TemporalField field) {
if (field instanceof ChronoField chronoField) {
switch (chronoField) {
case INSTANT_SECONDS:
throw new UnsupportedTemporalTypeException("Invalid field 'InstantSeconds' for get() method, use getLong() instead");
case OFFSET_SECONDS:
return getOffset().getTotalSeconds();
}
return dateTime.get(field);
return switch (chronoField) {
case INSTANT_SECONDS -> throw new UnsupportedTemporalTypeException("Invalid field " +
"'InstantSeconds' for get() method, use getLong() instead");
case OFFSET_SECONDS -> getOffset().getTotalSeconds();
default -> dateTime.get(field);
};
}
return ChronoZonedDateTime.super.get(field);
}
@ -851,11 +850,11 @@ public final class ZonedDateTime
@Override
public long getLong(TemporalField field) {
if (field instanceof ChronoField chronoField) {
switch (chronoField) {
case INSTANT_SECONDS: return toEpochSecond();
case OFFSET_SECONDS: return getOffset().getTotalSeconds();
}
return dateTime.getLong(field);
return switch (chronoField) {
case INSTANT_SECONDS -> toEpochSecond();
case OFFSET_SECONDS -> getOffset().getTotalSeconds();
default -> dateTime.getLong(field);
};
}
return field.getFrom(this);
}