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:
parent
36b73ef5d3
commit
204346f754
|
@ -143,7 +143,7 @@ public class CharSetUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (str.length() == 0 || deepEmpty(set)) {
|
if (str.length() == 0 || deepEmpty(set)) {
|
||||||
return "";
|
return StringUtils.EMPTY;
|
||||||
}
|
}
|
||||||
return modify(str, set, true);
|
return modify(str, set, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,10 +184,7 @@ public class ClassUtils {
|
||||||
* @return the class name of the class without the package name or an empty string
|
* @return the class name of the class without the package name or an empty string
|
||||||
*/
|
*/
|
||||||
public static String getShortClassName(String className) {
|
public static String getShortClassName(String className) {
|
||||||
if (className == null) {
|
if (StringUtils.isEmpty(className)) {
|
||||||
return StringUtils.EMPTY;
|
|
||||||
}
|
|
||||||
if (className.length() == 0) {
|
|
||||||
return StringUtils.EMPTY;
|
return StringUtils.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +286,7 @@ public class ClassUtils {
|
||||||
* @return the package name or an empty string
|
* @return the package name or an empty string
|
||||||
*/
|
*/
|
||||||
public static String getPackageName(String className) {
|
public static String getPackageName(String className) {
|
||||||
if (className == null || className.length() == 0) {
|
if (StringUtils.isEmpty(className)) {
|
||||||
return StringUtils.EMPTY;
|
return StringUtils.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -235,7 +235,7 @@ public class LocaleUtils {
|
||||||
for (int i = 0; i < locales.size(); i++) {
|
for (int i = 0; i < locales.size(); i++) {
|
||||||
Locale locale = locales.get(i);
|
Locale locale = locales.get(i);
|
||||||
if (countryCode.equals(locale.getCountry()) &&
|
if (countryCode.equals(locale.getCountry()) &&
|
||||||
locale.getVariant().length() == 0) {
|
locale.getVariant().isEmpty()) {
|
||||||
langs.add(locale);
|
langs.add(locale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,7 @@ public class LocaleUtils {
|
||||||
Locale locale = locales.get(i);
|
Locale locale = locales.get(i);
|
||||||
if (languageCode.equals(locale.getLanguage()) &&
|
if (languageCode.equals(locale.getLanguage()) &&
|
||||||
locale.getCountry().length() != 0 &&
|
locale.getCountry().length() != 0 &&
|
||||||
locale.getVariant().length() == 0) {
|
locale.getVariant().isEmpty()) {
|
||||||
countries.add(locale);
|
countries.add(locale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -647,7 +647,7 @@ public class ExceptionUtils {
|
||||||
String token = frames.nextToken();
|
String token = frames.nextToken();
|
||||||
// Determine if the line starts with <whitespace>at
|
// Determine if the line starts with <whitespace>at
|
||||||
int at = token.indexOf("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;
|
traceStarted = true;
|
||||||
list.add(token);
|
list.add(token);
|
||||||
} else if (traceStarted) {
|
} else if (traceStarted) {
|
||||||
|
|
|
@ -187,7 +187,7 @@ public abstract class StrMatcher {
|
||||||
* @return a new Matcher for the given characters
|
* @return a new Matcher for the given characters
|
||||||
*/
|
*/
|
||||||
public static StrMatcher charSetMatcher(String chars) {
|
public static StrMatcher charSetMatcher(String chars) {
|
||||||
if (chars == null || chars.length() == 0) {
|
if (StringUtils.isEmpty(chars)) {
|
||||||
return NONE_MATCHER;
|
return NONE_MATCHER;
|
||||||
}
|
}
|
||||||
if (chars.length() == 1) {
|
if (chars.length() == 1) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.ListIterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tokenizes a string based based on delimiters (separators)
|
* Tokenizes a string based based on delimiters (separators)
|
||||||
|
@ -650,7 +651,7 @@ public class StrTokenizer implements ListIterator<String>, Cloneable {
|
||||||
* @param tok the token to add
|
* @param tok the token to add
|
||||||
*/
|
*/
|
||||||
private void addToken(List<String> list, String tok) {
|
private void addToken(List<String> list, String tok) {
|
||||||
if (tok == null || tok.length() == 0) {
|
if (StringUtils.isEmpty(tok)) {
|
||||||
if (isIgnoreEmptyTokens()) {
|
if (isIgnoreEmptyTokens()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,8 +86,8 @@ public class LocaleUtilsTest extends TestCase {
|
||||||
assertNotNull("valid locale", locale);
|
assertNotNull("valid locale", locale);
|
||||||
assertEquals(language, locale.getLanguage());
|
assertEquals(language, locale.getLanguage());
|
||||||
//country and variant are empty
|
//country and variant are empty
|
||||||
assertTrue(locale.getCountry() == null || locale.getCountry().length() == 0);
|
assertTrue(locale.getCountry() == null || locale.getCountry().isEmpty());
|
||||||
assertTrue(locale.getVariant() == null || locale.getVariant().length() == 0);
|
assertTrue(locale.getVariant() == null || locale.getVariant().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,7 +103,7 @@ public class LocaleUtilsTest extends TestCase {
|
||||||
assertEquals(language, locale.getLanguage());
|
assertEquals(language, locale.getLanguage());
|
||||||
assertEquals(country, locale.getCountry());
|
assertEquals(country, locale.getCountry());
|
||||||
//variant is empty
|
//variant is empty
|
||||||
assertTrue(locale.getVariant() == null || locale.getVariant().length() == 0);
|
assertTrue(locale.getVariant() == null || locale.getVariant().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -393,7 +393,7 @@ public class LocaleUtilsTest extends TestCase {
|
||||||
Locale locale = iterator.next();
|
Locale locale = iterator.next();
|
||||||
// should have an en empty variant
|
// should have an en empty variant
|
||||||
assertTrue(locale.getVariant() == null
|
assertTrue(locale.getVariant() == null
|
||||||
|| locale.getVariant().length() == 0);
|
|| locale.getVariant().isEmpty());
|
||||||
assertEquals(country, locale.getCountry());
|
assertEquals(country, locale.getCountry());
|
||||||
if (language.equals(locale.getLanguage())) {
|
if (language.equals(locale.getLanguage())) {
|
||||||
found = true;
|
found = true;
|
||||||
|
@ -443,7 +443,7 @@ public class LocaleUtilsTest extends TestCase {
|
||||||
Locale locale = iterator.next();
|
Locale locale = iterator.next();
|
||||||
// should have an en empty variant
|
// should have an en empty variant
|
||||||
assertTrue(locale.getVariant() == null
|
assertTrue(locale.getVariant() == null
|
||||||
|| locale.getVariant().length() == 0);
|
|| locale.getVariant().isEmpty());
|
||||||
assertEquals(language, locale.getLanguage());
|
assertEquals(language, locale.getLanguage());
|
||||||
if (countrie.equals(locale.getCountry())) {
|
if (countrie.equals(locale.getCountry())) {
|
||||||
found = true;
|
found = true;
|
||||||
|
|
Loading…
Reference in New Issue