--- a/src/java.base/share/classes/java/util/Locale.java Thu Dec 13 16:14:07 2018 +0100
+++ b/src/java.base/share/classes/java/util/Locale.java Thu Dec 13 15:31:05 2018 +0100
@@ -1396,11 +1396,11 @@
*/
@Override
public final String toString() {
- boolean l = (baseLocale.getLanguage().length() != 0);
- boolean s = (baseLocale.getScript().length() != 0);
- boolean r = (baseLocale.getRegion().length() != 0);
- boolean v = (baseLocale.getVariant().length() != 0);
- boolean e = (localeExtensions != null && localeExtensions.getID().length() != 0);
+ boolean l = !baseLocale.getLanguage().isEmpty();
+ boolean s = !baseLocale.getScript().isEmpty();
+ boolean r = !baseLocale.getRegion().isEmpty();
+ boolean v = !baseLocale.getVariant().isEmpty();
+ boolean e = localeExtensions != null && !localeExtensions.getID().isEmpty();
StringBuilder result = new StringBuilder(baseLocale.getLanguage());
if (r || (l && (v || s || e))) {
@@ -1504,18 +1504,18 @@
StringBuilder buf = new StringBuilder();
String subtag = tag.getLanguage();
- if (subtag.length() > 0) {
+ if (!subtag.isEmpty()) {
buf.append(LanguageTag.canonicalizeLanguage(subtag));
}
subtag = tag.getScript();
- if (subtag.length() > 0) {
+ if (!subtag.isEmpty()) {
buf.append(LanguageTag.SEP);
buf.append(LanguageTag.canonicalizeScript(subtag));
}
subtag = tag.getRegion();
- if (subtag.length() > 0) {
+ if (!subtag.isEmpty()) {
buf.append(LanguageTag.SEP);
buf.append(LanguageTag.canonicalizeRegion(subtag));
}
@@ -1534,7 +1534,7 @@
}
subtag = tag.getPrivateuse();
- if (subtag.length() > 0) {
+ if (!subtag.isEmpty()) {
if (buf.length() > 0) {
buf.append(LanguageTag.SEP);
}
@@ -1684,7 +1684,7 @@
bldr.setLanguageTag(tag);
BaseLocale base = bldr.getBaseLocale();
LocaleExtensions exts = bldr.getLocaleExtensions();
- if (exts == null && base.getVariant().length() > 0) {
+ if (exts == null && !base.getVariant().isEmpty()) {
exts = getCompatibilityExtensions(base.getLanguage(), base.getScript(),
base.getRegion(), base.getVariant());
}
@@ -1917,7 +1917,7 @@
* @exception NullPointerException if <code>inLocale</code> is <code>null</code>
*/
public String getDisplayVariant(Locale inLocale) {
- if (baseLocale.getVariant().length() == 0)
+ if (baseLocale.getVariant().isEmpty())
return "";
LocaleResources lr = LocaleProviderAdapter
@@ -1998,14 +1998,14 @@
// The display name consists of a main name, followed by qualifiers.
// Typically, the format is "MainName (Qualifier, Qualifier)" but this
// depends on what pattern is stored in the display locale.
- String mainName = null;
- String[] qualifierNames = null;
+ String mainName;
+ String[] qualifierNames;
// The main name is the language, or if there is no language, the script,
// then if no script, the country. If there is no language/script/country
// (an anomalous situation) then the display name is simply the variant's
// display name.
- if (languageName.length() == 0 && scriptName.length() == 0 && countryName.length() == 0) {
+ if (languageName.isEmpty() && scriptName.isEmpty() && countryName.isEmpty()) {
if (variantNames.length == 0) {
return "";
} else {
@@ -2013,13 +2013,13 @@
}
}
ArrayList<String> names = new ArrayList<>(4);
- if (languageName.length() != 0) {
+ if (!languageName.isEmpty()) {
names.add(languageName);
}
- if (scriptName.length() != 0) {
+ if (!scriptName.isEmpty()) {
names.add(scriptName);
}
- if (countryName.length() != 0) {
+ if (!countryName.isEmpty()) {
names.add(countryName);
}
if (variantNames.length != 0) {
@@ -2309,7 +2309,7 @@
String variant = (String)fields.get("variant", "");
String extStr = (String)fields.get("extensions", "");
baseLocale = BaseLocale.getInstance(convertOldISOCodes(language), script, country, variant);
- if (extStr.length() > 0) {
+ if (!extStr.isEmpty()) {
try {
InternalLocaleBuilder bldr = new InternalLocaleBuilder();
bldr.setExtensions(extStr);
@@ -2367,13 +2367,13 @@
LocaleExtensions extensions = null;
// Special cases for backward compatibility support
if (LocaleUtils.caseIgnoreMatch(language, "ja")
- && script.length() == 0
+ && script.isEmpty()
&& LocaleUtils.caseIgnoreMatch(country, "jp")
&& "JP".equals(variant)) {
// ja_JP_JP -> u-ca-japanese (calendar = japanese)
extensions = LocaleExtensions.CALENDAR_JAPANESE;
} else if (LocaleUtils.caseIgnoreMatch(language, "th")
- && script.length() == 0
+ && script.isEmpty()
&& LocaleUtils.caseIgnoreMatch(country, "th")
&& "TH".equals(variant)) {
// th_TH_TH -> u-nu-thai (numbersystem = thai)
@@ -2806,7 +2806,7 @@
public Locale build() {
BaseLocale baseloc = localeBuilder.getBaseLocale();
LocaleExtensions extensions = localeBuilder.getLocaleExtensions();
- if (extensions == null && baseloc.getVariant().length() > 0) {
+ if (extensions == null && !baseloc.getVariant().isEmpty()) {
extensions = getCompatibilityExtensions(baseloc.getLanguage(), baseloc.getScript(),
baseloc.getRegion(), baseloc.getVariant());
}