Return-Path:
Delivered-To: apmail-commons-commits-archive@minotaur.apache.org
Received: (qmail 89420 invoked from network); 8 Mar 2010 22:23:18 -0000
Received: from unknown (HELO mail.apache.org) (140.211.11.3)
by 140.211.11.9 with SMTP; 8 Mar 2010 22:23:18 -0000
Received: (qmail 33962 invoked by uid 500); 8 Mar 2010 22:22:53 -0000
Delivered-To: apmail-commons-commits-archive@commons.apache.org
Received: (qmail 33880 invoked by uid 500); 8 Mar 2010 22:22:53 -0000
Mailing-List: contact commits-help@commons.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: dev@commons.apache.org
Delivered-To: mailing list commits@commons.apache.org
Received: (qmail 33873 invoked by uid 99); 8 Mar 2010 22:22:53 -0000
Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136)
by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Mar 2010 22:22:53 +0000
X-ASF-Spam-Status: No, hits=-2000.0 required=10.0
tests=ALL_TRUSTED
X-Spam-Check-By: apache.org
Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4)
by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Mar 2010 22:22:52 +0000
Received: by eris.apache.org (Postfix, from userid 65534)
id 88A5023889DD; Mon, 8 Mar 2010 22:22:31 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r920546 -
/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java
Date: Mon, 08 Mar 2010 22:22:31 -0000
To: commits@commons.apache.org
From: ggregory@apache.org
X-Mailer: svnmailer-1.0.8
Message-Id: <20100308222231.88A5023889DD@eris.apache.org>
Author: ggregory
Date: Mon Mar 8 22:22:31 2010
New Revision: 920546
URL: http://svn.apache.org/viewvc?rev=920546&view=rev
Log:
Use INDEX_NOT_FOUND instead of magic number.
Modified:
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java
Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java?rev=920546&r1=920545&r2=920546&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java Mon Mar 8 22:22:31 2010
@@ -497,7 +497,7 @@
} else if (stripChars.length() == 0) {
return str;
} else {
- while ((start != strLen) && (stripChars.indexOf(str.charAt(start)) != -1)) {
+ while ((start != strLen) && (stripChars.indexOf(str.charAt(start)) != INDEX_NOT_FOUND)) {
start++;
}
}
@@ -541,7 +541,7 @@
} else if (stripChars.length() == 0) {
return str;
} else {
- while ((end != 0) && (stripChars.indexOf(str.charAt(end - 1)) != -1)) {
+ while ((end != 0) && (stripChars.indexOf(str.charAt(end - 1)) != INDEX_NOT_FOUND)) {
end--;
}
}
@@ -731,7 +731,7 @@
* Finds the first index within a String, handling null
.
* This method uses {@link String#indexOf(int)}.
*
- * A null
or empty ("") String will return -1
.
+ * A null
or empty ("") String will return INDEX_NOT_FOUND (-1)
.
*
*
* StringUtils.indexOf(null, *) = -1
@@ -748,7 +748,7 @@
*/
public static int indexOf(String str, char searchChar) {
if (isEmpty(str)) {
- return -1;
+ return INDEX_NOT_FOUND;
}
return str.indexOf(searchChar);
}
@@ -758,7 +758,7 @@
* handling null
.
* This method uses {@link String#indexOf(int, int)}.
*
- * A null
or empty ("") String will return -1
.
+ *
A null
or empty ("") String will return (INDEX_NOT_FOUND) -1
.
* A negative start position is treated as zero.
* A start position greater than the string length returns -1
.
*
@@ -780,7 +780,7 @@
*/
public static int indexOf(String str, char searchChar, int startPos) {
if (isEmpty(str)) {
- return -1;
+ return INDEX_NOT_FOUND;
}
return str.indexOf(searchChar, startPos);
}
@@ -810,7 +810,7 @@
*/
public static int indexOf(String str, String searchStr) {
if (str == null || searchStr == null) {
- return -1;
+ return INDEX_NOT_FOUND;
}
return str.indexOf(searchStr);
}
@@ -849,7 +849,7 @@
*/
public static int indexOf(String str, String searchStr, int startPos) {
if (str == null || searchStr == null) {
- return -1;
+ return INDEX_NOT_FOUND;
}
return str.indexOf(searchStr, startPos);
}
@@ -989,14 +989,14 @@
*/
public static int indexOfIgnoreCase(String str, String searchStr, int startPos) {
if (str == null || searchStr == null) {
- return -1;
+ return INDEX_NOT_FOUND;
}
if (startPos < 0) {
startPos = 0;
}
int endLimit = (str.length() - searchStr.length()) + 1;
if (startPos > endLimit) {
- return -1;
+ return INDEX_NOT_FOUND;
}
if (searchStr.length() == 0) {
return startPos;
@@ -1006,7 +1006,7 @@
return i;
}
}
- return -1;
+ return INDEX_NOT_FOUND;
}
// LastIndexOf
@@ -1032,7 +1032,7 @@
*/
public static int lastIndexOf(String str, char searchChar) {
if (isEmpty(str)) {
- return -1;
+ return INDEX_NOT_FOUND;
}
return str.lastIndexOf(searchChar);
}
@@ -1066,7 +1066,7 @@
*/
public static int lastIndexOf(String str, char searchChar, int startPos) {
if (isEmpty(str)) {
- return -1;
+ return INDEX_NOT_FOUND;
}
return str.lastIndexOf(searchChar, startPos);
}
@@ -1095,7 +1095,7 @@
*/
public static int lastIndexOf(String str, String searchStr) {
if (str == null || searchStr == null) {
- return -1;
+ return INDEX_NOT_FOUND;
}
return str.lastIndexOf(searchStr);
}
@@ -1167,7 +1167,7 @@
*/
public static int lastIndexOf(String str, String searchStr, int startPos) {
if (str == null || searchStr == null) {
- return -1;
+ return INDEX_NOT_FOUND;
}
return str.lastIndexOf(searchStr, startPos);
}
@@ -1196,7 +1196,7 @@
*/
public static int lastIndexOfIgnoreCase(String str, String searchStr) {
if (str == null || searchStr == null) {
- return -1;
+ return INDEX_NOT_FOUND;
}
return lastIndexOfIgnoreCase(str, searchStr, str.length());
}
@@ -1231,13 +1231,13 @@
*/
public static int lastIndexOfIgnoreCase(String str, String searchStr, int startPos) {
if (str == null || searchStr == null) {
- return -1;
+ return INDEX_NOT_FOUND;
}
if (startPos > (str.length() - searchStr.length())) {
startPos = str.length() - searchStr.length();
}
if (startPos < 0) {
- return -1;
+ return INDEX_NOT_FOUND;
}
if (searchStr.length() == 0) {
return startPos;
@@ -1248,7 +1248,7 @@
return i;
}
}
- return -1;
+ return INDEX_NOT_FOUND;
}
// Contains
@@ -1370,7 +1370,7 @@
*/
public static int indexOfAny(CharSequence cs, char[] searchChars) {
if (isEmpty(cs) || ArrayUtils.isEmpty(searchChars)) {
- return -1;
+ return INDEX_NOT_FOUND;
}
for (int i = 0; i < cs.length(); i++) {
char ch = cs.charAt(i);
@@ -1380,7 +1380,7 @@
}
}
}
- return -1;
+ return INDEX_NOT_FOUND;
}
/**
@@ -1407,7 +1407,7 @@
*/
public static int indexOfAny(CharSequence cs, String searchChars) {
if (isEmpty(cs) || isEmpty(searchChars)) {
- return -1;
+ return INDEX_NOT_FOUND;
}
return indexOfAny(cs, searchChars.toCharArray());
}
@@ -1512,7 +1512,7 @@
*/
public static int indexOfAnyBut(CharSequence cs, char[] searchChars) {
if (isEmpty(cs) || ArrayUtils.isEmpty(searchChars)) {
- return -1;
+ return INDEX_NOT_FOUND;
}
outer : for (int i = 0; i < cs.length(); i++) {
char ch = cs.charAt(i);
@@ -1523,7 +1523,7 @@
}
return i;
}
- return -1;
+ return INDEX_NOT_FOUND;
}
/**
@@ -1550,14 +1550,14 @@
*/
public static int indexOfAnyBut(String str, String searchChars) {
if (isEmpty(str) || isEmpty(searchChars)) {
- return -1;
+ return INDEX_NOT_FOUND;
}
for (int i = 0; i < str.length(); i++) {
if (searchChars.indexOf(str.charAt(i)) < 0) {
return i;
}
}
- return -1;
+ return INDEX_NOT_FOUND;
}
// ContainsOnly
@@ -1594,7 +1594,7 @@
if (valid.length == 0) {
return false;
}
- return indexOfAnyBut(cs, valid) == -1;
+ return indexOfAnyBut(cs, valid) == INDEX_NOT_FOUND;
}
/**
@@ -1726,7 +1726,7 @@
*/
public static int indexOfAny(String str, String[] searchStrs) {
if (str == null || searchStrs == null) {
- return -1;
+ return INDEX_NOT_FOUND;
}
int sz = searchStrs.length;
@@ -1740,7 +1740,7 @@
continue;
}
tmp = str.indexOf(search);
- if (tmp == -1) {
+ if (tmp == INDEX_NOT_FOUND) {
continue;
}
@@ -1749,7 +1749,7 @@
}
}
- return (ret == Integer.MAX_VALUE) ? -1 : ret;
+ return (ret == Integer.MAX_VALUE) ? INDEX_NOT_FOUND : ret;
}
/**
@@ -1778,11 +1778,11 @@
* @return the last index of any of the Strings, -1 if no match
*/
public static int lastIndexOfAny(String str, String[] searchStrs) {
- if ((str == null) || (searchStrs == null)) {
- return -1;
+ if (str == null || searchStrs == null) {
+ return INDEX_NOT_FOUND;
}
int sz = searchStrs.length;
- int ret = -1;
+ int ret = INDEX_NOT_FOUND;
int tmp = 0;
for (int i = 0; i < sz; i++) {
String search = searchStrs[i];
@@ -2056,7 +2056,7 @@
return EMPTY;
}
int pos = str.indexOf(separator);
- if (pos == -1) {
+ if (pos == INDEX_NOT_FOUND) {
return str;
}
return str.substring(0, pos);
@@ -2098,7 +2098,7 @@
return EMPTY;
}
int pos = str.indexOf(separator);
- if (pos == -1) {
+ if (pos == INDEX_NOT_FOUND) {
return EMPTY;
}
return str.substring(pos + separator.length());
@@ -2136,7 +2136,7 @@
return str;
}
int pos = str.lastIndexOf(separator);
- if (pos == -1) {
+ if (pos == INDEX_NOT_FOUND) {
return str;
}
return str.substring(0, pos);
@@ -2179,7 +2179,7 @@
return EMPTY;
}
int pos = str.lastIndexOf(separator);
- if (pos == -1 || pos == (str.length() - separator.length())) {
+ if (pos == INDEX_NOT_FOUND || pos == (str.length() - separator.length())) {
return EMPTY;
}
return str.substring(pos + separator.length());
@@ -2244,9 +2244,9 @@
return null;
}
int start = str.indexOf(open);
- if (start != -1) {
+ if (start != INDEX_NOT_FOUND) {
int end = str.indexOf(close, start + open.length());
- if (end != -1) {
+ if (end != INDEX_NOT_FOUND) {
return str.substring(start + open.length(), end);
}
}
@@ -3564,7 +3564,7 @@
* @since 2.1
*/
public static String remove(String str, char remove) {
- if (isEmpty(str) || str.indexOf(remove) == -1) {
+ if (isEmpty(str) || str.indexOf(remove) == INDEX_NOT_FOUND) {
return str;
}
char[] chars = str.toCharArray();
@@ -3667,7 +3667,7 @@
}
int start = 0;
int end = text.indexOf(searchString, start);
- if (end == -1) {
+ if (end == INDEX_NOT_FOUND) {
return text;
}
int replLength = searchString.length();
@@ -3675,7 +3675,7 @@
increase = (increase < 0 ? 0 : increase);
increase *= (max < 0 ? 16 : (max > 64 ? 64 : max));
StringBuilder buf = new StringBuilder(text.length() + increase);
- while (end != -1) {
+ while (end != INDEX_NOT_FOUND) {
buf.append(text.substring(start, end)).append(replacement);
start = end + replLength;
if (--max == 0) {
@@ -4975,7 +4975,7 @@
}
int count = 0;
int idx = 0;
- while ((idx = str.indexOf(sub, idx)) != -1) {
+ while ((idx = str.indexOf(sub, idx)) != INDEX_NOT_FOUND) {
count++;
idx += sub.length();
}
@@ -5621,7 +5621,7 @@
return str1;
}
int at = indexOfDifference(str1, str2);
- if (at == -1) {
+ if (at == INDEX_NOT_FOUND) {
return EMPTY;
}
return str2.substring(at);
@@ -5652,7 +5652,7 @@
*/
public static int indexOfDifference(CharSequence cs1, CharSequence cs2) {
if (cs1 == cs2) {
- return -1;
+ return INDEX_NOT_FOUND;
}
if (cs1 == null || cs2 == null) {
return 0;
@@ -5666,7 +5666,7 @@
if (i < cs2.length() || i < cs1.length()) {
return i;
}
- return -1;
+ return INDEX_NOT_FOUND;
}
/**
@@ -5702,7 +5702,7 @@
*/
public static int indexOfDifference(CharSequence[] css) {
if (css == null || css.length <= 1) {
- return -1;
+ return INDEX_NOT_FOUND;
}
boolean anyStringNull = false;
boolean allStringsNull = true;
@@ -5726,7 +5726,7 @@
// handle lists containing all nulls or all empty strings
if (allStringsNull || (longestStrLen == 0 && !anyStringNull)) {
- return -1;
+ return INDEX_NOT_FOUND;
}
// handle lists containing some nulls or some empty strings
@@ -5796,7 +5796,7 @@
return EMPTY;
}
int smallestIndexOfDiff = indexOfDifference(strs);
- if (smallestIndexOfDiff == -1) {
+ if (smallestIndexOfDiff == INDEX_NOT_FOUND) {
// all strings were identical
if (strs[0] == null) {
return EMPTY;