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

@ -596,8 +596,8 @@ public final class OffsetDateTime
*/
@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 final class OffsetDateTime
*/
@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 final class OffsetDateTime
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);
}
/**