8267670: Update java.io, java.math, and java.text to use switch expressions

Reviewed-by: darcy, chegar, naoto, iris, dfuchs, lancea, vtewari
This commit is contained in:
Patrick Concannon 2021-06-01 10:14:56 +00:00
parent f5634fe39d
commit 4eb216824f
11 changed files with 161 additions and 349 deletions

View file

@ -623,12 +623,12 @@ loop: while (true) {
while (count < utflen) { while (count < utflen) {
c = (int) bytearr[count] & 0xff; c = (int) bytearr[count] & 0xff;
switch (c >> 4) { switch (c >> 4) {
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 0, 1, 2, 3, 4, 5, 6, 7 -> {
/* 0xxxxxxx*/ /* 0xxxxxxx*/
count++; count++;
chararr[chararr_count++]=(char)c; chararr[chararr_count++]=(char)c;
break; }
case 12: case 13: case 12, 13 -> {
/* 110x xxxx 10xx xxxx*/ /* 110x xxxx 10xx xxxx*/
count += 2; count += 2;
if (count > utflen) if (count > utflen)
@ -640,8 +640,8 @@ loop: while (true) {
"malformed input around byte " + count); "malformed input around byte " + count);
chararr[chararr_count++]=(char)(((c & 0x1F) << 6) | chararr[chararr_count++]=(char)(((c & 0x1F) << 6) |
(char2 & 0x3F)); (char2 & 0x3F));
break; }
case 14: case 14 -> {
/* 1110 xxxx 10xx xxxx 10xx xxxx */ /* 1110 xxxx 10xx xxxx 10xx xxxx */
count += 3; count += 3;
if (count > utflen) if (count > utflen)
@ -655,8 +655,8 @@ loop: while (true) {
chararr[chararr_count++]=(char)(((c & 0x0F) << 12) | chararr[chararr_count++]=(char)(((c & 0x0F) << 12) |
((char2 & 0x3F) << 6) | ((char2 & 0x3F) << 6) |
((char3 & 0x3F) << 0)); ((char3 & 0x3F) << 0));
break; }
default: default ->
/* 10xx xxxx, 1111 xxxx */ /* 10xx xxxx, 1111 xxxx */
throw new UTFDataFormatException( throw new UTFDataFormatException(
"malformed input around byte " + count); "malformed input around byte " + count);

View file

@ -1778,21 +1778,13 @@ public class ObjectInputStream
int oldHandle = passHandle; int oldHandle = passHandle;
try { try {
byte tc = bin.peekByte(); byte tc = bin.peekByte();
switch (tc) { return switch (tc) {
case TC_NULL: case TC_NULL -> (String) readNull();
return (String) readNull(); case TC_REFERENCE -> (String) readHandle(false);
case TC_STRING, TC_LONGSTRING -> readString(false);
case TC_REFERENCE: default -> throw new StreamCorruptedException(
return (String) readHandle(false);
case TC_STRING:
case TC_LONGSTRING:
return readString(false);
default:
throw new StreamCorruptedException(
String.format("invalid type code: %02X", tc)); String.format("invalid type code: %02X", tc));
} };
} finally { } finally {
passHandle = oldHandle; passHandle = oldHandle;
} }
@ -1872,27 +1864,20 @@ public class ObjectInputStream
throws IOException throws IOException
{ {
byte tc = bin.peekByte(); byte tc = bin.peekByte();
ObjectStreamClass descriptor;
switch (tc) { return switch (tc) {
case TC_NULL: case TC_NULL -> (ObjectStreamClass) readNull();
descriptor = (ObjectStreamClass) readNull(); case TC_PROXYCLASSDESC -> readProxyDesc(unshared);
break; case TC_CLASSDESC -> readNonProxyDesc(unshared);
case TC_REFERENCE: case TC_REFERENCE -> {
descriptor = (ObjectStreamClass) readHandle(unshared); var d = (ObjectStreamClass) readHandle(unshared);
// Should only reference initialized class descriptors // Should only reference initialized class descriptors
descriptor.checkInitialized(); d.checkInitialized();
break; yield d;
case TC_PROXYCLASSDESC: }
descriptor = readProxyDesc(unshared); default -> throw new StreamCorruptedException(
break;
case TC_CLASSDESC:
descriptor = readNonProxyDesc(unshared);
break;
default:
throw new StreamCorruptedException(
String.format("invalid type code: %02X", tc)); String.format("invalid type code: %02X", tc));
} };
return descriptor;
} }
private boolean isCustomSubclass() { private boolean isCustomSubclass() {
@ -2052,21 +2037,13 @@ public class ObjectInputStream
* assigned handle. * assigned handle.
*/ */
private String readString(boolean unshared) throws IOException { private String readString(boolean unshared) throws IOException {
String str;
byte tc = bin.readByte(); byte tc = bin.readByte();
switch (tc) { String str = switch (tc) {
case TC_STRING: case TC_STRING -> bin.readUTF();
str = bin.readUTF(); case TC_LONGSTRING -> bin.readLongUTF();
break; default -> throw new StreamCorruptedException(
case TC_LONGSTRING:
str = bin.readLongUTF();
break;
default:
throw new StreamCorruptedException(
String.format("invalid type code: %02X", tc)); String.format("invalid type code: %02X", tc));
} };
passHandle = handles.assign(unshared ? unsharedMarker : str); passHandle = handles.assign(unshared ? unsharedMarker : str);
handles.finish(passHandle); handles.finish(passHandle);
return str; return str;
@ -3680,28 +3657,17 @@ public class ObjectInputStream
int b1, b2, b3; int b1, b2, b3;
b1 = buf[pos++] & 0xFF; b1 = buf[pos++] & 0xFF;
switch (b1 >> 4) { switch (b1 >> 4) {
case 0: case 0, 1, 2, 3, 4, 5, 6, 7 -> // 1 byte format: 0xxxxxxx
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7: // 1 byte format: 0xxxxxxx
cbuf[cpos++] = (char) b1; cbuf[cpos++] = (char) b1;
break; case 12, 13 -> { // 2 byte format: 110xxxxx 10xxxxxx
case 12:
case 13: // 2 byte format: 110xxxxx 10xxxxxx
b2 = buf[pos++]; b2 = buf[pos++];
if ((b2 & 0xC0) != 0x80) { if ((b2 & 0xC0) != 0x80) {
throw new UTFDataFormatException(); throw new UTFDataFormatException();
} }
cbuf[cpos++] = (char) (((b1 & 0x1F) << 6) | cbuf[cpos++] = (char) (((b1 & 0x1F) << 6) |
((b2 & 0x3F) << 0)); ((b2 & 0x3F) << 0));
break; }
case 14 -> { // 3 byte format: 1110xxxx 10xxxxxx 10xxxxxx
case 14: // 3 byte format: 1110xxxx 10xxxxxx 10xxxxxx
b3 = buf[pos + 1]; b3 = buf[pos + 1];
b2 = buf[pos + 0]; b2 = buf[pos + 0];
pos += 2; pos += 2;
@ -3711,10 +3677,8 @@ public class ObjectInputStream
cbuf[cpos++] = (char) (((b1 & 0x0F) << 12) | cbuf[cpos++] = (char) (((b1 & 0x0F) << 12) |
((b2 & 0x3F) << 6) | ((b2 & 0x3F) << 6) |
((b3 & 0x3F) << 0)); ((b3 & 0x3F) << 0));
break; }
default -> throw new UTFDataFormatException(); // 10xx xxxx, 1111 xxxx
default: // 10xx xxxx, 1111 xxxx
throw new UTFDataFormatException();
} }
} }
} catch (ArrayIndexOutOfBoundsException ex) { } catch (ArrayIndexOutOfBoundsException ex) {
@ -3748,19 +3712,11 @@ public class ObjectInputStream
int b1, b2, b3; int b1, b2, b3;
b1 = readByte() & 0xFF; b1 = readByte() & 0xFF;
switch (b1 >> 4) { switch (b1 >> 4) {
case 0: case 0, 1, 2, 3, 4, 5, 6, 7 -> { // 1 byte format: 0xxxxxxx
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7: // 1 byte format: 0xxxxxxx
sbuf.append((char) b1); sbuf.append((char) b1);
return 1; return 1;
}
case 12: case 12, 13 -> { // 2 byte format: 110xxxxx 10xxxxxx
case 13: // 2 byte format: 110xxxxx 10xxxxxx
if (utflen < 2) { if (utflen < 2) {
throw new UTFDataFormatException(); throw new UTFDataFormatException();
} }
@ -3771,8 +3727,8 @@ public class ObjectInputStream
sbuf.append((char) (((b1 & 0x1F) << 6) | sbuf.append((char) (((b1 & 0x1F) << 6) |
((b2 & 0x3F) << 0))); ((b2 & 0x3F) << 0)));
return 2; return 2;
}
case 14: // 3 byte format: 1110xxxx 10xxxxxx 10xxxxxx case 14 -> { // 3 byte format: 1110xxxx 10xxxxxx 10xxxxxx
if (utflen < 3) { if (utflen < 3) {
if (utflen == 2) { if (utflen == 2) {
readByte(); // consume remaining byte readByte(); // consume remaining byte
@ -3785,12 +3741,11 @@ public class ObjectInputStream
throw new UTFDataFormatException(); throw new UTFDataFormatException();
} }
sbuf.append((char) (((b1 & 0x0F) << 12) | sbuf.append((char) (((b1 & 0x0F) << 12) |
((b2 & 0x3F) << 6) | ((b2 & 0x3F) << 6) |
((b3 & 0x3F) << 0))); ((b3 & 0x3F) << 0)));
return 3; return 3;
}
default: // 10xx xxxx, 1111 xxxx default -> throw new UTFDataFormatException(); // 10xx xxxx, 1111 xxxx
throw new UTFDataFormatException();
} }
} }

View file

@ -1493,39 +1493,26 @@ public class ObjectStreamClass implements Serializable {
for (int i = 0; i < fields.length; i++) { for (int i = 0; i < fields.length; i++) {
ObjectStreamField f = fields[i]; ObjectStreamField f = fields[i];
switch (f.getTypeCode()) { switch (f.getTypeCode()) {
case 'Z': case 'Z', 'B' -> f.setOffset(primDataSize++);
case 'B': case 'C', 'S' -> {
f.setOffset(primDataSize++);
break;
case 'C':
case 'S':
f.setOffset(primDataSize); f.setOffset(primDataSize);
primDataSize += 2; primDataSize += 2;
break; }
case 'I', 'F' -> {
case 'I':
case 'F':
f.setOffset(primDataSize); f.setOffset(primDataSize);
primDataSize += 4; primDataSize += 4;
break; }
case 'J', 'D' -> {
case 'J':
case 'D':
f.setOffset(primDataSize); f.setOffset(primDataSize);
primDataSize += 8; primDataSize += 8;
break; }
case '[', 'L' -> {
case '[':
case 'L':
f.setOffset(numObjFields++); f.setOffset(numObjFields++);
if (firstObjIndex == -1) { if (firstObjIndex == -1) {
firstObjIndex = i; firstObjIndex = i;
} }
break; }
default -> throw new InternalError();
default:
throw new InternalError();
} }
} }
if (firstObjIndex != -1 && if (firstObjIndex != -1 &&
@ -2124,40 +2111,15 @@ public class ObjectStreamClass implements Serializable {
long key = readKeys[i]; long key = readKeys[i];
int off = offsets[i]; int off = offsets[i];
switch (typeCodes[i]) { switch (typeCodes[i]) {
case 'Z': case 'Z' -> Bits.putBoolean(buf, off, unsafe.getBoolean(obj, key));
Bits.putBoolean(buf, off, unsafe.getBoolean(obj, key)); case 'B' -> buf[off] = unsafe.getByte(obj, key);
break; case 'C' -> Bits.putChar(buf, off, unsafe.getChar(obj, key));
case 'S' -> Bits.putShort(buf, off, unsafe.getShort(obj, key));
case 'B': case 'I' -> Bits.putInt(buf, off, unsafe.getInt(obj, key));
buf[off] = unsafe.getByte(obj, key); case 'F' -> Bits.putFloat(buf, off, unsafe.getFloat(obj, key));
break; case 'J' -> Bits.putLong(buf, off, unsafe.getLong(obj, key));
case 'D' -> Bits.putDouble(buf, off, unsafe.getDouble(obj, key));
case 'C': default -> throw new InternalError();
Bits.putChar(buf, off, unsafe.getChar(obj, key));
break;
case 'S':
Bits.putShort(buf, off, unsafe.getShort(obj, key));
break;
case 'I':
Bits.putInt(buf, off, unsafe.getInt(obj, key));
break;
case 'F':
Bits.putFloat(buf, off, unsafe.getFloat(obj, key));
break;
case 'J':
Bits.putLong(buf, off, unsafe.getLong(obj, key));
break;
case 'D':
Bits.putDouble(buf, off, unsafe.getDouble(obj, key));
break;
default:
throw new InternalError();
} }
} }
} }
@ -2178,40 +2140,15 @@ public class ObjectStreamClass implements Serializable {
} }
int off = offsets[i]; int off = offsets[i];
switch (typeCodes[i]) { switch (typeCodes[i]) {
case 'Z': case 'Z' -> unsafe.putBoolean(obj, key, Bits.getBoolean(buf, off));
unsafe.putBoolean(obj, key, Bits.getBoolean(buf, off)); case 'B' -> unsafe.putByte(obj, key, buf[off]);
break; case 'C' -> unsafe.putChar(obj, key, Bits.getChar(buf, off));
case 'S' -> unsafe.putShort(obj, key, Bits.getShort(buf, off));
case 'B': case 'I' -> unsafe.putInt(obj, key, Bits.getInt(buf, off));
unsafe.putByte(obj, key, buf[off]); case 'F' -> unsafe.putFloat(obj, key, Bits.getFloat(buf, off));
break; case 'J' -> unsafe.putLong(obj, key, Bits.getLong(buf, off));
case 'D' -> unsafe.putDouble(obj, key, Bits.getDouble(buf, off));
case 'C': default -> throw new InternalError();
unsafe.putChar(obj, key, Bits.getChar(buf, off));
break;
case 'S':
unsafe.putShort(obj, key, Bits.getShort(buf, off));
break;
case 'I':
unsafe.putInt(obj, key, Bits.getInt(buf, off));
break;
case 'F':
unsafe.putFloat(obj, key, Bits.getFloat(buf, off));
break;
case 'J':
unsafe.putLong(obj, key, Bits.getLong(buf, off));
break;
case 'D':
unsafe.putDouble(obj, key, Bits.getDouble(buf, off));
break;
default:
throw new InternalError();
} }
} }
} }
@ -2230,15 +2167,10 @@ public class ObjectStreamClass implements Serializable {
* in array should be equal to Unsafe.INVALID_FIELD_OFFSET. * in array should be equal to Unsafe.INVALID_FIELD_OFFSET.
*/ */
for (int i = numPrimFields; i < fields.length; i++) { for (int i = numPrimFields; i < fields.length; i++) {
switch (typeCodes[i]) { vals[offsets[i]] = switch (typeCodes[i]) {
case 'L': case 'L', '[' -> unsafe.getReference(obj, readKeys[i]);
case '[': default -> throw new InternalError();
vals[offsets[i]] = unsafe.getReference(obj, readKeys[i]); };
break;
default:
throw new InternalError();
}
} }
} }
@ -2272,8 +2204,7 @@ public class ObjectStreamClass implements Serializable {
continue; // discard value continue; // discard value
} }
switch (typeCodes[i]) { switch (typeCodes[i]) {
case 'L': case 'L', '[' -> {
case '[':
Object val = vals[offsets[i]]; Object val = vals[offsets[i]];
if (val != null && if (val != null &&
!types[i - numPrimFields].isInstance(val)) !types[i - numPrimFields].isInstance(val))
@ -2289,10 +2220,8 @@ public class ObjectStreamClass implements Serializable {
} }
if (!dryRun) if (!dryRun)
unsafe.putReference(obj, key, val); unsafe.putReference(obj, key, val);
break; }
default -> throw new InternalError();
default:
throw new InternalError();
} }
} }
} }

