diff --git a/src/java.base/share/classes/java/time/Clock.java b/src/java.base/share/classes/java/time/Clock.java index 78a8ee72fff9..454e4e8e1693 100644 --- a/src/java.base/share/classes/java/time/Clock.java +++ b/src/java.base/share/classes/java/time/Clock.java @@ -730,11 +730,9 @@ public Instant instant() { } @Override public boolean equals(Object obj) { - if (obj instanceof TickClock) { - TickClock other = (TickClock) obj; - return baseClock.equals(other.baseClock) && tickNanos == other.tickNanos; - } - return false; + return (obj instanceof TickClock other) + && tickNanos == other.tickNanos + && baseClock.equals(other.baseClock); } @Override public int hashCode() { diff --git a/src/java.base/share/classes/java/time/Duration.java b/src/java.base/share/classes/java/time/Duration.java index ea3a382c69de..3eeffb2288a6 100644 --- a/src/java.base/share/classes/java/time/Duration.java +++ b/src/java.base/share/classes/java/time/Duration.java @@ -719,8 +719,8 @@ public Duration plus(long amountToAdd, TemporalUnit unit) { if (amountToAdd == 0) { return this; } - if (unit instanceof ChronoUnit) { - switch ((ChronoUnit) unit) { + if (unit instanceof ChronoUnit chronoUnit) { + switch (chronoUnit) { case NANOS: return plusNanos(amountToAdd); case MICROS: return plusSeconds((amountToAdd / (1000_000L * 1000)) * 1000).plusNanos((amountToAdd % (1000_000L * 1000)) * 1000); case MILLIS: return plusMillis(amountToAdd); @@ -1421,20 +1421,17 @@ public int compareTo(Duration otherDuration) { *

* The comparison is based on the total length of the durations. * - * @param otherDuration the other duration, null returns false + * @param other the other duration, null returns false * @return true if the other duration is equal to this one */ @Override - public boolean equals(Object otherDuration) { - if (this == otherDuration) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (otherDuration instanceof Duration) { - Duration other = (Duration) otherDuration; - return this.seconds == other.seconds && - this.nanos == other.nanos; - } - return false; + return (other instanceof Duration otherDuration) + && this.seconds == otherDuration.seconds + && this.nanos == otherDuration.nanos; } /** diff --git a/src/java.base/share/classes/java/time/Instant.java b/src/java.base/share/classes/java/time/Instant.java index b129b9c90d56..af387290a06d 100644 --- a/src/java.base/share/classes/java/time/Instant.java +++ b/src/java.base/share/classes/java/time/Instant.java @@ -1292,20 +1292,17 @@ public boolean isBefore(Instant otherInstant) { *

* The comparison is based on the time-line position of the instants. * - * @param otherInstant the other instant, null returns false + * @param other the other instant, null returns false * @return true if the other instant is equal to this one */ @Override - public boolean equals(Object otherInstant) { - if (this == otherInstant) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (otherInstant instanceof Instant) { - Instant other = (Instant) otherInstant; - return this.seconds == other.seconds && - this.nanos == other.nanos; - } - return false; + return (other instanceof Instant otherInstant) + && this.seconds == otherInstant.seconds + && this.nanos == otherInstant.nanos; } /** diff --git a/src/java.base/share/classes/java/time/LocalDate.java b/src/java.base/share/classes/java/time/LocalDate.java index 2ed2f98544c2..2b60b9c23548 100644 --- a/src/java.base/share/classes/java/time/LocalDate.java +++ b/src/java.base/share/classes/java/time/LocalDate.java @@ -1940,7 +1940,7 @@ public ZonedDateTime atStartOfDay(ZoneId zone) { // need to handle case where there is a gap from 11:30 to 00:30 // standard ZDT factory would result in 01:00 rather than 00:30 LocalDateTime ldt = atTime(LocalTime.MIDNIGHT); - if (zone instanceof ZoneOffset == false) { + if (!(zone instanceof ZoneOffset)) { ZoneRules rules = zone.getRules(); ZoneOffsetTransition trans = rules.getTransition(ldt); if (trans != null && trans.isGap()) { diff --git a/src/java.base/share/classes/java/time/LocalDateTime.java b/src/java.base/share/classes/java/time/LocalDateTime.java index 0f6022bb659f..5366a028ce34 100644 --- a/src/java.base/share/classes/java/time/LocalDateTime.java +++ b/src/java.base/share/classes/java/time/LocalDateTime.java @@ -1683,7 +1683,7 @@ public Temporal adjustInto(Temporal temporal) { @Override public long until(Temporal endExclusive, TemporalUnit unit) { LocalDateTime end = LocalDateTime.from(endExclusive); - if (unit instanceof ChronoUnit) { + if (unit instanceof ChronoUnit chronoUnit) { if (unit.isTimeBased()) { long amount = date.daysUntil(end.date); if (amount == 0) { @@ -1697,7 +1697,7 @@ public long until(Temporal endExclusive, TemporalUnit unit) { amount++; // safe timePart -= NANOS_PER_DAY; // safe } - switch ((ChronoUnit) unit) { + switch (chronoUnit) { case NANOS: amount = Math.multiplyExact(amount, NANOS_PER_DAY); break; @@ -1935,11 +1935,9 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof LocalDateTime) { - LocalDateTime other = (LocalDateTime) obj; - return date.equals(other.date) && time.equals(other.time); - } - return false; + return (obj instanceof LocalDateTime other) + && date.equals(other.date) + && time.equals(other.time); } /** diff --git a/src/java.base/share/classes/java/time/LocalTime.java b/src/java.base/share/classes/java/time/LocalTime.java index a8602b681ca6..d0d2e393d2d3 100644 --- a/src/java.base/share/classes/java/time/LocalTime.java +++ b/src/java.base/share/classes/java/time/LocalTime.java @@ -1066,8 +1066,8 @@ public LocalTime plus(TemporalAmount amountToAdd) { */ @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 Temporal adjustInto(Temporal temporal) { @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 boolean equals(Object obj) { 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; } /** diff --git a/src/java.base/share/classes/java/time/MonthDay.java b/src/java.base/share/classes/java/time/MonthDay.java index e126f2dea75c..d8155e0367ff 100644 --- a/src/java.base/share/classes/java/time/MonthDay.java +++ b/src/java.base/share/classes/java/time/MonthDay.java @@ -444,8 +444,8 @@ public int get(TemporalField field) { */ @Override public long getLong(TemporalField field) { - if (field instanceof ChronoField) { - switch ((ChronoField) field) { + if (field instanceof ChronoField chronoField) { + switch (chronoField) { // alignedDOW and alignedWOM not supported because they cannot be set in with() case DAY_OF_MONTH: return day; case MONTH_OF_YEAR: return month; @@ -720,11 +720,9 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof MonthDay) { - MonthDay other = (MonthDay) obj; - return month == other.month && day == other.day; - } - return false; + return (obj instanceof MonthDay other) + && month == other.month + && day == other.day; } /** diff --git a/src/java.base/share/classes/java/time/OffsetDateTime.java b/src/java.base/share/classes/java/time/OffsetDateTime.java index 16d47f70de26..40dde0d5006a 100644 --- a/src/java.base/share/classes/java/time/OffsetDateTime.java +++ b/src/java.base/share/classes/java/time/OffsetDateTime.java @@ -596,8 +596,8 @@ public ValueRange range(TemporalField field) { */ @Override public int get(TemporalField field) { - if (field instanceof ChronoField) { - switch ((ChronoField) 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: @@ -633,8 +633,8 @@ public int get(TemporalField field) { */ @Override public long getLong(TemporalField field) { - if (field instanceof ChronoField) { - switch ((ChronoField) field) { + if (field instanceof ChronoField chronoField) { + switch (chronoField) { case INSTANT_SECONDS: return toEpochSecond(); case OFFSET_SECONDS: return getOffset().getTotalSeconds(); } @@ -1881,11 +1881,9 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof OffsetDateTime) { - OffsetDateTime other = (OffsetDateTime) obj; - return dateTime.equals(other.dateTime) && offset.equals(other.offset); - } - return false; + return (obj instanceof OffsetDateTime other) + && dateTime.equals(other.dateTime) + && offset.equals(other.offset); } /** diff --git a/src/java.base/share/classes/java/time/OffsetTime.java b/src/java.base/share/classes/java/time/OffsetTime.java index 89ea67e4442e..f09543435978 100644 --- a/src/java.base/share/classes/java/time/OffsetTime.java +++ b/src/java.base/share/classes/java/time/OffsetTime.java @@ -1178,9 +1178,9 @@ public Temporal adjustInto(Temporal temporal) { @Override public long until(Temporal endExclusive, TemporalUnit unit) { OffsetTime end = OffsetTime.from(endExclusive); - if (unit instanceof ChronoUnit) { + if (unit instanceof ChronoUnit chronoUnit) { long nanosUntil = end.toEpochNano() - toEpochNano(); // no overflow - switch ((ChronoUnit) unit) { + switch (chronoUnit) { case NANOS: return nanosUntil; case MICROS: return nanosUntil / 1000; case MILLIS: return nanosUntil / 1000_000; @@ -1360,11 +1360,9 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof OffsetTime) { - OffsetTime other = (OffsetTime) obj; - return time.equals(other.time) && offset.equals(other.offset); - } - return false; + return (obj instanceof OffsetTime other) + && time.equals(other.time) + && offset.equals(other.offset); } /** diff --git a/src/java.base/share/classes/java/time/Period.java b/src/java.base/share/classes/java/time/Period.java index ba68c5ac9c16..40cad4cac59a 100644 --- a/src/java.base/share/classes/java/time/Period.java +++ b/src/java.base/share/classes/java/time/Period.java @@ -992,13 +992,10 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof Period) { - Period other = (Period) obj; - return years == other.years && - months == other.months && - days == other.days; - } - return false; + return (obj instanceof Period other) + && years == other.years + && months == other.months + && days == other.days; } /** diff --git a/src/java.base/share/classes/java/time/Year.java b/src/java.base/share/classes/java/time/Year.java index 88096a396054..5d32df1db814 100644 --- a/src/java.base/share/classes/java/time/Year.java +++ b/src/java.base/share/classes/java/time/Year.java @@ -496,8 +496,8 @@ public int get(TemporalField field) { */ @Override public long getLong(TemporalField field) { - if (field instanceof ChronoField) { - switch ((ChronoField) field) { + if (field instanceof ChronoField chronoField) { + switch (chronoField) { case YEAR_OF_ERA: return (year < 1 ? 1 - year : year); case YEAR: return year; case ERA: return (year < 1 ? 0 : 1); @@ -708,8 +708,8 @@ public Year plus(TemporalAmount amountToAdd) { */ @Override public Year plus(long amountToAdd, TemporalUnit unit) { - if (unit instanceof ChronoUnit) { - switch ((ChronoUnit) unit) { + if (unit instanceof ChronoUnit chronoUnit) { + switch (chronoUnit) { case YEARS: return plusYears(amountToAdd); case DECADES: return plusYears(Math.multiplyExact(amountToAdd, 10)); case CENTURIES: return plusYears(Math.multiplyExact(amountToAdd, 100)); @@ -914,9 +914,9 @@ public Temporal adjustInto(Temporal temporal) { @Override public long until(Temporal endExclusive, TemporalUnit unit) { Year end = Year.from(endExclusive); - if (unit instanceof ChronoUnit) { + if (unit instanceof ChronoUnit chronoUnit) { long yearsUntil = ((long) end.year) - year; // no overflow - switch ((ChronoUnit) unit) { + switch (chronoUnit) { case YEARS: return yearsUntil; case DECADES: return yearsUntil / 10; case CENTURIES: return yearsUntil / 100; diff --git a/src/java.base/share/classes/java/time/YearMonth.java b/src/java.base/share/classes/java/time/YearMonth.java index d4874bd90a17..38a5116b9f5a 100644 --- a/src/java.base/share/classes/java/time/YearMonth.java +++ b/src/java.base/share/classes/java/time/YearMonth.java @@ -485,8 +485,8 @@ public int get(TemporalField field) { */ @Override public long getLong(TemporalField field) { - if (field instanceof ChronoField) { - switch ((ChronoField) field) { + if (field instanceof ChronoField chronoField) { + switch (chronoField) { case MONTH_OF_YEAR: return month; case PROLEPTIC_MONTH: return getProlepticMonth(); case YEAR_OF_ERA: return (year < 1 ? 1 - year : year); @@ -805,8 +805,8 @@ public YearMonth plus(TemporalAmount amountToAdd) { */ @Override public YearMonth plus(long amountToAdd, TemporalUnit unit) { - if (unit instanceof ChronoUnit) { - switch ((ChronoUnit) unit) { + if (unit instanceof ChronoUnit chronoUnit) { + switch (chronoUnit) { case MONTHS: return plusMonths(amountToAdd); case YEARS: return plusYears(amountToAdd); case DECADES: return plusYears(Math.multiplyExact(amountToAdd, 10)); @@ -1046,9 +1046,9 @@ public Temporal adjustInto(Temporal temporal) { @Override public long until(Temporal endExclusive, TemporalUnit unit) { YearMonth end = YearMonth.from(endExclusive); - if (unit instanceof ChronoUnit) { + if (unit instanceof ChronoUnit chronoUnit) { long monthsUntil = end.getProlepticMonth() - getProlepticMonth(); // no overflow - switch ((ChronoUnit) unit) { + switch (chronoUnit) { case MONTHS: return monthsUntil; case YEARS: return monthsUntil / 12; case DECADES: return monthsUntil / 120; @@ -1168,11 +1168,9 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof YearMonth) { - YearMonth other = (YearMonth) obj; - return year == other.year && month == other.month; - } - return false; + return (obj instanceof YearMonth other) + && year == other.year + && month == other.month; } /** diff --git a/src/java.base/share/classes/java/time/ZoneId.java b/src/java.base/share/classes/java/time/ZoneId.java index cfb3e570cb74..fc9dcc4e0543 100644 --- a/src/java.base/share/classes/java/time/ZoneId.java +++ b/src/java.base/share/classes/java/time/ZoneId.java @@ -602,11 +602,8 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof ZoneId) { - ZoneId other = (ZoneId) obj; - return getId().equals(other.getId()); - } - return false; + return (obj instanceof ZoneId other) + && getId().equals(other.getId()); } /** diff --git a/src/java.base/share/classes/java/time/ZonedDateTime.java b/src/java.base/share/classes/java/time/ZonedDateTime.java index e6bc1d256f02..586848569c76 100644 --- a/src/java.base/share/classes/java/time/ZonedDateTime.java +++ b/src/java.base/share/classes/java/time/ZonedDateTime.java @@ -813,8 +813,8 @@ public ValueRange range(TemporalField field) { */ @Override // override for Javadoc and performance public int get(TemporalField field) { - if (field instanceof ChronoField) { - switch ((ChronoField) 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: @@ -850,8 +850,8 @@ public int get(TemporalField field) { */ @Override public long getLong(TemporalField field) { - if (field instanceof ChronoField) { - switch ((ChronoField) field) { + if (field instanceof ChronoField chronoField) { + switch (chronoField) { case INSTANT_SECONDS: return toEpochSecond(); case OFFSET_SECONDS: return getOffset().getTotalSeconds(); } diff --git a/src/java.base/share/classes/java/time/chrono/ChronoLocalDateImpl.java b/src/java.base/share/classes/java/time/chrono/ChronoLocalDateImpl.java index e1755218ea65..38874eb8ea27 100644 --- a/src/java.base/share/classes/java/time/chrono/ChronoLocalDateImpl.java +++ b/src/java.base/share/classes/java/time/chrono/ChronoLocalDateImpl.java @@ -377,8 +377,8 @@ D minusDays(long daysToSubtract) { public long until(Temporal endExclusive, TemporalUnit unit) { Objects.requireNonNull(endExclusive, "endExclusive"); ChronoLocalDate end = getChronology().date(endExclusive); - if (unit instanceof ChronoUnit) { - switch ((ChronoUnit) unit) { + if (unit instanceof ChronoUnit chronoUnit) { + switch (chronoUnit) { case DAYS: return daysUntil(end); case WEEKS: return daysUntil(end) / 7; case MONTHS: return monthsUntil(end); diff --git a/src/java.base/share/classes/java/time/chrono/ChronoLocalDateTimeImpl.java b/src/java.base/share/classes/java/time/chrono/ChronoLocalDateTimeImpl.java index 4a53cd3daddd..66f964b4e78b 100644 --- a/src/java.base/share/classes/java/time/chrono/ChronoLocalDateTimeImpl.java +++ b/src/java.base/share/classes/java/time/chrono/ChronoLocalDateTimeImpl.java @@ -373,10 +373,10 @@ public long until(Temporal endExclusive, TemporalUnit unit) { Objects.requireNonNull(endExclusive, "endExclusive"); @SuppressWarnings("unchecked") ChronoLocalDateTime end = (ChronoLocalDateTime) getChronology().localDateTime(endExclusive); - if (unit instanceof ChronoUnit) { + if (unit instanceof ChronoUnit chronoUnit) { if (unit.isTimeBased()) { long amount = end.getLong(EPOCH_DAY) - date.getLong(EPOCH_DAY); - switch ((ChronoUnit) unit) { + switch (chronoUnit) { case NANOS: amount = Math.multiplyExact(amount, NANOS_PER_DAY); break; case MICROS: amount = Math.multiplyExact(amount, MICROS_PER_DAY); break; case MILLIS: amount = Math.multiplyExact(amount, MILLIS_PER_DAY); break; diff --git a/src/java.base/share/classes/java/time/chrono/ChronoPeriodImpl.java b/src/java.base/share/classes/java/time/chrono/ChronoPeriodImpl.java index 9503035525d6..d329e3203775 100644 --- a/src/java.base/share/classes/java/time/chrono/ChronoPeriodImpl.java +++ b/src/java.base/share/classes/java/time/chrono/ChronoPeriodImpl.java @@ -199,11 +199,11 @@ public ChronoPeriod minus(TemporalAmount amountToSubtract) { */ private ChronoPeriodImpl validateAmount(TemporalAmount amount) { Objects.requireNonNull(amount, "amount"); - if (amount instanceof ChronoPeriodImpl == false) { + if (!(amount instanceof ChronoPeriodImpl)) { throw new DateTimeException("Unable to obtain ChronoPeriod from TemporalAmount: " + amount.getClass()); } ChronoPeriodImpl period = (ChronoPeriodImpl) amount; - if (chrono.equals(period.getChronology()) == false) { + if (!(chrono.equals(period.getChronology()))) { throw new ClassCastException("Chronology mismatch, expected: " + chrono.getId() + ", actual: " + period.getChronology().getId()); } return period; @@ -320,12 +320,9 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof ChronoPeriodImpl) { - ChronoPeriodImpl other = (ChronoPeriodImpl) obj; - return years == other.years && months == other.months && - days == other.days && chrono.equals(other.chrono); - } - return false; + return (obj instanceof ChronoPeriodImpl other) + && years == other.years && months == other.months + && days == other.days && chrono.equals(other.chrono); } @Override diff --git a/src/java.base/share/classes/java/time/chrono/ChronoZonedDateTime.java b/src/java.base/share/classes/java/time/chrono/ChronoZonedDateTime.java index cc96504971ca..aeaa3242de9f 100644 --- a/src/java.base/share/classes/java/time/chrono/ChronoZonedDateTime.java +++ b/src/java.base/share/classes/java/time/chrono/ChronoZonedDateTime.java @@ -195,8 +195,8 @@ default ValueRange range(TemporalField field) { @Override default int get(TemporalField field) { - if (field instanceof ChronoField) { - switch ((ChronoField) 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: @@ -209,8 +209,8 @@ default int get(TemporalField field) { @Override default long getLong(TemporalField field) { - if (field instanceof ChronoField) { - switch ((ChronoField) field) { + if (field instanceof ChronoField chronoField) { + switch (chronoField) { case INSTANT_SECONDS: return toEpochSecond(); case OFFSET_SECONDS: return getOffset().getTotalSeconds(); } diff --git a/src/java.base/share/classes/java/time/chrono/HijrahChronology.java b/src/java.base/share/classes/java/time/chrono/HijrahChronology.java index bdb935924556..75720247d9bb 100644 --- a/src/java.base/share/classes/java/time/chrono/HijrahChronology.java +++ b/src/java.base/share/classes/java/time/chrono/HijrahChronology.java @@ -498,7 +498,7 @@ public boolean isLeapYear(long prolepticYear) { @Override public int prolepticYear(Era era, int yearOfEra) { - if (era instanceof HijrahEra == false) { + if (!(era instanceof HijrahEra)) { throw new ClassCastException("Era must be HijrahEra"); } return yearOfEra; diff --git a/src/java.base/share/classes/java/time/chrono/HijrahDate.java b/src/java.base/share/classes/java/time/chrono/HijrahDate.java index 9f0b6d7a5733..46f28e1f0023 100644 --- a/src/java.base/share/classes/java/time/chrono/HijrahDate.java +++ b/src/java.base/share/classes/java/time/chrono/HijrahDate.java @@ -628,14 +628,11 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof HijrahDate) { - HijrahDate otherDate = (HijrahDate) obj; - return prolepticYear == otherDate.prolepticYear + return (obj instanceof HijrahDate otherDate) + && prolepticYear == otherDate.prolepticYear && this.monthOfYear == otherDate.monthOfYear && this.dayOfMonth == otherDate.dayOfMonth && getChronology().equals(otherDate.getChronology()); - } - return false; } /** diff --git a/src/java.base/share/classes/java/time/chrono/IsoChronology.java b/src/java.base/share/classes/java/time/chrono/IsoChronology.java index 369a3da9aa5f..4051018bb624 100644 --- a/src/java.base/share/classes/java/time/chrono/IsoChronology.java +++ b/src/java.base/share/classes/java/time/chrono/IsoChronology.java @@ -479,7 +479,7 @@ public boolean isLeapYear(long prolepticYear) { @Override public int prolepticYear(Era era, int yearOfEra) { - if (era instanceof IsoEra == false) { + if (!(era instanceof IsoEra)) { throw new ClassCastException("Era must be IsoEra"); } return (era == IsoEra.CE ? yearOfEra : 1 - yearOfEra); diff --git a/src/java.base/share/classes/java/time/chrono/JapaneseChronology.java b/src/java.base/share/classes/java/time/chrono/JapaneseChronology.java index 548a56c10285..878eb99d46a1 100644 --- a/src/java.base/share/classes/java/time/chrono/JapaneseChronology.java +++ b/src/java.base/share/classes/java/time/chrono/JapaneseChronology.java @@ -202,10 +202,10 @@ public String getCalendarType() { */ @Override public JapaneseDate date(Era era, int yearOfEra, int month, int dayOfMonth) { - if (era instanceof JapaneseEra == false) { + if (!(era instanceof JapaneseEra jera)) { throw new ClassCastException("Era must be JapaneseEra"); } - return JapaneseDate.of((JapaneseEra) era, yearOfEra, month, dayOfMonth); + return JapaneseDate.of(jera, yearOfEra, month, dayOfMonth); } /** diff --git a/src/java.base/share/classes/java/time/chrono/JapaneseDate.java b/src/java.base/share/classes/java/time/chrono/JapaneseDate.java index 8fd05d93aa99..ee2d1738c942 100644 --- a/src/java.base/share/classes/java/time/chrono/JapaneseDate.java +++ b/src/java.base/share/classes/java/time/chrono/JapaneseDate.java @@ -697,11 +697,8 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof JapaneseDate) { - JapaneseDate otherDate = (JapaneseDate) obj; - return this.isoDate.equals(otherDate.isoDate); - } - return false; + return (obj instanceof JapaneseDate otherDate) + && this.isoDate.equals(otherDate.isoDate); } /** diff --git a/src/java.base/share/classes/java/time/chrono/MinguoChronology.java b/src/java.base/share/classes/java/time/chrono/MinguoChronology.java index 896fe5c96977..7f65313ac16f 100644 --- a/src/java.base/share/classes/java/time/chrono/MinguoChronology.java +++ b/src/java.base/share/classes/java/time/chrono/MinguoChronology.java @@ -293,7 +293,7 @@ public boolean isLeapYear(long prolepticYear) { @Override public int prolepticYear(Era era, int yearOfEra) { - if (era instanceof MinguoEra == false) { + if (!(era instanceof MinguoEra)) { throw new ClassCastException("Era must be MinguoEra"); } return (era == MinguoEra.ROC ? yearOfEra : 1 - yearOfEra); diff --git a/src/java.base/share/classes/java/time/chrono/MinguoDate.java b/src/java.base/share/classes/java/time/chrono/MinguoDate.java index 6f3170177a5b..62e6eeaad835 100644 --- a/src/java.base/share/classes/java/time/chrono/MinguoDate.java +++ b/src/java.base/share/classes/java/time/chrono/MinguoDate.java @@ -459,11 +459,8 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof MinguoDate) { - MinguoDate otherDate = (MinguoDate) obj; - return this.isoDate.equals(otherDate.isoDate); - } - return false; + return (obj instanceof MinguoDate otherDate) + && this.isoDate.equals(otherDate.isoDate); } /** diff --git a/src/java.base/share/classes/java/time/chrono/ThaiBuddhistChronology.java b/src/java.base/share/classes/java/time/chrono/ThaiBuddhistChronology.java index 28e3282c4ea8..244ff4e6ceb6 100644 --- a/src/java.base/share/classes/java/time/chrono/ThaiBuddhistChronology.java +++ b/src/java.base/share/classes/java/time/chrono/ThaiBuddhistChronology.java @@ -329,7 +329,7 @@ public boolean isLeapYear(long prolepticYear) { @Override public int prolepticYear(Era era, int yearOfEra) { - if (era instanceof ThaiBuddhistEra == false) { + if (!(era instanceof ThaiBuddhistEra)) { throw new ClassCastException("Era must be BuddhistEra"); } return (era == ThaiBuddhistEra.BE ? yearOfEra : 1 - yearOfEra); diff --git a/src/java.base/share/classes/java/time/chrono/ThaiBuddhistDate.java b/src/java.base/share/classes/java/time/chrono/ThaiBuddhistDate.java index 865d2731abf1..3ada1fa09019 100644 --- a/src/java.base/share/classes/java/time/chrono/ThaiBuddhistDate.java +++ b/src/java.base/share/classes/java/time/chrono/ThaiBuddhistDate.java @@ -459,11 +459,8 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj instanceof ThaiBuddhistDate) { - ThaiBuddhistDate otherDate = (ThaiBuddhistDate) obj; - return this.isoDate.equals(otherDate.isoDate); - } - return false; + return (obj instanceof ThaiBuddhistDate otherDate) + && this.isoDate.equals(otherDate.isoDate); } /** diff --git a/src/java.base/share/classes/java/time/format/DateTimeFormatter.java b/src/java.base/share/classes/java/time/format/DateTimeFormatter.java index 0e4f8d36aff1..c94b123b26c9 100644 --- a/src/java.base/share/classes/java/time/format/DateTimeFormatter.java +++ b/src/java.base/share/classes/java/time/format/DateTimeFormatter.java @@ -2208,7 +2208,7 @@ public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition po Objects.requireNonNull(obj, "obj"); Objects.requireNonNull(toAppendTo, "toAppendTo"); Objects.requireNonNull(pos, "pos"); - if (obj instanceof TemporalAccessor == false) { + if (!(obj instanceof TemporalAccessor)) { throw new IllegalArgumentException("Format target must implement TemporalAccessor"); } pos.setBeginIndex(0); diff --git a/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java b/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java index 2fd1260c2d8e..3a0d75956163 100644 --- a/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java +++ b/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java @@ -165,7 +165,7 @@ public final class DateTimeFormatterBuilder { */ private static final TemporalQuery QUERY_REGION_ONLY = (temporal) -> { ZoneId zone = temporal.query(TemporalQueries.zoneId()); - return (zone != null && zone instanceof ZoneOffset == false ? zone : null); + return zone instanceof ZoneOffset ? null : zone; }; /** diff --git a/src/java.base/share/classes/java/time/format/Parsed.java b/src/java.base/share/classes/java/time/format/Parsed.java index 60ad53969533..c6065a04c11e 100644 --- a/src/java.base/share/classes/java/time/format/Parsed.java +++ b/src/java.base/share/classes/java/time/format/Parsed.java @@ -189,7 +189,7 @@ public boolean isSupported(TemporalField field) { (time != null && time.isSupported(field))) { return true; } - return field != null && (field instanceof ChronoField == false) && field.isSupportedBy(this); + return field != null && (!(field instanceof ChronoField)) && field.isSupportedBy(this); } @Override diff --git a/src/java.base/share/classes/java/time/temporal/ValueRange.java b/src/java.base/share/classes/java/time/temporal/ValueRange.java index 4e4cab7c8e60..b17f56ccd4d5 100644 --- a/src/java.base/share/classes/java/time/temporal/ValueRange.java +++ b/src/java.base/share/classes/java/time/temporal/ValueRange.java @@ -393,12 +393,11 @@ public boolean equals(Object obj) { if (obj == this) { return true; } - if (obj instanceof ValueRange) { - ValueRange other = (ValueRange) obj; - return minSmallest == other.minSmallest && minLargest == other.minLargest && - maxSmallest == other.maxSmallest && maxLargest == other.maxLargest; - } - return false; + return (obj instanceof ValueRange other) + && minSmallest == other.minSmallest + && minLargest == other.minLargest + && maxSmallest == other.maxSmallest + && maxLargest == other.maxLargest; } /** diff --git a/src/java.base/share/classes/java/time/zone/ZoneOffsetTransition.java b/src/java.base/share/classes/java/time/zone/ZoneOffsetTransition.java index 6d108e277a05..3119458ec8d9 100644 --- a/src/java.base/share/classes/java/time/zone/ZoneOffsetTransition.java +++ b/src/java.base/share/classes/java/time/zone/ZoneOffsetTransition.java @@ -421,12 +421,10 @@ public boolean equals(Object other) { if (other == this) { return true; } - if (other instanceof ZoneOffsetTransition) { - ZoneOffsetTransition d = (ZoneOffsetTransition) other; - return epochSecond == d.epochSecond && - offsetBefore.equals(d.offsetBefore) && offsetAfter.equals(d.offsetAfter); - } - return false; + return (other instanceof ZoneOffsetTransition d) + && epochSecond == d.epochSecond + && offsetBefore.equals(d.offsetBefore) + && offsetAfter.equals(d.offsetAfter); } /** diff --git a/src/java.base/share/classes/java/time/zone/ZoneOffsetTransitionRule.java b/src/java.base/share/classes/java/time/zone/ZoneOffsetTransitionRule.java index 9b622feaa06a..8eb232075fe3 100644 --- a/src/java.base/share/classes/java/time/zone/ZoneOffsetTransitionRule.java +++ b/src/java.base/share/classes/java/time/zone/ZoneOffsetTransitionRule.java @@ -519,17 +519,16 @@ public boolean equals(Object otherRule) { if (otherRule == this) { return true; } - if (otherRule instanceof ZoneOffsetTransitionRule) { - ZoneOffsetTransitionRule other = (ZoneOffsetTransitionRule) otherRule; - return month == other.month && dom == other.dom && dow == other.dow && - timeDefinition == other.timeDefinition && - time.equals(other.time) && - timeEndOfDay == other.timeEndOfDay && - standardOffset.equals(other.standardOffset) && - offsetBefore.equals(other.offsetBefore) && - offsetAfter.equals(other.offsetAfter); - } - return false; + return (otherRule instanceof ZoneOffsetTransitionRule other) + && month == other.month + && dom == other.dom + && dow == other.dow + && timeDefinition == other.timeDefinition + && timeEndOfDay == other.timeEndOfDay + && time.equals(other.time) + && standardOffset.equals(other.standardOffset) + && offsetBefore.equals(other.offsetBefore) + && offsetAfter.equals(other.offsetAfter); } /** diff --git a/src/java.base/share/classes/java/time/zone/ZoneRules.java b/src/java.base/share/classes/java/time/zone/ZoneRules.java index 6ed9452ec09f..bd22b154d9eb 100644 --- a/src/java.base/share/classes/java/time/zone/ZoneRules.java +++ b/src/java.base/share/classes/java/time/zone/ZoneRules.java @@ -1027,15 +1027,12 @@ public boolean equals(Object otherRules) { if (this == otherRules) { return true; } - if (otherRules instanceof ZoneRules) { - ZoneRules other = (ZoneRules) otherRules; - return Arrays.equals(standardTransitions, other.standardTransitions) && - Arrays.equals(standardOffsets, other.standardOffsets) && - Arrays.equals(savingsInstantTransitions, other.savingsInstantTransitions) && - Arrays.equals(wallOffsets, other.wallOffsets) && - Arrays.equals(lastRules, other.lastRules); - } - return false; + return (otherRules instanceof ZoneRules other) + && Arrays.equals(standardTransitions, other.standardTransitions) + && Arrays.equals(standardOffsets, other.standardOffsets) + && Arrays.equals(savingsInstantTransitions, other.savingsInstantTransitions) + && Arrays.equals(wallOffsets, other.wallOffsets) + && Arrays.equals(lastRules, other.lastRules); } /**