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

@ -1180,16 +1180,16 @@ public final class OffsetTime
OffsetTime end = OffsetTime.from(endExclusive);
if (unit instanceof ChronoUnit chronoUnit) {
long nanosUntil = end.toEpochNano() - toEpochNano(); // no overflow
switch (chronoUnit) {
case NANOS: return nanosUntil;
case MICROS: return nanosUntil / 1000;
case MILLIS: return nanosUntil / 1000_000;
case SECONDS: return nanosUntil / NANOS_PER_SECOND;
case MINUTES: return nanosUntil / NANOS_PER_MINUTE;
case HOURS: return nanosUntil / NANOS_PER_HOUR;
case HALF_DAYS: return nanosUntil / (12 * NANOS_PER_HOUR);
}
throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
return switch (chronoUnit) {
case NANOS -> nanosUntil;
case MICROS -> nanosUntil / 1000;
case MILLIS -> nanosUntil / 1000_000;
case SECONDS -> nanosUntil / NANOS_PER_SECOND;
case MINUTES -> nanosUntil / NANOS_PER_MINUTE;
case HOURS -> nanosUntil / NANOS_PER_HOUR;
case HALF_DAYS -> nanosUntil / (12 * NANOS_PER_HOUR);
default -> throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
};
}
return unit.between(this, end);
}