View file

@ -110,19 +110,18 @@ public class ObjectStreamField
this.unshared = unshared; this.unshared = unshared;
this.field = null; this.field = null;
switch (signature.charAt(0)) { type = switch (signature.charAt(0)) {
case 'Z': type = Boolean.TYPE; break; case 'Z' -> Boolean.TYPE;
case 'B': type = Byte.TYPE; break; case 'B' -> Byte.TYPE;
case 'C': type = Character.TYPE; break; case 'C' -> Character.TYPE;
case 'S': type = Short.TYPE; break; case 'S' -> Short.TYPE;
case 'I': type = Integer.TYPE; break; case 'I' -> Integer.TYPE;
case 'J': type = Long.TYPE; break; case 'J' -> Long.TYPE;
case 'F': type = Float.TYPE; break; case 'F' -> Float.TYPE;
case 'D': type = Double.TYPE; break; case 'D' -> Double.TYPE;
case 'L': case 'L', '[' -> Object.class;
case '[': type = Object.class; break; default -> throw new IllegalArgumentException("illegal signature");
default: throw new IllegalArgumentException("illegal signature"); };
}
} }
/** /**

View file

@ -658,29 +658,16 @@ public class StreamTokenizer {
} else } else
d = c2; d = c2;
} else { } else {
switch (c) { c = switch (c) {
case 'a': case 'a' -> 0x7;
c = 0x7; case 'b' -> '\b';
break; case 'f' -> 0xC;
case 'b': case 'n' -> '\n';
c = '\b'; case 'r' -> '\r';
break; case 't' -> '\t';
case 'f': case 'v' -> 0xB;
c = 0xC; default -> c;
break; };
case 'n':
c = '\n';
break;
case 'r':
c = '\r';
break;
case 't':
c = '\t';
break;
case 'v':
c = 0xB;
break;
}
d = read(); d = read();
} }
} else { } else {
@ -791,43 +778,28 @@ public class StreamTokenizer {
* @see java.io.StreamTokenizer#ttype * @see java.io.StreamTokenizer#ttype
*/ */
public String toString() { public String toString() {
String ret; String ret = switch (ttype) {
switch (ttype) { case TT_EOF -> "EOF";
case TT_EOF: case TT_EOL -> "EOL";
ret = "EOF"; case TT_WORD -> sval;
break; case TT_NUMBER -> "n=" + nval;
case TT_EOL: case TT_NOTHING -> "NOTHING";
ret = "EOL"; default -> {
break;
case TT_WORD:
ret = sval;
break;
case TT_NUMBER:
ret = "n=" + nval;
break;
case TT_NOTHING:
ret = "NOTHING";
break;
default: {
/* /*
* ttype is the first character of either a quoted string or * ttype is the first character of either a quoted string or
* is an ordinary character. ttype can definitely not be less * is an ordinary character. ttype can definitely not be less
* than 0, since those are reserved values used in the previous * than 0, since those are reserved values used in the previous
* case statements * case statements
*/ */
if (ttype < 256 && if (ttype < 256 && ((ctype[ttype] & CT_QUOTE) != 0)) {
((ctype[ttype] & CT_QUOTE) != 0)) { yield sval;
ret = sval;
break;
} }
char s[] = new char[3]; char s[] = new char[3];
s[0] = s[2] = '\''; s[0] = s[2] = '\'';
s[1] = (char) ttype; s[1] = (char) ttype;
ret = new String(s); yield new String(s);
break;
} }
} };
return "Token[" + ret + "], line " + LINENO; return "Token[" + ret + "], line " + LINENO;
} }

View file

@ -4706,19 +4706,13 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
else { // half-way else { // half-way
assert cmpFracHalf == 0; assert cmpFracHalf == 0;
switch(roundingMode) { return switch (roundingMode) {
case ROUND_HALF_DOWN: case ROUND_HALF_DOWN -> false;
return false; case ROUND_HALF_UP -> true;
case ROUND_HALF_EVEN -> oddQuot;
case ROUND_HALF_UP: default -> throw new AssertionError("Unexpected rounding mode" + roundingMode);
return true; };
case ROUND_HALF_EVEN:
return oddQuot;
default:
throw new AssertionError("Unexpected rounding mode" + roundingMode);
}
} }
} }
} }

View file

@ -3791,14 +3791,11 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
*/ */
public int compareTo(BigInteger val) { public int compareTo(BigInteger val) {
if (signum == val.signum) { if (signum == val.signum) {
switch (signum) { return switch (signum) {
case 1: case 1 -> compareMagnitude(val);
return compareMagnitude(val); case -1 -> val.compareMagnitude(this);
case -1: default -> 0;
return val.compareMagnitude(this); };
default:
return 0;
}
} }
return signum > val.signum ? 1 : -1; return signum > val.signum ? 1 : -1;
} }

View file

@ -377,34 +377,16 @@ public enum RoundingMode {
* @throws IllegalArgumentException integer is out of range * @throws IllegalArgumentException integer is out of range
*/ */
public static RoundingMode valueOf(int rm) { public static RoundingMode valueOf(int rm) {
switch(rm) { return switch (rm) {
case BigDecimal.ROUND_UP -> UP;
case BigDecimal.ROUND_UP: case BigDecimal.ROUND_DOWN -> DOWN;
return UP; case BigDecimal.ROUND_CEILING -> CEILING;
case BigDecimal.ROUND_FLOOR -> FLOOR;
case BigDecimal.ROUND_DOWN: case BigDecimal.ROUND_HALF_UP -> HALF_UP;
return DOWN; case BigDecimal.ROUND_HALF_DOWN -> HALF_DOWN;
case BigDecimal.ROUND_HALF_EVEN -> HALF_EVEN;
case BigDecimal.ROUND_CEILING: case BigDecimal.ROUND_UNNECESSARY -> UNNECESSARY;
return CEILING; default -> throw new IllegalArgumentException("argument out of range");
};
case BigDecimal.ROUND_FLOOR:
return FLOOR;
case BigDecimal.ROUND_HALF_UP:
return HALF_UP;
case BigDecimal.ROUND_HALF_DOWN:
return HALF_DOWN;
case BigDecimal.ROUND_HALF_EVEN:
return HALF_EVEN;
case BigDecimal.ROUND_UNNECESSARY:
return UNNECESSARY;
default:
throw new IllegalArgumentException("argument out of range");
}
} }
} }

View file

@ -560,22 +560,13 @@ public abstract class BreakIterator implements Cloneable
private static BreakIterator createBreakInstance(LocaleProviderAdapter adapter, Locale locale, int type) { private static BreakIterator createBreakInstance(LocaleProviderAdapter adapter, Locale locale, int type) {
BreakIteratorProvider breakIteratorProvider = adapter.getBreakIteratorProvider(); BreakIteratorProvider breakIteratorProvider = adapter.getBreakIteratorProvider();
BreakIterator iterator = null; return switch (type) {
switch (type) { case CHARACTER_INDEX -> breakIteratorProvider.getCharacterInstance(locale);
case CHARACTER_INDEX: case WORD_INDEX -> breakIteratorProvider.getWordInstance(locale);
iterator = breakIteratorProvider.getCharacterInstance(locale); case LINE_INDEX -> breakIteratorProvider.getLineInstance(locale);
break; case SENTENCE_INDEX -> breakIteratorProvider.getSentenceInstance(locale);
case WORD_INDEX: default -> null;
iterator = breakIteratorProvider.getWordInstance(locale); };
break;
case LINE_INDEX:
iterator = breakIteratorProvider.getLineInstance(locale);
break;
case SENTENCE_INDEX:
iterator = breakIteratorProvider.getSentenceInstance(locale);
break;
}
return iterator;
} }
/** /**

View file

@ -972,25 +972,14 @@ public abstract class NumberFormat extends Format {
Locale locale, Style formatStyle, Locale locale, Style formatStyle,
int choice) { int choice) {
NumberFormatProvider provider = adapter.getNumberFormatProvider(); NumberFormatProvider provider = adapter.getNumberFormatProvider();
NumberFormat numberFormat = null; return switch (choice) {
switch (choice) { case NUMBERSTYLE -> provider.getNumberInstance(locale);
case NUMBERSTYLE: case PERCENTSTYLE -> provider.getPercentInstance(locale);
numberFormat = provider.getNumberInstance(locale); case CURRENCYSTYLE -> provider.getCurrencyInstance(locale);
break; case INTEGERSTYLE -> provider.getIntegerInstance(locale);
case PERCENTSTYLE: case COMPACTSTYLE -> provider.getCompactNumberInstance(locale, formatStyle);
numberFormat = provider.getPercentInstance(locale); default -> null;
break; };
case CURRENCYSTYLE:
numberFormat = provider.getCurrencyInstance(locale);
break;
case INTEGERSTYLE:
numberFormat = provider.getIntegerInstance(locale);
break;
case COMPACTSTYLE:
numberFormat = provider.getCompactNumberInstance(locale, formatStyle);
break;
}
return numberFormat;
} }
/** /**

View file

@ -130,14 +130,18 @@ class PatternEntry {
if (showWhiteSpace) if (showWhiteSpace)
toAddTo.append(' '); toAddTo.append(' ');
} }
switch (strength) { var c = switch (strength) {
case Collator.IDENTICAL: toAddTo.append('='); break; case Collator.IDENTICAL -> '=';
case Collator.TERTIARY: toAddTo.append(','); break; case Collator.TERTIARY -> ',';
case Collator.SECONDARY: toAddTo.append(';'); break; case Collator.SECONDARY -> ';';
case Collator.PRIMARY: toAddTo.append('<'); break; case Collator.PRIMARY -> '<';
case RESET: toAddTo.append('&'); break; case RESET -> '&';
case UNSET: toAddTo.append('?'); break; case UNSET -> '?';
}
default -> throw new IllegalStateException("Unexpected value: " + strength);
};
toAddTo.append(c);
if (showWhiteSpace) if (showWhiteSpace)
toAddTo.append(' '); toAddTo.append(' ');
appendQuoted(chars,toAddTo); appendQuoted(chars,toAddTo);