Format @since 2.4 methods to match the rest of the file. For example, expressions use no spaces around parens.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@619143 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2008-02-06 20:21:57 +00:00
parent 004d7b3e8f
commit 11fc6950e9
1 changed files with 74 additions and 78 deletions

View File

@ -1163,8 +1163,7 @@ public class StringUtils {
* @since 2.4 * @since 2.4
*/ */
public static boolean containsAny(String str, char[] searchChars) { public static boolean containsAny(String str, char[] searchChars) {
if (str == null || str.length() == 0 || if (str == null || str.length() == 0 || searchChars == null || searchChars.length == 0) {
searchChars == null || searchChars.length == 0) {
return false; return false;
} }
for (int i = 0; i < str.length(); i++) { for (int i = 0; i < str.length(); i++) {
@ -1179,12 +1178,15 @@ public class StringUtils {
} }
/** /**
* <p>Checks if the String contains any character in the given * <p>
* set of characters.</p> * Checks if the String contains any character in the given set of characters.
* * </p>
* <p>A <code>null</code> String will return <code>false</code>. *
* A <code>null</code> search string will return <code>false</code>.</p> * <p>
* * A <code>null</code> String will return <code>false</code>. A <code>null</code> search string will return
* <code>false</code>.
* </p>
*
* <pre> * <pre>
* StringUtils.containsAny(null, *) = false * StringUtils.containsAny(null, *) = false
* StringUtils.containsAny("", *) = false * StringUtils.containsAny("", *) = false
@ -1194,11 +1196,12 @@ public class StringUtils {
* StringUtils.containsAny("zzabyycdxx", "by") = true * StringUtils.containsAny("zzabyycdxx", "by") = true
* StringUtils.containsAny("aba","z") = false * StringUtils.containsAny("aba","z") = false
* </pre> * </pre>
* *
* @param str the String to check, may be null * @param str
* @param searchChars the chars to search for, may be null * the String to check, may be null
* @return the <code>true</code> if any of the chars are found, * @param searchChars
* <code>false</code> if no match or null input * the chars to search for, may be null
* @return the <code>true</code> if any of the chars are found, <code>false</code> if no match or null input
* @since 2.4 * @since 2.4
*/ */
public static boolean containsAny(String str, String searchChars) { public static boolean containsAny(String str, String searchChars) {
@ -2283,7 +2286,7 @@ public class StringUtils {
* @since 2.4 * @since 2.4
*/ */
public static String[] splitByWholeSeparatorPreserveAllTokens(String str, String separator) { public static String[] splitByWholeSeparatorPreserveAllTokens(String str, String separator) {
return splitByWholeSeparatorWorker( str, separator, -1, true ) ; return splitByWholeSeparatorWorker(str, separator, -1, true);
} }
/** /**
@ -2315,7 +2318,7 @@ public class StringUtils {
* @return an array of parsed Strings, <code>null</code> if null String was input * @return an array of parsed Strings, <code>null</code> if null String was input
* @since 2.4 * @since 2.4
*/ */
public static String[] splitByWholeSeparatorPreserveAllTokens( String str, String separator, int max ) { public static String[] splitByWholeSeparatorPreserveAllTokens(String str, String separator, int max) {
return splitByWholeSeparatorWorker(str, separator, max, true); return splitByWholeSeparatorWorker(str, separator, max, true);
} }
@ -2333,76 +2336,72 @@ public class StringUtils {
* @return an array of parsed Strings, <code>null</code> if null String input * @return an array of parsed Strings, <code>null</code> if null String input
* @since 2.4 * @since 2.4
*/ */
private static String[] splitByWholeSeparatorWorker( String str, String separator, private static String[] splitByWholeSeparatorWorker(String str, String separator, int max, boolean preserveAllTokens) {
int max, boolean preserveAllTokens )
{
if (str == null) { if (str == null) {
return null; return null;
} }
int len = str.length() ; int len = str.length();
if (len == 0) { if (len == 0) {
return ArrayUtils.EMPTY_STRING_ARRAY; return ArrayUtils.EMPTY_STRING_ARRAY;
} }
if ( ( separator == null ) || ( EMPTY.equals( separator ) ) ) { if ((separator == null) || (EMPTY.equals(separator))) {
// Split on whitespace. // Split on whitespace.
return splitWorker( str, null, max, preserveAllTokens ) ; return splitWorker(str, null, max, preserveAllTokens);
} }
int separatorLength = separator.length();
int separatorLength = separator.length() ; ArrayList substrings = new ArrayList();
int numberOfSubstrings = 0;
int beg = 0;
int end = 0;
while (end < len) {
end = str.indexOf(separator, beg);
ArrayList substrings = new ArrayList() ; if (end > -1) {
int numberOfSubstrings = 0 ; if (end > beg) {
int beg = 0 ; numberOfSubstrings += 1;
int end = 0 ;
while ( end < len ) {
end = str.indexOf( separator, beg ) ;
if ( end > -1 ) { if (numberOfSubstrings == max) {
if ( end > beg ) { end = len;
numberOfSubstrings += 1 ; substrings.add(str.substring(beg));
if ( numberOfSubstrings == max ) {
end = len ;
substrings.add( str.substring( beg ) ) ;
} else { } else {
// The following is OK, because String.substring( beg, end ) excludes // The following is OK, because String.substring( beg, end ) excludes
// the character at the position 'end'. // the character at the position 'end'.
substrings.add( str.substring( beg, end ) ) ; substrings.add(str.substring(beg, end));
// Set the starting point for the next search. // Set the starting point for the next search.
// The following is equivalent to beg = end + (separatorLength - 1) + 1, // The following is equivalent to beg = end + (separatorLength - 1) + 1,
// which is the right calculation: // which is the right calculation:
beg = end + separatorLength ; beg = end + separatorLength;
} }
} else { } else {
// We found a consecutive occurrence of the separator, so skip it. // We found a consecutive occurrence of the separator, so skip it.
if( preserveAllTokens ) { if (preserveAllTokens) {
numberOfSubstrings += 1 ; numberOfSubstrings += 1;
if ( numberOfSubstrings == max ) { if (numberOfSubstrings == max) {
end = len ; end = len;
substrings.add( str.substring( beg ) ) ; substrings.add(str.substring(beg));
} else { } else {
substrings.add( EMPTY ); substrings.add(EMPTY);
} }
} }
beg = end + separatorLength ; beg = end + separatorLength;
} }
} else { } else {
// String.substring( beg ) goes from 'beg' to the end of the String. // String.substring( beg ) goes from 'beg' to the end of the String.
substrings.add( str.substring( beg ) ) ; substrings.add(str.substring(beg));
end = len ; end = len;
} }
} }
return (String[]) substrings.toArray( new String[substrings.size()] ) ; return (String[]) substrings.toArray(new String[substrings.size()]);
} }
// -----------------------------------------------------------------------
//-----------------------------------------------------------------------
/** /**
* <p>Splits the provided text into an array, using whitespace as the * <p>Splits the provided text into an array, using whitespace as the
* separator, preserving all tokens, including empty tokens created by * separator, preserving all tokens, including empty tokens created by
@ -2770,8 +2769,7 @@ public class StringUtils {
if (type == currentType) { if (type == currentType) {
continue; continue;
} }
if (camelCase && type == Character.LOWERCASE_LETTER if (camelCase && type == Character.LOWERCASE_LETTER && currentType == Character.UPPERCASE_LETTER) {
&& currentType == Character.UPPERCASE_LETTER) {
int newTokenStart = pos - 1; int newTokenStart = pos - 1;
if (newTokenStart != tokenStart) { if (newTokenStart != tokenStart) {
list.add(new String(c, tokenStart, newTokenStart - tokenStart)); list.add(new String(c, tokenStart, newTokenStart - tokenStart));
@ -3267,7 +3265,7 @@ public class StringUtils {
if (isEmpty(str) || isEmpty(remove)) { if (isEmpty(str) || isEmpty(remove)) {
return str; return str;
} }
if (startsWithIgnoreCase(str, remove)){ if (startsWithIgnoreCase(str, remove)) {
return str.substring(remove.length()); return str.substring(remove.length());
} }
return str; return str;
@ -3603,7 +3601,6 @@ public class StringUtils {
* @since 2.4 * @since 2.4
*/ */
public static String replaceEachRepeatedly(String text, String[] repl, String[] with) { public static String replaceEachRepeatedly(String text, String[] repl, String[] with) {
// timeToLive should be 0 if not used or nothing to replace, else it's // timeToLive should be 0 if not used or nothing to replace, else it's
// the length of the replace array // the length of the replace array
int timeToLive = repl == null ? 0 : repl.length; int timeToLive = repl == null ? 0 : repl.length;
@ -3656,16 +3653,12 @@ public class StringUtils {
* and/or size 0) * and/or size 0)
* @since 2.4 * @since 2.4
*/ */
private static String replaceEach(String text, String[] repl, String[] with, private static String replaceEach(String text, String[] repl, String[] with, boolean repeat, int timeToLive) {
boolean repeat, int timeToLive) {
// 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 || if (text == null || text.length() == 0 || repl == null || repl.length == 0 || with == null || with.length == 0) {
repl == null || repl.length == 0 ||
with == null || with.length == 0)
{
return text; return text;
} }
@ -3679,7 +3672,10 @@ public class StringUtils {
// make sure lengths are ok, these need to be equal // make sure lengths are ok, these need to be equal
if (replLength != withLength) { if (replLength != withLength) {
throw new IllegalArgumentException("Search and Replace array lengths don't match: " + replLength + " vs " + withLength); throw new IllegalArgumentException("Search and Replace array lengths don't match: "
+ replLength
+ " vs "
+ withLength);
} }
// keep track of which still have matches // keep track of which still have matches
@ -3697,7 +3693,7 @@ public class StringUtils {
continue; continue;
} }
tempIndex = text.indexOf(repl[i]); tempIndex = text.indexOf(repl[i]);
// see if we need to keep searching for this // see if we need to keep searching for this
if (tempIndex == -1) { if (tempIndex == -1) {
noMoreMatchesForReplIndex[i] = true; noMoreMatchesForReplIndex[i] = true;
@ -3721,15 +3717,15 @@ public class StringUtils {
int increase = 0; int increase = 0;
// count the replacement text elements that are larger than their corresponding text being replaced // count the replacement text elements that are larger than their corresponding text being replaced
for (int i=0; i<repl.length; i++) { for (int i = 0; i < repl.length; i++) {
int greater = with[i].length() - repl[i].length(); int greater = with[i].length() - repl[i].length();
if(greater > 0) { if (greater > 0) {
increase += 3 * greater; // assume 3 matches increase += 3 * greater; // assume 3 matches
} }
} }
// have upper-bound at 20% increase, then let Java take over // have upper-bound at 20% increase, then let Java take over
increase = Math.min(increase, text.length() / 5); increase = Math.min(increase, text.length() / 5);
StringBuffer buf = new StringBuffer(text.length() + increase); StringBuffer buf = new StringBuffer(text.length() + increase);
while (textIndex != -1) { while (textIndex != -1) {
@ -3751,8 +3747,8 @@ public class StringUtils {
continue; continue;
} }
tempIndex = text.indexOf(repl[i], start); tempIndex = text.indexOf(repl[i], start);
//see if we need to keep searching for this // see if we need to keep searching for this
if (tempIndex == -1) { if (tempIndex == -1) {
noMoreMatchesForReplIndex[i] = true; noMoreMatchesForReplIndex[i] = true;
} else { } else {
@ -5571,14 +5567,14 @@ public class StringUtils {
int shortestStrLen = Integer.MAX_VALUE; int shortestStrLen = Integer.MAX_VALUE;
int longestStrLen = 0; int longestStrLen = 0;
// find the min and max string lengths; this avoids checking to make // find the min and max string lengths; this avoids checking to make
// sure we are not exceeding the length of the string each time through // sure we are not exceeding the length of the string each time through
// the bottom loop. // the bottom loop.
for (int i=0; i<arrayLen; i++) { for (int i = 0; i < arrayLen; i++) {
if (strs[i] == null) { if (strs[i] == null) {
anyStringNull = true; anyStringNull = true;
shortestStrLen = 0; shortestStrLen = 0;
} else { } else {
allStringsNull = false; allStringsNull = false;
shortestStrLen = Math.min(strs[i].length(), shortestStrLen); shortestStrLen = Math.min(strs[i].length(), shortestStrLen);
longestStrLen = Math.max(strs[i].length(), longestStrLen); longestStrLen = Math.max(strs[i].length(), longestStrLen);
@ -5593,13 +5589,13 @@ public class StringUtils {
// handle lists containing some nulls or some empty strings // handle lists containing some nulls or some empty strings
if (shortestStrLen == 0) { if (shortestStrLen == 0) {
return 0; return 0;
} }
// find the position with the first difference across all strings // find the position with the first difference across all strings
int firstDiff = -1; int firstDiff = -1;
for (int stringPos = 0; stringPos<shortestStrLen; stringPos++) { for (int stringPos = 0; stringPos < shortestStrLen; stringPos++) {
char comparisonChar = strs[0].charAt(stringPos); char comparisonChar = strs[0].charAt(stringPos);
for (int arrayPos = 1; arrayPos<arrayLen; arrayPos++) { for (int arrayPos = 1; arrayPos < arrayLen; arrayPos++) {
if (strs[arrayPos].charAt(stringPos) != comparisonChar) { if (strs[arrayPos].charAt(stringPos) != comparisonChar) {
firstDiff = stringPos; firstDiff = stringPos;
break; break;
@ -5611,8 +5607,8 @@ public class StringUtils {
} }
if (firstDiff == -1 && shortestStrLen != longestStrLen) { if (firstDiff == -1 && shortestStrLen != longestStrLen) {
// we compared all of the characters up to the length of the // we compared all of the characters up to the length of the
// shortest string and didn't find a match, but the string lengths // shortest string and didn't find a match, but the string lengths
// vary, so return the length of the shortest string. // vary, so return the length of the shortest string.
return shortestStrLen; return shortestStrLen;
} }
@ -5667,7 +5663,7 @@ public class StringUtils {
// there were no common initial characters // there were no common initial characters
return EMPTY; return EMPTY;
} else { } else {
// we found a common initial character sequence // we found a common initial character sequence
return strs[0].substring(0, smallestIndexOfDiff); return strs[0].substring(0, smallestIndexOfDiff);
} }
} }