mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: dfuchs, alanb
This commit is contained in:
parent
c998ead188
commit
a3df1d618e
155 changed files with 340 additions and 382 deletions
|
@ -1396,11 +1396,11 @@ public final class Locale implements Cloneable, Serializable {
|
|||
*/
|
||||
@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 @@ public final class Locale implements Cloneable, Serializable {
|
|||
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 @@ public final class Locale implements Cloneable, Serializable {
|
|||
}
|
||||
|
||||
subtag = tag.getPrivateuse();
|
||||
if (subtag.length() > 0) {
|
||||
if (!subtag.isEmpty()) {
|
||||
if (buf.length() > 0) {
|
||||
buf.append(LanguageTag.SEP);
|
||||
}
|
||||
|
@ -1684,7 +1684,7 @@ public final class Locale implements Cloneable, Serializable {
|
|||
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 @@ public final class Locale implements Cloneable, Serializable {
|
|||
* @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 @@ public final class Locale implements Cloneable, Serializable {
|
|||
// 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 @@ public final class Locale implements Cloneable, Serializable {
|
|||
}
|
||||
}
|
||||
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 @@ public final class Locale implements Cloneable, Serializable {
|
|||
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 @@ public final class Locale implements Cloneable, Serializable {
|
|||
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 final class Locale implements Cloneable, Serializable {
|
|||
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());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue