Eat own dog food: StringUtils#isEmpty(String) and replace some but not all String#length() == 0 with String#isEmpty()

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1299411 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2012-03-11 17:55:29 +00:00
parent 36b73ef5d3
commit 204346f754
7 changed files with 15 additions and 17 deletions

View File

@ -143,7 +143,7 @@ public static String keep(String str, String... set) {
return null;
}
if (str.length() == 0 || deepEmpty(set)) {
return "";
return StringUtils.EMPTY;
}
return modify(str, set, true);
}

View File

@ -183,11 +183,8 @@ public static String getShortClassName(Class<?> cls) {
* @param className the className to get the short name for
* @return the class name of the class without the package name or an empty string
*/
public static String getShortClassName(String className) {
if (className == null) {
return StringUtils.EMPTY;
}
if (className.length() == 0) {
public static String getShortClassName(String className) {
if (StringUtils.isEmpty(className)) {
return StringUtils.EMPTY;
}
@ -289,7 +286,7 @@ public static String getPackageName(Class<?> cls) {
* @return the package name or an empty string
*/
public static String getPackageName(String className) {
if (className == null || className.length() == 0) {
if (StringUtils.isEmpty(className)) {
return StringUtils.EMPTY;
}

View File

@ -235,7 +235,7 @@ public static List<Locale> languagesByCountry(String countryCode) {
for (int i = 0; i < locales.size(); i++) {
Locale locale = locales.get(i);
if (countryCode.equals(locale.getCountry()) &&
locale.getVariant().length() == 0) {
locale.getVariant().isEmpty()) {
langs.add(locale);
}
}
@ -268,7 +268,7 @@ public static List<Locale> countriesByLanguage(String languageCode) {
Locale locale = locales.get(i);
if (languageCode.equals(locale.getLanguage()) &&
locale.getCountry().length() != 0 &&
locale.getVariant().length() == 0) {
locale.getVariant().isEmpty()) {
countries.add(locale);
}
}

View File

@ -647,7 +647,7 @@ static List<String> getStackFrameList(Throwable t) {
String token = frames.nextToken();
// Determine if the line starts with <whitespace>at
int at = token.indexOf("at");
if (at != -1 && token.substring(0, at).trim().length() == 0) {
if (at != -1 && token.substring(0, at).trim().isEmpty()) {
traceStarted = true;
list.add(token);
} else if (traceStarted) {

View File

@ -187,7 +187,7 @@ public static StrMatcher charSetMatcher(char... chars) {
* @return a new Matcher for the given characters
*/
public static StrMatcher charSetMatcher(String chars) {
if (chars == null || chars.length() == 0) {
if (StringUtils.isEmpty(chars)) {
return NONE_MATCHER;
}
if (chars.length() == 1) {

View File

@ -23,6 +23,7 @@
import java.util.NoSuchElementException;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
/**
* Tokenizes a string based based on delimiters (separators)
@ -650,7 +651,7 @@ protected List<String> tokenize(char[] chars, int offset, int count) {
* @param tok the token to add
*/
private void addToken(List<String> list, String tok) {
if (tok == null || tok.length() == 0) {
if (StringUtils.isEmpty(tok)) {
if (isIgnoreEmptyTokens()) {
return;
}

View File

@ -86,8 +86,8 @@ private void assertValidToLocale(String language) {
assertNotNull("valid locale", locale);
assertEquals(language, locale.getLanguage());
//country and variant are empty
assertTrue(locale.getCountry() == null || locale.getCountry().length() == 0);
assertTrue(locale.getVariant() == null || locale.getVariant().length() == 0);
assertTrue(locale.getCountry() == null || locale.getCountry().isEmpty());
assertTrue(locale.getVariant() == null || locale.getVariant().isEmpty());
}
/**
@ -103,7 +103,7 @@ private void assertValidToLocale(String localeString, String language, String co
assertEquals(language, locale.getLanguage());
assertEquals(country, locale.getCountry());
//variant is empty
assertTrue(locale.getVariant() == null || locale.getVariant().length() == 0);
assertTrue(locale.getVariant() == null || locale.getVariant().isEmpty());
}
/**
@ -393,7 +393,7 @@ private void assertLanguageByCountry(String country, String[] languages) {
Locale locale = iterator.next();
// should have an en empty variant
assertTrue(locale.getVariant() == null
|| locale.getVariant().length() == 0);
|| locale.getVariant().isEmpty());
assertEquals(country, locale.getCountry());
if (language.equals(locale.getLanguage())) {
found = true;
@ -443,7 +443,7 @@ private void assertCountriesByLanguage(String language, String[] countries) {
Locale locale = iterator.next();
// should have an en empty variant
assertTrue(locale.getVariant() == null
|| locale.getVariant().length() == 0);
|| locale.getVariant().isEmpty());
assertEquals(language, locale.getLanguage());
if (countrie.equals(locale.getCountry())) {
found = true;