8263668: Update java.time to use instanceof pattern variable

Reviewed-by: lancea, ryadav, naoto, rriggs, dfuchs, scolebourne, chegar
This commit is contained in:
Patrick Concannon 2021-04-22 10:17:43 +00:00
parent a93d911954
commit 28af31db34
34 changed files with 129 additions and 176 deletions

View file

@ -1066,8 +1066,8 @@ public final class LocalTime
*/
@Override
public LocalTime plus(long amountToAdd, TemporalUnit unit) {
if (unit instanceof ChronoUnit) {
switch ((ChronoUnit) unit) {
if (unit instanceof ChronoUnit chronoUnit) {
switch (chronoUnit) {
case NANOS: return plusNanos(amountToAdd);
case MICROS: return plusNanos((amountToAdd % MICROS_PER_DAY) * 1000);
case MILLIS: return plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000_000);
@ -1407,9 +1407,9 @@ public final class LocalTime
@Override
public long until(Temporal endExclusive, TemporalUnit unit) {
LocalTime end = LocalTime.from(endExclusive);
if (unit instanceof ChronoUnit) {
if (unit instanceof ChronoUnit chronoUnit) {
long nanosUntil = end.toNanoOfDay() - toNanoOfDay(); // no overflow
switch ((ChronoUnit) unit) {
switch (chronoUnit) {
case NANOS: return nanosUntil;
case MICROS: return nanosUntil / 1000;
case MILLIS: return nanosUntil / 1000_000;
@ -1583,12 +1583,11 @@ public final class LocalTime
if (this == obj) {
return true;
}
if (obj instanceof LocalTime) {
LocalTime other = (LocalTime) obj;
return hour == other.hour && minute == other.minute &&
second == other.second && nano == other.nano;
}
return false;
return (obj instanceof LocalTime other)
&& hour == other.hour
&& minute == other.minute
&& second == other.second
&& nano == other.nano;
}
/**