8263668: Update java.time to use instanceof pattern variable
Reviewed-by: lancea, ryadav, naoto, rriggs, dfuchs, scolebourne, chegar
This commit is contained in:
parent
a93d911954
commit
28af31db34
@ -730,11 +730,9 @@ public abstract class Clock {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj instanceof TickClock) {
|
return (obj instanceof TickClock other)
|
||||||
TickClock other = (TickClock) obj;
|
&& tickNanos == other.tickNanos
|
||||||
return baseClock.equals(other.baseClock) && tickNanos == other.tickNanos;
|
&& baseClock.equals(other.baseClock);
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
|
@ -719,8 +719,8 @@ public final class Duration
|
|||||||
if (amountToAdd == 0) {
|
if (amountToAdd == 0) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
if (unit instanceof ChronoUnit) {
|
if (unit instanceof ChronoUnit chronoUnit) {
|
||||||
switch ((ChronoUnit) unit) {
|
switch (chronoUnit) {
|
||||||
case NANOS: return plusNanos(amountToAdd);
|
case NANOS: return plusNanos(amountToAdd);
|
||||||
case MICROS: return plusSeconds((amountToAdd / (1000_000L * 1000)) * 1000).plusNanos((amountToAdd % (1000_000L * 1000)) * 1000);
|
case MICROS: return plusSeconds((amountToAdd / (1000_000L * 1000)) * 1000).plusNanos((amountToAdd % (1000_000L * 1000)) * 1000);
|
||||||
case MILLIS: return plusMillis(amountToAdd);
|
case MILLIS: return plusMillis(amountToAdd);
|
||||||
@ -1421,20 +1421,17 @@ public final class Duration
|
|||||||
* <p>
|
* <p>
|
||||||
* The comparison is based on the total length of the durations.
|
* 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
|
* @return true if the other duration is equal to this one
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object otherDuration) {
|
public boolean equals(Object other) {
|
||||||
if (this == otherDuration) {
|
if (this == other) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (otherDuration instanceof Duration) {
|
return (other instanceof Duration otherDuration)
|
||||||
Duration other = (Duration) otherDuration;
|
&& this.seconds == otherDuration.seconds
|
||||||
return this.seconds == other.seconds &&
|
&& this.nanos == otherDuration.nanos;
|
||||||
this.nanos == other.nanos;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1292,20 +1292,17 @@ public final class Instant
|
|||||||
* <p>
|
* <p>
|
||||||
* The comparison is based on the time-line position of the instants.
|
* 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
|
* @return true if the other instant is equal to this one
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object otherInstant) {
|
public boolean equals(Object other) {
|
||||||
if (this == otherInstant) {
|
if (this == other) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (otherInstant instanceof Instant) {
|
return (other instanceof Instant otherInstant)
|
||||||
Instant other = (Instant) otherInstant;
|
&& this.seconds == otherInstant.seconds
|
||||||
return this.seconds == other.seconds &&
|
&& this.nanos == otherInstant.nanos;
|
||||||
this.nanos == other.nanos;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1940,7 +1940,7 @@ public final class LocalDate
|
|||||||
// need to handle case where there is a gap from 11:30 to 00:30
|
// 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
|
// standard ZDT factory would result in 01:00 rather than 00:30
|
||||||
LocalDateTime ldt = atTime(LocalTime.MIDNIGHT);
|
LocalDateTime ldt = atTime(LocalTime.MIDNIGHT);
|
||||||
if (zone instanceof ZoneOffset == false) {
|
if (!(zone instanceof ZoneOffset)) {
|
||||||
ZoneRules rules = zone.getRules();
|
ZoneRules rules = zone.getRules();
|
||||||
ZoneOffsetTransition trans = rules.getTransition(ldt);
|
ZoneOffsetTransition trans = rules.getTransition(ldt);
|
||||||
if (trans != null && trans.isGap()) {
|
if (trans != null && trans.isGap()) {
|
||||||
|
@ -1683,7 +1683,7 @@ public final class LocalDateTime
|
|||||||
@Override
|
@Override
|
||||||
public long until(Temporal endExclusive, TemporalUnit unit) {
|
public long until(Temporal endExclusive, TemporalUnit unit) {
|
||||||
LocalDateTime end = LocalDateTime.from(endExclusive);
|
LocalDateTime end = LocalDateTime.from(endExclusive);
|
||||||
if (unit instanceof ChronoUnit) {
|
if (unit instanceof ChronoUnit chronoUnit) {
|
||||||
if (unit.isTimeBased()) {
|
if (unit.isTimeBased()) {
|
||||||
long amount = date.daysUntil(end.date);
|
long amount = date.daysUntil(end.date);
|
||||||
if (amount == 0) {
|
if (amount == 0) {
|
||||||
@ -1697,7 +1697,7 @@ public final class LocalDateTime
|
|||||||
amount++; // safe
|
amount++; // safe
|
||||||
timePart -= NANOS_PER_DAY; // safe
|
timePart -= NANOS_PER_DAY; // safe
|
||||||
}
|
}
|
||||||
switch ((ChronoUnit) unit) {
|
switch (chronoUnit) {
|
||||||
case NANOS:
|
case NANOS:
|
||||||
amount = Math.multiplyExact(amount, NANOS_PER_DAY);
|
amount = Math.multiplyExact(amount, NANOS_PER_DAY);
|
||||||
break;
|
break;
|
||||||
@ -1935,11 +1935,9 @@ public final class LocalDateTime
|
|||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj instanceof LocalDateTime) {
|
return (obj instanceof LocalDateTime other)
|
||||||
LocalDateTime other = (LocalDateTime) obj;
|
&& date.equals(other.date)
|
||||||
return date.equals(other.date) && time.equals(other.time);
|
&& time.equals(other.time);
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1066,8 +1066,8 @@ public final class LocalTime
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public LocalTime plus(long amountToAdd, TemporalUnit unit) {
|
public LocalTime plus(long amountToAdd, TemporalUnit unit) {
|
||||||
if (unit instanceof ChronoUnit) {
|
if (unit instanceof ChronoUnit chronoUnit) {
|
||||||
switch ((ChronoUnit) unit) {
|
switch (chronoUnit) {
|
||||||
case NANOS: return plusNanos(amountToAdd);
|
case NANOS: return plusNanos(amountToAdd);
|
||||||
case MICROS: return plusNanos((amountToAdd % MICROS_PER_DAY) * 1000);
|
case MICROS: return plusNanos((amountToAdd % MICROS_PER_DAY) * 1000);
|
||||||
case MILLIS: return plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000_000);
|
case MILLIS: return plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000_000);
|
||||||
@ -1407,9 +1407,9 @@ public final class LocalTime
|
|||||||
@Override
|
@Override
|
||||||
public long until(Temporal endExclusive, TemporalUnit unit) {
|
public long until(Temporal endExclusive, TemporalUnit unit) {
|
||||||
LocalTime end = LocalTime.from(endExclusive);
|
LocalTime end = LocalTime.from(endExclusive);
|
||||||
if (unit instanceof ChronoUnit) {
|
if (unit instanceof ChronoUnit chronoUnit) {
|
||||||
long nanosUntil = end.toNanoOfDay() - toNanoOfDay(); // no overflow
|
long nanosUntil = end.toNanoOfDay() - toNanoOfDay(); // no overflow
|
||||||
switch ((ChronoUnit) unit) {
|
switch (chronoUnit) {
|
||||||
case NANOS: return nanosUntil;
|
case NANOS: return nanosUntil;
|
||||||
case MICROS: return nanosUntil / 1000;
|
case MICROS: return nanosUntil / 1000;
|
||||||
case MILLIS: return nanosUntil / 1000_000;
|
case MILLIS: return nanosUntil / 1000_000;
|
||||||
@ -1583,12 +1583,11 @@ public final class LocalTime
|
|||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj instanceof LocalTime) {
|
return (obj instanceof LocalTime other)
|
||||||
LocalTime other = (LocalTime) obj;
|
&& hour == other.hour
|
||||||
return hour == other.hour && minute == other.minute &&
|
&& minute == other.minute
|
||||||
second == other.second && nano == other.nano;
|
&& second == other.second
|
||||||
}
|
&& nano == other.nano;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -444,8 +444,8 @@ public final class MonthDay
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long getLong(TemporalField field) {
|
public long getLong(TemporalField field) {
|
||||||
if (field instanceof ChronoField) {
|
if (field instanceof ChronoField chronoField) {
|
||||||
switch ((ChronoField) field) {
|
switch (chronoField) {
|
||||||
// alignedDOW and alignedWOM not supported because they cannot be set in with()
|
// alignedDOW and alignedWOM not supported because they cannot be set in with()
|
||||||
case DAY_OF_MONTH: return day;
|
case DAY_OF_MONTH: return day;
|
||||||
case MONTH_OF_YEAR: return month;
|
case MONTH_OF_YEAR: return month;
|
||||||
@ -720,11 +720,9 @@ public final class MonthDay
|
|||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj instanceof MonthDay) {
|
return (obj instanceof MonthDay other)
|
||||||
MonthDay other = (MonthDay) obj;
|
&& month == other.month
|
||||||
return month == other.month && day == other.day;
|
&& day == other.day;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -596,8 +596,8 @@ public final class OffsetDateTime
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int get(TemporalField field) {
|
public int get(TemporalField field) {
|
||||||
if (field instanceof ChronoField) {
|
if (field instanceof ChronoField chronoField) {
|
||||||
switch ((ChronoField) field) {
|
switch (chronoField) {
|
||||||
case INSTANT_SECONDS:
|
case INSTANT_SECONDS:
|
||||||
throw new UnsupportedTemporalTypeException("Invalid field 'InstantSeconds' for get() method, use getLong() instead");
|
throw new UnsupportedTemporalTypeException("Invalid field 'InstantSeconds' for get() method, use getLong() instead");
|
||||||
case OFFSET_SECONDS:
|
case OFFSET_SECONDS:
|
||||||
@ -633,8 +633,8 @@ public final class OffsetDateTime
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long getLong(TemporalField field) {
|
public long getLong(TemporalField field) {
|
||||||
if (field instanceof ChronoField) {
|
if (field instanceof ChronoField chronoField) {
|
||||||
switch ((ChronoField) field) {
|
switch (chronoField) {
|
||||||
case INSTANT_SECONDS: return toEpochSecond();
|
case INSTANT_SECONDS: return toEpochSecond();
|
||||||
case OFFSET_SECONDS: return getOffset().getTotalSeconds();
|
case OFFSET_SECONDS: return getOffset().getTotalSeconds();
|
||||||
}
|
}
|
||||||
@ -1881,11 +1881,9 @@ public final class OffsetDateTime
|
|||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj instanceof OffsetDateTime) {
|
return (obj instanceof OffsetDateTime other)
|
||||||
OffsetDateTime other = (OffsetDateTime) obj;
|
&& dateTime.equals(other.dateTime)
|
||||||
return dateTime.equals(other.dateTime) && offset.equals(other.offset);
|
&& offset.equals(other.offset);
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1178,9 +1178,9 @@ public final class OffsetTime
|
|||||||
@Override
|
@Override
|
||||||
public long until(Temporal endExclusive, TemporalUnit unit) {
|
public long until(Temporal endExclusive, TemporalUnit unit) {
|
||||||
OffsetTime end = OffsetTime.from(endExclusive);
|
OffsetTime end = OffsetTime.from(endExclusive);
|
||||||
if (unit instanceof ChronoUnit) {
|
if (unit instanceof ChronoUnit chronoUnit) {
|
||||||
long nanosUntil = end.toEpochNano() - toEpochNano(); // no overflow
|
long nanosUntil = end.toEpochNano() - toEpochNano(); // no overflow
|
||||||
switch ((ChronoUnit) unit) {
|
switch (chronoUnit) {
|
||||||
case NANOS: return nanosUntil;
|
case NANOS: return nanosUntil;
|
||||||
case MICROS: return nanosUntil / 1000;
|
case MICROS: return nanosUntil / 1000;
|
||||||
case MILLIS: return nanosUntil / 1000_000;
|
case MILLIS: return nanosUntil / 1000_000;
|
||||||
@ -1360,11 +1360,9 @@ public final class OffsetTime
|
|||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj instanceof OffsetTime) {
|
return (obj instanceof OffsetTime other)
|
||||||
OffsetTime other = (OffsetTime) obj;
|
&& time.equals(other.time)
|
||||||
return time.equals(other.time) && offset.equals(other.offset);
|
&& offset.equals(other.offset);
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -992,13 +992,10 @@ public final class Period
|
|||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj instanceof Period) {
|
return (obj instanceof Period other)
|
||||||
Period other = (Period) obj;
|
&& years == other.years
|
||||||
return years == other.years &&
|
&& months == other.months
|
||||||
months == other.months &&
|
&& days == other.days;
|
||||||
days == other.days;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -496,8 +496,8 @@ public final class Year
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long getLong(TemporalField field) {
|
public long getLong(TemporalField field) {
|
||||||
if (field instanceof ChronoField) {
|
if (field instanceof ChronoField chronoField) {
|
||||||
switch ((ChronoField) field) {
|
switch (chronoField) {
|
||||||
case YEAR_OF_ERA: return (year < 1 ? 1 - year : year);
|
case YEAR_OF_ERA: return (year < 1 ? 1 - year : year);
|
||||||
case YEAR: return year;
|
case YEAR: return year;
|
||||||
case ERA: return (year < 1 ? 0 : 1);
|
case ERA: return (year < 1 ? 0 : 1);
|
||||||
@ -708,8 +708,8 @@ public final class Year
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Year plus(long amountToAdd, TemporalUnit unit) {
|
public Year plus(long amountToAdd, TemporalUnit unit) {
|
||||||
if (unit instanceof ChronoUnit) {
|
if (unit instanceof ChronoUnit chronoUnit) {
|
||||||
switch ((ChronoUnit) unit) {
|
switch (chronoUnit) {
|
||||||
case YEARS: return plusYears(amountToAdd);
|
case YEARS: return plusYears(amountToAdd);
|
||||||
case DECADES: return plusYears(Math.multiplyExact(amountToAdd, 10));
|
case DECADES: return plusYears(Math.multiplyExact(amountToAdd, 10));
|
||||||
case CENTURIES: return plusYears(Math.multiplyExact(amountToAdd, 100));
|
case CENTURIES: return plusYears(Math.multiplyExact(amountToAdd, 100));
|
||||||
@ -914,9 +914,9 @@ public final class Year
|
|||||||
@Override
|
@Override
|
||||||
public long until(Temporal endExclusive, TemporalUnit unit) {
|
public long until(Temporal endExclusive, TemporalUnit unit) {
|
||||||
Year end = Year.from(endExclusive);
|
Year end = Year.from(endExclusive);
|
||||||
if (unit instanceof ChronoUnit) {
|
if (unit instanceof ChronoUnit chronoUnit) {
|
||||||
long yearsUntil = ((long) end.year) - year; // no overflow
|
long yearsUntil = ((long) end.year) - year; // no overflow
|
||||||
switch ((ChronoUnit) unit) {
|
switch (chronoUnit) {
|
||||||
case YEARS: return yearsUntil;
|
case YEARS: return yearsUntil;
|
||||||
case DECADES: return yearsUntil / 10;
|
case DECADES: return yearsUntil / 10;
|
||||||
case CENTURIES: return yearsUntil / 100;
|
case CENTURIES: return yearsUntil / 100;
|
||||||
|
@ -485,8 +485,8 @@ public final class YearMonth
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long getLong(TemporalField field) {
|
public long getLong(TemporalField field) {
|
||||||
if (field instanceof ChronoField) {
|
if (field instanceof ChronoField chronoField) {
|
||||||
switch ((ChronoField) field) {
|
switch (chronoField) {
|
||||||
case MONTH_OF_YEAR: return month;
|
case MONTH_OF_YEAR: return month;
|
||||||
case PROLEPTIC_MONTH: return getProlepticMonth();
|
case PROLEPTIC_MONTH: return getProlepticMonth();
|
||||||
case YEAR_OF_ERA: return (year < 1 ? 1 - year : year);
|
case YEAR_OF_ERA: return (year < 1 ? 1 - year : year);
|
||||||
@ -805,8 +805,8 @@ public final class YearMonth
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public YearMonth plus(long amountToAdd, TemporalUnit unit) {
|
public YearMonth plus(long amountToAdd, TemporalUnit unit) {
|
||||||
if (unit instanceof ChronoUnit) {
|
if (unit instanceof ChronoUnit chronoUnit) {
|
||||||
switch ((ChronoUnit) unit) {
|
switch (chronoUnit) {
|
||||||
case MONTHS: return plusMonths(amountToAdd);
|
case MONTHS: return plusMonths(amountToAdd);
|
||||||
case YEARS: return plusYears(amountToAdd);
|
case YEARS: return plusYears(amountToAdd);
|
||||||
case DECADES: return plusYears(Math.multiplyExact(amountToAdd, 10));
|
case DECADES: return plusYears(Math.multiplyExact(amountToAdd, 10));
|
||||||
@ -1046,9 +1046,9 @@ public final class YearMonth
|
|||||||
@Override
|
@Override
|
||||||
public long until(Temporal endExclusive, TemporalUnit unit) {
|
public long until(Temporal endExclusive, TemporalUnit unit) {
|
||||||
YearMonth end = YearMonth.from(endExclusive);
|
YearMonth end = YearMonth.from(endExclusive);
|
||||||
if (unit instanceof ChronoUnit) {
|
if (unit instanceof ChronoUnit chronoUnit) {
|
||||||
long monthsUntil = end.getProlepticMonth() - getProlepticMonth(); // no overflow
|
long monthsUntil = end.getProlepticMonth() - getProlepticMonth(); // no overflow
|
||||||
switch ((ChronoUnit) unit) {
|
switch (chronoUnit) {
|
||||||
case MONTHS: return monthsUntil;
|
case MONTHS: return monthsUntil;
|
||||||
case YEARS: return monthsUntil / 12;
|
case YEARS: return monthsUntil / 12;
|
||||||
case DECADES: return monthsUntil / 120;
|
case DECADES: return monthsUntil / 120;
|
||||||
@ -1168,11 +1168,9 @@ public final class YearMonth
|
|||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj instanceof YearMonth) {
|
return (obj instanceof YearMonth other)
|
||||||
YearMonth other = (YearMonth) obj;
|
&& year == other.year
|
||||||
return year == other.year && month == other.month;
|
&& month == other.month;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -602,11 +602,8 @@ public abstract class ZoneId implements Serializable {
|
|||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj instanceof ZoneId) {
|
return (obj instanceof ZoneId other)
|
||||||
ZoneId other = (ZoneId) obj;
|
&& getId().equals(other.getId());
|
||||||
return getId().equals(other.getId());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -813,8 +813,8 @@ public final class ZonedDateTime
|
|||||||
*/
|
*/
|
||||||
@Override // override for Javadoc and performance
|
@Override // override for Javadoc and performance
|
||||||
public int get(TemporalField field) {
|
public int get(TemporalField field) {
|
||||||
if (field instanceof ChronoField) {
|
if (field instanceof ChronoField chronoField) {
|
||||||
switch ((ChronoField) field) {
|
switch (chronoField) {
|
||||||
case INSTANT_SECONDS:
|
case INSTANT_SECONDS:
|
||||||
throw new UnsupportedTemporalTypeException("Invalid field 'InstantSeconds' for get() method, use getLong() instead");
|
throw new UnsupportedTemporalTypeException("Invalid field 'InstantSeconds' for get() method, use getLong() instead");
|
||||||
case OFFSET_SECONDS:
|
case OFFSET_SECONDS:
|
||||||
@ -850,8 +850,8 @@ public final class ZonedDateTime
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long getLong(TemporalField field) {
|
public long getLong(TemporalField field) {
|
||||||
if (field instanceof ChronoField) {
|
if (field instanceof ChronoField chronoField) {
|
||||||
switch ((ChronoField) field) {
|
switch (chronoField) {
|
||||||
case INSTANT_SECONDS: return toEpochSecond();
|
case INSTANT_SECONDS: return toEpochSecond();
|
||||||
case OFFSET_SECONDS: return getOffset().getTotalSeconds();
|
case OFFSET_SECONDS: return getOffset().getTotalSeconds();
|
||||||
}
|
}
|
||||||
|
@ -377,8 +377,8 @@ abstract class ChronoLocalDateImpl<D extends ChronoLocalDate>
|
|||||||
public long until(Temporal endExclusive, TemporalUnit unit) {
|
public long until(Temporal endExclusive, TemporalUnit unit) {
|
||||||
Objects.requireNonNull(endExclusive, "endExclusive");
|
Objects.requireNonNull(endExclusive, "endExclusive");
|
||||||
ChronoLocalDate end = getChronology().date(endExclusive);
|
ChronoLocalDate end = getChronology().date(endExclusive);
|
||||||
if (unit instanceof ChronoUnit) {
|
if (unit instanceof ChronoUnit chronoUnit) {
|
||||||
switch ((ChronoUnit) unit) {
|
switch (chronoUnit) {
|
||||||
case DAYS: return daysUntil(end);
|
case DAYS: return daysUntil(end);
|
||||||
case WEEKS: return daysUntil(end) / 7;
|
case WEEKS: return daysUntil(end) / 7;
|
||||||
case MONTHS: return monthsUntil(end);
|
case MONTHS: return monthsUntil(end);
|
||||||
|
@ -373,10 +373,10 @@ final class ChronoLocalDateTimeImpl<D extends ChronoLocalDate>
|
|||||||
Objects.requireNonNull(endExclusive, "endExclusive");
|
Objects.requireNonNull(endExclusive, "endExclusive");
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
ChronoLocalDateTime<D> end = (ChronoLocalDateTime<D>) getChronology().localDateTime(endExclusive);
|
ChronoLocalDateTime<D> end = (ChronoLocalDateTime<D>) getChronology().localDateTime(endExclusive);
|
||||||
if (unit instanceof ChronoUnit) {
|
if (unit instanceof ChronoUnit chronoUnit) {
|
||||||
if (unit.isTimeBased()) {
|
if (unit.isTimeBased()) {
|
||||||
long amount = end.getLong(EPOCH_DAY) - date.getLong(EPOCH_DAY);
|
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 NANOS: amount = Math.multiplyExact(amount, NANOS_PER_DAY); break;
|
||||||
case MICROS: amount = Math.multiplyExact(amount, MICROS_PER_DAY); break;
|
case MICROS: amount = Math.multiplyExact(amount, MICROS_PER_DAY); break;
|
||||||
case MILLIS: amount = Math.multiplyExact(amount, MILLIS_PER_DAY); break;
|
case MILLIS: amount = Math.multiplyExact(amount, MILLIS_PER_DAY); break;
|
||||||
|
@ -199,11 +199,11 @@ final class ChronoPeriodImpl
|
|||||||
*/
|
*/
|
||||||
private ChronoPeriodImpl validateAmount(TemporalAmount amount) {
|
private ChronoPeriodImpl validateAmount(TemporalAmount amount) {
|
||||||
Objects.requireNonNull(amount, "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());
|
throw new DateTimeException("Unable to obtain ChronoPeriod from TemporalAmount: " + amount.getClass());
|
||||||
}
|
}
|
||||||
ChronoPeriodImpl period = (ChronoPeriodImpl) amount;
|
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());
|
throw new ClassCastException("Chronology mismatch, expected: " + chrono.getId() + ", actual: " + period.getChronology().getId());
|
||||||
}
|
}
|
||||||
return period;
|
return period;
|
||||||
@ -320,12 +320,9 @@ final class ChronoPeriodImpl
|
|||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj instanceof ChronoPeriodImpl) {
|
return (obj instanceof ChronoPeriodImpl other)
|
||||||
ChronoPeriodImpl other = (ChronoPeriodImpl) obj;
|
&& years == other.years && months == other.months
|
||||||
return years == other.years && months == other.months &&
|
&& days == other.days && chrono.equals(other.chrono);
|
||||||
days == other.days && chrono.equals(other.chrono);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -195,8 +195,8 @@ public interface ChronoZonedDateTime<D extends ChronoLocalDate>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
default int get(TemporalField field) {
|
default int get(TemporalField field) {
|
||||||
if (field instanceof ChronoField) {
|
if (field instanceof ChronoField chronoField) {
|
||||||
switch ((ChronoField) field) {
|
switch (chronoField) {
|
||||||
case INSTANT_SECONDS:
|
case INSTANT_SECONDS:
|
||||||
throw new UnsupportedTemporalTypeException("Invalid field 'InstantSeconds' for get() method, use getLong() instead");
|
throw new UnsupportedTemporalTypeException("Invalid field 'InstantSeconds' for get() method, use getLong() instead");
|
||||||
case OFFSET_SECONDS:
|
case OFFSET_SECONDS:
|
||||||
@ -209,8 +209,8 @@ public interface ChronoZonedDateTime<D extends ChronoLocalDate>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
default long getLong(TemporalField field) {
|
default long getLong(TemporalField field) {
|
||||||
if (field instanceof ChronoField) {
|
if (field instanceof ChronoField chronoField) {
|
||||||
switch ((ChronoField) field) {
|
switch (chronoField) {
|
||||||
case INSTANT_SECONDS: return toEpochSecond();
|
case INSTANT_SECONDS: return toEpochSecond();
|
||||||
case OFFSET_SECONDS: return getOffset().getTotalSeconds();
|
case OFFSET_SECONDS: return getOffset().getTotalSeconds();
|
||||||
}
|
}
|
||||||
|
@ -498,7 +498,7 @@ public final class HijrahChronology extends AbstractChronology implements Serial
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int prolepticYear(Era era, int yearOfEra) {
|
public int prolepticYear(Era era, int yearOfEra) {
|
||||||
if (era instanceof HijrahEra == false) {
|
if (!(era instanceof HijrahEra)) {
|
||||||
throw new ClassCastException("Era must be HijrahEra");
|
throw new ClassCastException("Era must be HijrahEra");
|
||||||
}
|
}
|
||||||
return yearOfEra;
|
return yearOfEra;
|
||||||
|
@ -628,14 +628,11 @@ public final class HijrahDate
|
|||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj instanceof HijrahDate) {
|
return (obj instanceof HijrahDate otherDate)
|
||||||
HijrahDate otherDate = (HijrahDate) obj;
|
&& prolepticYear == otherDate.prolepticYear
|
||||||
return prolepticYear == otherDate.prolepticYear
|
|
||||||
&& this.monthOfYear == otherDate.monthOfYear
|
&& this.monthOfYear == otherDate.monthOfYear
|
||||||
&& this.dayOfMonth == otherDate.dayOfMonth
|
&& this.dayOfMonth == otherDate.dayOfMonth
|
||||||
&& getChronology().equals(otherDate.getChronology());
|
&& getChronology().equals(otherDate.getChronology());
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -479,7 +479,7 @@ public final class IsoChronology extends AbstractChronology implements Serializa
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int prolepticYear(Era era, int yearOfEra) {
|
public int prolepticYear(Era era, int yearOfEra) {
|
||||||
if (era instanceof IsoEra == false) {
|
if (!(era instanceof IsoEra)) {
|
||||||
throw new ClassCastException("Era must be IsoEra");
|
throw new ClassCastException("Era must be IsoEra");
|
||||||
}
|
}
|
||||||
return (era == IsoEra.CE ? yearOfEra : 1 - yearOfEra);
|
return (era == IsoEra.CE ? yearOfEra : 1 - yearOfEra);
|
||||||
|
@ -202,10 +202,10 @@ public final class JapaneseChronology extends AbstractChronology implements Seri
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public JapaneseDate date(Era era, int yearOfEra, int month, int dayOfMonth) {
|
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");
|
throw new ClassCastException("Era must be JapaneseEra");
|
||||||
}
|
}
|
||||||
return JapaneseDate.of((JapaneseEra) era, yearOfEra, month, dayOfMonth);
|
return JapaneseDate.of(jera, yearOfEra, month, dayOfMonth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -697,11 +697,8 @@ public final class JapaneseDate
|
|||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj instanceof JapaneseDate) {
|
return (obj instanceof JapaneseDate otherDate)
|
||||||
JapaneseDate otherDate = (JapaneseDate) obj;
|
&& this.isoDate.equals(otherDate.isoDate);
|
||||||
return this.isoDate.equals(otherDate.isoDate);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -293,7 +293,7 @@ public final class MinguoChronology extends AbstractChronology implements Serial
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int prolepticYear(Era era, int yearOfEra) {
|
public int prolepticYear(Era era, int yearOfEra) {
|
||||||
if (era instanceof MinguoEra == false) {
|
if (!(era instanceof MinguoEra)) {
|
||||||
throw new ClassCastException("Era must be MinguoEra");
|
throw new ClassCastException("Era must be MinguoEra");
|
||||||
}
|
}
|
||||||
return (era == MinguoEra.ROC ? yearOfEra : 1 - yearOfEra);
|
return (era == MinguoEra.ROC ? yearOfEra : 1 - yearOfEra);
|
||||||
|
@ -459,11 +459,8 @@ public final class MinguoDate
|
|||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj instanceof MinguoDate) {
|
return (obj instanceof MinguoDate otherDate)
|
||||||
MinguoDate otherDate = (MinguoDate) obj;
|
&& this.isoDate.equals(otherDate.isoDate);
|
||||||
return this.isoDate.equals(otherDate.isoDate);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -329,7 +329,7 @@ public final class ThaiBuddhistChronology extends AbstractChronology implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int prolepticYear(Era era, int yearOfEra) {
|
public int prolepticYear(Era era, int yearOfEra) {
|
||||||
if (era instanceof ThaiBuddhistEra == false) {
|
if (!(era instanceof ThaiBuddhistEra)) {
|
||||||
throw new ClassCastException("Era must be BuddhistEra");
|
throw new ClassCastException("Era must be BuddhistEra");
|
||||||
}
|
}
|
||||||
return (era == ThaiBuddhistEra.BE ? yearOfEra : 1 - yearOfEra);
|
return (era == ThaiBuddhistEra.BE ? yearOfEra : 1 - yearOfEra);
|
||||||
|
@ -459,11 +459,8 @@ public final class ThaiBuddhistDate
|
|||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj instanceof ThaiBuddhistDate) {
|
return (obj instanceof ThaiBuddhistDate otherDate)
|
||||||
ThaiBuddhistDate otherDate = (ThaiBuddhistDate) obj;
|
&& this.isoDate.equals(otherDate.isoDate);
|
||||||
return this.isoDate.equals(otherDate.isoDate);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2208,7 +2208,7 @@ public final class DateTimeFormatter {
|
|||||||
Objects.requireNonNull(obj, "obj");
|
Objects.requireNonNull(obj, "obj");
|
||||||
Objects.requireNonNull(toAppendTo, "toAppendTo");
|
Objects.requireNonNull(toAppendTo, "toAppendTo");
|
||||||
Objects.requireNonNull(pos, "pos");
|
Objects.requireNonNull(pos, "pos");
|
||||||
if (obj instanceof TemporalAccessor == false) {
|
if (!(obj instanceof TemporalAccessor)) {
|
||||||
throw new IllegalArgumentException("Format target must implement TemporalAccessor");
|
throw new IllegalArgumentException("Format target must implement TemporalAccessor");
|
||||||
}
|
}
|
||||||
pos.setBeginIndex(0);
|
pos.setBeginIndex(0);
|
||||||
|
@ -165,7 +165,7 @@ public final class DateTimeFormatterBuilder {
|
|||||||
*/
|
*/
|
||||||
private static final TemporalQuery<ZoneId> QUERY_REGION_ONLY = (temporal) -> {
|
private static final TemporalQuery<ZoneId> QUERY_REGION_ONLY = (temporal) -> {
|
||||||
ZoneId zone = temporal.query(TemporalQueries.zoneId());
|
ZoneId zone = temporal.query(TemporalQueries.zoneId());
|
||||||
return (zone != null && zone instanceof ZoneOffset == false ? zone : null);
|
return zone instanceof ZoneOffset ? null : zone;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -189,7 +189,7 @@ final class Parsed implements TemporalAccessor {
|
|||||||
(time != null && time.isSupported(field))) {
|
(time != null && time.isSupported(field))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return field != null && (field instanceof ChronoField == false) && field.isSupportedBy(this);
|
return field != null && (!(field instanceof ChronoField)) && field.isSupportedBy(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -393,12 +393,11 @@ public final class ValueRange implements Serializable {
|
|||||||
if (obj == this) {
|
if (obj == this) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj instanceof ValueRange) {
|
return (obj instanceof ValueRange other)
|
||||||
ValueRange other = (ValueRange) obj;
|
&& minSmallest == other.minSmallest
|
||||||
return minSmallest == other.minSmallest && minLargest == other.minLargest &&
|
&& minLargest == other.minLargest
|
||||||
maxSmallest == other.maxSmallest && maxLargest == other.maxLargest;
|
&& maxSmallest == other.maxSmallest
|
||||||
}
|
&& maxLargest == other.maxLargest;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -421,12 +421,10 @@ public final class ZoneOffsetTransition
|
|||||||
if (other == this) {
|
if (other == this) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (other instanceof ZoneOffsetTransition) {
|
return (other instanceof ZoneOffsetTransition d)
|
||||||
ZoneOffsetTransition d = (ZoneOffsetTransition) other;
|
&& epochSecond == d.epochSecond
|
||||||
return epochSecond == d.epochSecond &&
|
&& offsetBefore.equals(d.offsetBefore)
|
||||||
offsetBefore.equals(d.offsetBefore) && offsetAfter.equals(d.offsetAfter);
|
&& offsetAfter.equals(d.offsetAfter);
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -519,17 +519,16 @@ public final class ZoneOffsetTransitionRule implements Serializable {
|
|||||||
if (otherRule == this) {
|
if (otherRule == this) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (otherRule instanceof ZoneOffsetTransitionRule) {
|
return (otherRule instanceof ZoneOffsetTransitionRule other)
|
||||||
ZoneOffsetTransitionRule other = (ZoneOffsetTransitionRule) otherRule;
|
&& month == other.month
|
||||||
return month == other.month && dom == other.dom && dow == other.dow &&
|
&& dom == other.dom
|
||||||
timeDefinition == other.timeDefinition &&
|
&& dow == other.dow
|
||||||
time.equals(other.time) &&
|
&& timeDefinition == other.timeDefinition
|
||||||
timeEndOfDay == other.timeEndOfDay &&
|
&& timeEndOfDay == other.timeEndOfDay
|
||||||
standardOffset.equals(other.standardOffset) &&
|
&& time.equals(other.time)
|
||||||
offsetBefore.equals(other.offsetBefore) &&
|
&& standardOffset.equals(other.standardOffset)
|
||||||
offsetAfter.equals(other.offsetAfter);
|
&& offsetBefore.equals(other.offsetBefore)
|
||||||
}
|
&& offsetAfter.equals(other.offsetAfter);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1027,15 +1027,12 @@ public final class ZoneRules implements Serializable {
|
|||||||
if (this == otherRules) {
|
if (this == otherRules) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (otherRules instanceof ZoneRules) {
|
return (otherRules instanceof ZoneRules other)
|
||||||
ZoneRules other = (ZoneRules) otherRules;
|
&& Arrays.equals(standardTransitions, other.standardTransitions)
|
||||||
return Arrays.equals(standardTransitions, other.standardTransitions) &&
|
&& Arrays.equals(standardOffsets, other.standardOffsets)
|
||||||
Arrays.equals(standardOffsets, other.standardOffsets) &&
|
&& Arrays.equals(savingsInstantTransitions, other.savingsInstantTransitions)
|
||||||
Arrays.equals(savingsInstantTransitions, other.savingsInstantTransitions) &&
|
&& Arrays.equals(wallOffsets, other.wallOffsets)
|
||||||
Arrays.equals(wallOffsets, other.wallOffsets) &&
|
&& Arrays.equals(lastRules, other.lastRules);
|
||||||
Arrays.equals(lastRules, other.lastRules);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user