Use String#isEmpty() instead of String#length() == 0

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1489692 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2013-06-05 03:35:37 +00:00
parent ef9623ef8e
commit c6ad3493e8
3 changed files with 10 additions and 10 deletions

View File

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

View File

@ -423,7 +423,7 @@ public static String stripToNull(String str) {
return null; return null;
} }
str = strip(str, null); str = strip(str, null);
return str.length() == 0 ? null : str; return str.isEmpty() ? null : str;
} }
/** /**
@ -520,7 +520,7 @@ public static String stripStart(final String str, final String stripChars) {
while (start != strLen && Character.isWhitespace(str.charAt(start))) { while (start != strLen && Character.isWhitespace(str.charAt(start))) {
start++; start++;
} }
} else if (stripChars.length() == 0) { } else if (stripChars.isEmpty()) {
return str; return str;
} else { } else {
while (start != strLen && stripChars.indexOf(str.charAt(start)) != INDEX_NOT_FOUND) { while (start != strLen && stripChars.indexOf(str.charAt(start)) != INDEX_NOT_FOUND) {
@ -565,7 +565,7 @@ public static String stripEnd(final String str, final String stripChars) {
while (end != 0 && Character.isWhitespace(str.charAt(end - 1))) { while (end != 0 && Character.isWhitespace(str.charAt(end - 1))) {
end--; end--;
} }
} else if (stripChars.length() == 0) { } else if (stripChars.isEmpty()) {
return str; return str;
} else { } else {
while (end != 0 && stripChars.indexOf(str.charAt(end - 1)) != INDEX_NOT_FOUND) { while (end != 0 && stripChars.indexOf(str.charAt(end - 1)) != INDEX_NOT_FOUND) {
@ -2174,7 +2174,7 @@ public static String substringBefore(final String str, final String separator) {
if (isEmpty(str) || separator == null) { if (isEmpty(str) || separator == null) {
return str; return str;
} }
if (separator.length() == 0) { if (separator.isEmpty()) {
return EMPTY; return EMPTY;
} }
final int pos = str.indexOf(separator); final int pos = str.indexOf(separator);
@ -3106,7 +3106,7 @@ private static String[] splitByCharacterType(final String str, final boolean cam
if (str == null) { if (str == null) {
return null; return null;
} }
if (str.length() == 0) { if (str.isEmpty()) {
return ArrayUtils.EMPTY_STRING_ARRAY; return ArrayUtils.EMPTY_STRING_ARRAY;
} }
final char[] c = str.toCharArray(); final char[] c = str.toCharArray();
@ -4567,7 +4567,7 @@ private static String replaceEach(
// mchyzer Performance note: This creates very few new objects (one major goal) // mchyzer Performance note: This creates very few new objects (one major goal)
// let me know if there are performance requests, we can create a harness to measure // let me know if there are performance requests, we can create a harness to measure
if (text == null || text.length() == 0 || searchList == null || if (text == null || text.isEmpty() || searchList == null ||
searchList.length == 0 || replacementList == null || replacementList.length == 0) { searchList.length == 0 || replacementList == null || replacementList.length == 0) {
return text; return text;
} }
@ -4601,7 +4601,7 @@ private static String replaceEach(
// NOTE: logic duplicated below START // NOTE: logic duplicated below START
for (int i = 0; i < searchLength; i++) { for (int i = 0; i < searchLength; i++) {
if (noMoreMatchesForReplIndex[i] || searchList[i] == null || if (noMoreMatchesForReplIndex[i] || searchList[i] == null ||
searchList[i].length() == 0 || replacementList[i] == null) { searchList[i].isEmpty() || replacementList[i] == null) {
continue; continue;
} }
tempIndex = text.indexOf(searchList[i]); tempIndex = text.indexOf(searchList[i]);
@ -4659,7 +4659,7 @@ private static String replaceEach(
// NOTE: logic mostly duplicated above START // NOTE: logic mostly duplicated above START
for (int i = 0; i < searchLength; i++) { for (int i = 0; i < searchLength; i++) {
if (noMoreMatchesForReplIndex[i] || searchList[i] == null || if (noMoreMatchesForReplIndex[i] || searchList[i] == null ||
searchList[i].length() == 0 || replacementList[i] == null) { searchList[i].isEmpty() || replacementList[i] == null) {
continue; continue;
} }
tempIndex = text.indexOf(searchList[i], start); tempIndex = text.indexOf(searchList[i], start);

View File

@ -170,7 +170,7 @@ public String getNullText() {
* @return this, to enable chaining * @return this, to enable chaining
*/ */
public StrBuilder setNullText(String nullText) { public StrBuilder setNullText(String nullText) {
if (nullText != null && nullText.length() == 0) { if (nullText != null && nullText.isEmpty()) {
nullText = null; nullText = null;
} }
this.nullText = nullText; this.nullText = nullText;