RFR: 8267670: Update java.io, java.math, and java.text to use switch expressions
Chris Hegarty
chegar at openjdk.java.net
Tue May 25 13:00:01 UTC 2021
On Tue, 25 May 2021 09:37:58 GMT, Patrick Concannon <pconcannon at openjdk.org> wrote:
> Hi,
>
> Could someone please review my code for updating the code in the `java.io`, `java.math`, and `java.text` packages to make use of the switch expressions?
>
> Kind regards,
> Patrick
src/java.base/share/classes/java/io/StreamTokenizer.java line 795:
> 793: * case statements
> 794: */
> 795: if (ttype < 256 && ((ctype[ttype] & CT_QUOTE) != 0)) {
Maybe (since its easier to grok the yield rather than the assignment of ret in branches):
String ret = switch (ttype) {
case TT_EOF -> "EOF";
case TT_EOL -> "EOL";
case TT_WORD -> sval;
case TT_NUMBER -> "n=" + nval;
case TT_NOTHING -> "NOTHING";
default -> {
/*
* ttype is the first character of either a quoted string or
* is an ordinary character. ttype can definitely not be less
* than 0, since those are reserved values used in the previous
* case statements
*/
if (ttype < 256 && ((ctype[ttype] & CT_QUOTE) != 0)) {
yield sval;
}
char s[] = new char[3];
s[0] = s[2] = ''';
s[1] = (char) ttype;
yield new String(s);
}
};
return "Token[" + ret + "], line " + LINENO;
-------------
PR: https://git.openjdk.java.net/jdk/pull/4182
More information about the core-libs-dev
mailing list