mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +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
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue