mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +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
|
@ -331,7 +331,7 @@ public final class InternalLocaleBuilder {
|
|||
done.add(key);
|
||||
}
|
||||
}
|
||||
if (privateuse != null && privateuse.length() > 0) {
|
||||
if (privateuse != null && !privateuse.isEmpty()) {
|
||||
// privateuse string contains prefix, e.g. "x-abc-def"
|
||||
if (extensions == null) {
|
||||
extensions = new HashMap<>(1);
|
||||
|
@ -406,19 +406,19 @@ public final class InternalLocaleBuilder {
|
|||
// Validate base locale fields before updating internal state.
|
||||
// LocaleExtensions always store validated/canonicalized values,
|
||||
// so no checks are necessary.
|
||||
if (language.length() > 0 && !LanguageTag.isLanguage(language)) {
|
||||
if (!language.isEmpty() && !LanguageTag.isLanguage(language)) {
|
||||
throw new LocaleSyntaxException("Ill-formed language: " + language);
|
||||
}
|
||||
|
||||
if (script.length() > 0 && !LanguageTag.isScript(script)) {
|
||||
if (!script.isEmpty() && !LanguageTag.isScript(script)) {
|
||||
throw new LocaleSyntaxException("Ill-formed script: " + script);
|
||||
}
|
||||
|
||||
if (region.length() > 0 && !LanguageTag.isRegion(region)) {
|
||||
if (!region.isEmpty() && !LanguageTag.isRegion(region)) {
|
||||
throw new LocaleSyntaxException("Ill-formed region: " + region);
|
||||
}
|
||||
|
||||
if (variant.length() > 0) {
|
||||
if (!variant.isEmpty()) {
|
||||
int errIdx = checkVariants(variant, BaseLocale.SEP);
|
||||
if (errIdx != -1) {
|
||||
throw new LocaleSyntaxException("Ill-formed variant: " + variant, errIdx);
|
||||
|
|
|
@ -212,7 +212,7 @@ public class LanguageTag {
|
|||
if (!itr.isDone() && !sts.isError()) {
|
||||
String s = itr.current();
|
||||
sts.errorIndex = itr.currentStart();
|
||||
if (s.length() == 0) {
|
||||
if (s.isEmpty()) {
|
||||
sts.errorMsg = "Empty subtag";
|
||||
} else {
|
||||
sts.errorMsg = "Invalid subtag: " + s;
|
||||
|
@ -454,7 +454,7 @@ public class LanguageTag {
|
|||
variant = "";
|
||||
}
|
||||
|
||||
if (variant.length() > 0) {
|
||||
if (!variant.isEmpty()) {
|
||||
List<String> variants = null;
|
||||
StringTokenIterator varitr = new StringTokenIterator(variant, BaseLocale.SEP);
|
||||
while (!varitr.isDone()) {
|
||||
|
@ -527,7 +527,7 @@ public class LanguageTag {
|
|||
tag.privateuse = privateuse;
|
||||
}
|
||||
|
||||
if (tag.language.length() == 0 && (hasSubtag || privateuse == null)) {
|
||||
if (tag.language.isEmpty() && (hasSubtag || privateuse == null)) {
|
||||
// use lang "und" when 1) no language is available AND
|
||||
// 2) any of other subtags other than private use are available or
|
||||
// no private use tag is available
|
||||
|
@ -712,18 +712,18 @@ public class LanguageTag {
|
|||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (language.length() > 0) {
|
||||
if (!language.isEmpty()) {
|
||||
sb.append(language);
|
||||
|
||||
for (String extlang : extlangs) {
|
||||
sb.append(SEP).append(extlang);
|
||||
}
|
||||
|
||||
if (script.length() > 0) {
|
||||
if (!script.isEmpty()) {
|
||||
sb.append(SEP).append(script);
|
||||
}
|
||||
|
||||
if (region.length() > 0) {
|
||||
if (!region.isEmpty()) {
|
||||
sb.append(SEP).append(region);
|
||||
}
|
||||
|
||||
|
@ -735,7 +735,7 @@ public class LanguageTag {
|
|||
sb.append(SEP).append(extension);
|
||||
}
|
||||
}
|
||||
if (privateuse.length() > 0) {
|
||||
if (!privateuse.isEmpty()) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(SEP);
|
||||
}
|
||||
|
|
|
@ -402,7 +402,7 @@ public final class LocaleMatcher {
|
|||
}
|
||||
|
||||
String rangeForRegex = range.replace("*", "\\p{Alnum}*");
|
||||
while (rangeForRegex.length() > 0) {
|
||||
while (!rangeForRegex.isEmpty()) {
|
||||
for (String tag : tags) {
|
||||
// change to lowercase for case-insensitive matching
|
||||
String lowerCaseTag = tag.toLowerCase(Locale.ROOT);
|
||||
|
@ -437,7 +437,7 @@ public final class LocaleMatcher {
|
|||
}
|
||||
|
||||
String rangeForRegex = range.replace("*", "\\p{Alnum}*");
|
||||
while (rangeForRegex.length() > 0) {
|
||||
while (!rangeForRegex.isEmpty()) {
|
||||
if (tag.matches(rangeForRegex)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -591,7 +591,7 @@ public final class LocaleMatcher {
|
|||
private static String[] getEquivalentsForLanguage(String range) {
|
||||
String r = range;
|
||||
|
||||
while (r.length() > 0) {
|
||||
while (!r.isEmpty()) {
|
||||
if (LocaleEquivalentMaps.singleEquivMap.containsKey(r)) {
|
||||
String equiv = LocaleEquivalentMaps.singleEquivMap.get(r);
|
||||
// Return immediately for performance if the first matching
|
||||
|
@ -680,7 +680,7 @@ public final class LocaleMatcher {
|
|||
String r = range;
|
||||
boolean hasEquivalent = false;
|
||||
|
||||
while (r.length() > 0) {
|
||||
while (!r.isEmpty()) {
|
||||
if (keyMap.containsKey(r)) {
|
||||
hasEquivalent = true;
|
||||
List<String> equivalents = map.get(keyMap.get(r));
|
||||
|
|
|
@ -207,7 +207,7 @@ public final class LocaleUtils {
|
|||
}
|
||||
|
||||
static boolean isEmpty(String str) {
|
||||
return str == null || str.length() == 0;
|
||||
return str == null || str.isEmpty();
|
||||
}
|
||||
|
||||
static boolean isEmpty(Set<?> set) {
|
||||
|
|
|
@ -80,7 +80,7 @@ public class UnicodeLocaleExtension extends Extension {
|
|||
String value = keyword.getValue();
|
||||
|
||||
sj.add(key);
|
||||
if (value.length() > 0) {
|
||||
if (!value.isEmpty()) {
|
||||
sj.add(value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av
|
|||
}
|
||||
name = strings[value];
|
||||
// If name is empty in standalone, try its `format' style.
|
||||
if (name.length() == 0
|
||||
if (name.isEmpty()
|
||||
&& (style == SHORT_STANDALONE || style == LONG_STANDALONE
|
||||
|| style == NARROW_STANDALONE)) {
|
||||
name = getDisplayName(calendarType, field, value,
|
||||
|
@ -183,7 +183,7 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av
|
|||
String name = strings[i];
|
||||
// Ignore any empty string (some standalone month names
|
||||
// are not defined)
|
||||
if (name.length() == 0) {
|
||||
if (name.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
map.put(name, base + i);
|
||||
|
|
|
@ -503,7 +503,7 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter implements R
|
|||
*/
|
||||
String supportedLocaleString = createSupportedLocaleString("AvailableLocales");
|
||||
|
||||
if (supportedLocaleString.length() == 0) {
|
||||
if (supportedLocaleString.isEmpty()) {
|
||||
throw new InternalError("No available locales for JRE");
|
||||
}
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ public abstract class LocaleProviderAdapter {
|
|||
List<Type> typeList = new ArrayList<>();
|
||||
|
||||
// Check user specified adapter preference
|
||||
if (order != null && order.length() != 0) {
|
||||
if (order != null && !order.isEmpty()) {
|
||||
String[] types = order.split(",");
|
||||
for (String type : types) {
|
||||
type = type.trim().toUpperCase(Locale.ROOT);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue