mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +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
|
@ -2232,7 +2232,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
|
|||
if (strings != null) {
|
||||
Map<String,Integer> names = new HashMap<>();
|
||||
for (int i = 0; i < strings.length; i++) {
|
||||
if (strings[i].length() == 0) {
|
||||
if (strings[i].isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
names.put(strings[i], i);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -771,8 +771,8 @@ public abstract class ResourceBundle {
|
|||
@Override
|
||||
public String toString() {
|
||||
String l = locale.toString();
|
||||
if (l.length() == 0) {
|
||||
if (locale.getVariant().length() != 0) {
|
||||
if (l.isEmpty()) {
|
||||
if (!locale.getVariant().isEmpty()) {
|
||||
l = "__" + locale.getVariant();
|
||||
} else {
|
||||
l = "\"\"";
|
||||
|
@ -2903,7 +2903,7 @@ public abstract class ResourceBundle {
|
|||
List<Locale> bokmalList = new LinkedList<>();
|
||||
for (Locale l : tmpList) {
|
||||
bokmalList.add(l);
|
||||
if (l.getLanguage().length() == 0) {
|
||||
if (l.getLanguage().isEmpty()) {
|
||||
break;
|
||||
}
|
||||
bokmalList.add(Locale.getInstance("no", l.getScript(), l.getCountry(),
|
||||
|
@ -2921,7 +2921,7 @@ public abstract class ResourceBundle {
|
|||
}
|
||||
// Special handling for Chinese
|
||||
else if (language.equals("zh")) {
|
||||
if (script.length() == 0 && region.length() > 0) {
|
||||
if (script.isEmpty() && !region.isEmpty()) {
|
||||
// Supply script for users who want to use zh_Hans/zh_Hant
|
||||
// as bundle names (recommended for Java7+)
|
||||
switch (region) {
|
||||
|
@ -2944,7 +2944,7 @@ public abstract class ResourceBundle {
|
|||
private static List<Locale> getDefaultList(String language, String script, String region, String variant) {
|
||||
List<String> variants = null;
|
||||
|
||||
if (variant.length() > 0) {
|
||||
if (!variant.isEmpty()) {
|
||||
variants = new LinkedList<>();
|
||||
int idx = variant.length();
|
||||
while (idx != -1) {
|
||||
|
@ -2960,14 +2960,14 @@ public abstract class ResourceBundle {
|
|||
list.add(Locale.getInstance(language, script, region, v, null));
|
||||
}
|
||||
}
|
||||
if (region.length() > 0) {
|
||||
if (!region.isEmpty()) {
|
||||
list.add(Locale.getInstance(language, script, region, "", null));
|
||||
}
|
||||
if (script.length() > 0) {
|
||||
if (!script.isEmpty()) {
|
||||
list.add(Locale.getInstance(language, script, "", "", null));
|
||||
// Special handling for Chinese
|
||||
if (language.equals("zh")) {
|
||||
if (region.length() == 0) {
|
||||
if (region.isEmpty()) {
|
||||
// Supply region(country) for users who still package Chinese
|
||||
// bundles using old convension.
|
||||
switch (script) {
|
||||
|
@ -2988,11 +2988,11 @@ public abstract class ResourceBundle {
|
|||
list.add(Locale.getInstance(language, "", region, v, null));
|
||||
}
|
||||
}
|
||||
if (region.length() > 0) {
|
||||
if (!region.isEmpty()) {
|
||||
list.add(Locale.getInstance(language, "", region, "", null));
|
||||
}
|
||||
}
|
||||
if (language.length() > 0) {
|
||||
if (!language.isEmpty()) {
|
||||
list.add(Locale.getInstance(language, "", "", "", null));
|
||||
}
|
||||
// Add root locale at the end
|
||||
|
|
|
@ -1297,16 +1297,16 @@ public final class Scanner implements Iterator<String>, Closeable {
|
|||
nanString = "\\Q" + dfs.getNaN() + "\\E";
|
||||
infinityString = "\\Q" + dfs.getInfinity() + "\\E";
|
||||
positivePrefix = df.getPositivePrefix();
|
||||
if (positivePrefix.length() > 0)
|
||||
if (!positivePrefix.isEmpty())
|
||||
positivePrefix = "\\Q" + positivePrefix + "\\E";
|
||||
negativePrefix = df.getNegativePrefix();
|
||||
if (negativePrefix.length() > 0)
|
||||
if (!negativePrefix.isEmpty())
|
||||
negativePrefix = "\\Q" + negativePrefix + "\\E";
|
||||
positiveSuffix = df.getPositiveSuffix();
|
||||
if (positiveSuffix.length() > 0)
|
||||
if (!positiveSuffix.isEmpty())
|
||||
positiveSuffix = "\\Q" + positiveSuffix + "\\E";
|
||||
negativeSuffix = df.getNegativeSuffix();
|
||||
if (negativeSuffix.length() > 0)
|
||||
if (!negativeSuffix.isEmpty())
|
||||
negativeSuffix = "\\Q" + negativeSuffix + "\\E";
|
||||
|
||||
// Force rebuilding and recompilation of locale dependent
|
||||
|
|
|
@ -1390,7 +1390,7 @@ public final class Pattern
|
|||
localTCNCount = 0;
|
||||
|
||||
// if length > 0, the Pattern is lazily compiled
|
||||
if (pattern.length() == 0) {
|
||||
if (pattern.isEmpty()) {
|
||||
root = new Start(lastAccept);
|
||||
matchRoot = lastAccept;
|
||||
compiled = true;
|
||||
|
@ -1423,7 +1423,7 @@ public final class Pattern
|
|||
localCount = 0;
|
||||
localTCNCount = 0;
|
||||
|
||||
if (pattern.length() > 0) {
|
||||
if (!pattern.isEmpty()) {
|
||||
compile();
|
||||
} else {
|
||||
root = new Start(lastAccept);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue