mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
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
34 changed files with 129 additions and 176 deletions
|
@ -485,8 +485,8 @@ public final class YearMonth
|
|||
*/
|
||||
@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 final class YearMonth
|
|||
*/
|
||||
@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 final class YearMonth
|
|||
@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 final class YearMonth
|
|||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue