mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8268124: Update java.lang to use switch expressions
Reviewed-by: naoto, darcy, mchung, iris, lancea, dfuchs
This commit is contained in:
parent
a187fcc3ec
commit
d43c8a74b3
22 changed files with 421 additions and 551 deletions
|
@ -213,38 +213,27 @@ public final class Long extends Number
|
|||
if (i >= 0)
|
||||
return toString(i, radix);
|
||||
else {
|
||||
switch (radix) {
|
||||
case 2:
|
||||
return toBinaryString(i);
|
||||
|
||||
case 4:
|
||||
return toUnsignedString0(i, 2);
|
||||
|
||||
case 8:
|
||||
return toOctalString(i);
|
||||
|
||||
case 10:
|
||||
/*
|
||||
* We can get the effect of an unsigned division by 10
|
||||
* on a long value by first shifting right, yielding a
|
||||
* positive value, and then dividing by 5. This
|
||||
* allows the last digit and preceding digits to be
|
||||
* isolated more quickly than by an initial conversion
|
||||
* to BigInteger.
|
||||
*/
|
||||
long quot = (i >>> 1) / 5;
|
||||
long rem = i - quot * 10;
|
||||
return toString(quot) + rem;
|
||||
|
||||
case 16:
|
||||
return toHexString(i);
|
||||
|
||||
case 32:
|
||||
return toUnsignedString0(i, 5);
|
||||
|
||||
default:
|
||||
return toUnsignedBigInteger(i).toString(radix);
|
||||
}
|
||||
return switch (radix) {
|
||||
case 2 -> toBinaryString(i);
|
||||
case 4 -> toUnsignedString0(i, 2);
|
||||
case 8 -> toOctalString(i);
|
||||
case 10 -> {
|
||||
/*
|
||||
* We can get the effect of an unsigned division by 10
|
||||
* on a long value by first shifting right, yielding a
|
||||
* positive value, and then dividing by 5. This
|
||||
* allows the last digit and preceding digits to be
|
||||
* isolated more quickly than by an initial conversion
|
||||
* to BigInteger.
|
||||
*/
|
||||
long quot = (i >>> 1) / 5;
|
||||
long rem = i - quot * 10;
|
||||
yield toString(quot) + rem;
|
||||
}
|
||||
case 16 -> toHexString(i);
|
||||
case 32 -> toUnsignedString0(i, 5);
|
||||
default -> toUnsignedBigInteger(i).toString(radix);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue