8267587: Update java.util to use enhanced switch

Reviewed-by: iris
This commit is contained in:
Tagir F. Valeev 2021-05-31 08:48:38 +00:00
parent 35916ed57f
commit ab5a7ff230
15 changed files with 556 additions and 776 deletions

View file

@ -2257,23 +2257,20 @@ public final class Locale implements Cloneable, Serializable {
return Arrays.stream(stringList).collect(Collectors.joining(","));
}
switch (stringList.length) {
case 0:
return "";
case 1:
return stringList[0];
default:
return Arrays.stream(stringList).reduce("",
(s1, s2) -> {
if (s1.isEmpty()) {
return s2;
}
if (s2.isEmpty()) {
return s1;
}
return MessageFormat.format(pattern, s1, s2);
});
}
return switch (stringList.length) {
case 0 -> "";
case 1 -> stringList[0];
default -> Arrays.stream(stringList).reduce("",
(s1, s2) -> {
if (s1.isEmpty()) {
return s2;
}
if (s2.isEmpty()) {
return s1;
}
return MessageFormat.format(pattern, s1, s2);
});
};
}
// Duplicate of sun.util.locale.UnicodeLocaleExtension.isKey in order to