Return-Path: Delivered-To: apmail-commons-commits-archive@locus.apache.org Received: (qmail 26948 invoked from network); 6 Feb 2008 20:22:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Feb 2008 20:22:21 -0000 Received: (qmail 25496 invoked by uid 500); 6 Feb 2008 20:22:12 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 25439 invoked by uid 500); 6 Feb 2008 20:22:12 -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 25424 invoked by uid 99); 6 Feb 2008 20:22:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Feb 2008 12:22:12 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Feb 2008 20:21:51 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id AB2931A9832; Wed, 6 Feb 2008 12:21:58 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r619143 - /commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java Date: Wed, 06 Feb 2008 20:21:58 -0000 To: commits@commons.apache.org From: ggregory@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080206202158.AB2931A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ggregory Date: Wed Feb 6 12:21:57 2008 New Revision: 619143 URL: http://svn.apache.org/viewvc?rev=619143&view=rev Log: Format @since 2.4 methods to match the rest of the file. For example, expressions use no spaces around parens. Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java?rev=619143&r1=619142&r2=619143&view=diff ============================================================================== --- commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java (original) +++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java Wed Feb 6 12:21:57 2008 @@ -1163,8 +1163,7 @@ * @since 2.4 */ public static boolean containsAny(String str, char[] searchChars) { - if (str == null || str.length() == 0 || - searchChars == null || searchChars.length == 0) { + if (str == null || str.length() == 0 || searchChars == null || searchChars.length == 0) { return false; } for (int i = 0; i < str.length(); i++) { @@ -1179,12 +1178,15 @@ } /** - *

Checks if the String contains any character in the given - * set of characters.

- * - *

A null String will return false. - * A null search string will return false.

- * + *

+ * Checks if the String contains any character in the given set of characters. + *

+ * + *

+ * A null String will return false. A null search string will return + * false. + *

+ * *
      * StringUtils.containsAny(null, *)            = false
      * StringUtils.containsAny("", *)              = false
@@ -1194,11 +1196,12 @@
      * StringUtils.containsAny("zzabyycdxx", "by") = true
      * StringUtils.containsAny("aba","z")          = false
      * 
- * - * @param str the String to check, may be null - * @param searchChars the chars to search for, may be null - * @return the true if any of the chars are found, - * false if no match or null input + * + * @param str + * the String to check, may be null + * @param searchChars + * the chars to search for, may be null + * @return the true if any of the chars are found, false if no match or null input * @since 2.4 */ public static boolean containsAny(String str, String searchChars) { @@ -2283,7 +2286,7 @@ * @since 2.4 */ public static String[] splitByWholeSeparatorPreserveAllTokens(String str, String separator) { - return splitByWholeSeparatorWorker( str, separator, -1, true ) ; + return splitByWholeSeparatorWorker(str, separator, -1, true); } /** @@ -2315,7 +2318,7 @@ * @return an array of parsed Strings, null if null String was input * @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); } @@ -2333,76 +2336,72 @@ * @return an array of parsed Strings, null if null String input * @since 2.4 */ - private static String[] splitByWholeSeparatorWorker( String str, String separator, - int max, boolean preserveAllTokens ) - { + private static String[] splitByWholeSeparatorWorker(String str, String separator, int max, boolean preserveAllTokens) { if (str == null) { return null; } - int len = str.length() ; + int len = str.length(); if (len == 0) { return ArrayUtils.EMPTY_STRING_ARRAY; } - if ( ( separator == null ) || ( EMPTY.equals( separator ) ) ) { + if ((separator == null) || (EMPTY.equals(separator))) { // 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(); + int numberOfSubstrings = 0; + int beg = 0; + int end = 0; + while (end < len) { + end = str.indexOf(separator, beg); - if ( end > -1 ) { - if ( end > beg ) { - numberOfSubstrings += 1 ; + if (end > -1) { + if (end > beg) { + numberOfSubstrings += 1; - if ( numberOfSubstrings == max ) { - end = len ; - substrings.add( str.substring( beg ) ) ; + if (numberOfSubstrings == max) { + end = len; + substrings.add(str.substring(beg)); } else { // The following is OK, because String.substring( beg, end ) excludes // 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. // The following is equivalent to beg = end + (separatorLength - 1) + 1, // which is the right calculation: - beg = end + separatorLength ; + beg = end + separatorLength; } } else { // We found a consecutive occurrence of the separator, so skip it. - if( preserveAllTokens ) { - numberOfSubstrings += 1 ; - if ( numberOfSubstrings == max ) { - end = len ; - substrings.add( str.substring( beg ) ) ; + if (preserveAllTokens) { + numberOfSubstrings += 1; + if (numberOfSubstrings == max) { + end = len; + substrings.add(str.substring(beg)); } else { - substrings.add( EMPTY ); + substrings.add(EMPTY); } } - beg = end + separatorLength ; + beg = end + separatorLength; } } else { // String.substring( beg ) goes from 'beg' to the end of the String. - substrings.add( str.substring( beg ) ) ; - end = len ; + substrings.add(str.substring(beg)); + end = len; } } - return (String[]) substrings.toArray( new String[substrings.size()] ) ; + return (String[]) substrings.toArray(new String[substrings.size()]); } - - //----------------------------------------------------------------------- + // ----------------------------------------------------------------------- /** *

Splits the provided text into an array, using whitespace as the * separator, preserving all tokens, including empty tokens created by @@ -2770,8 +2769,7 @@ if (type == currentType) { continue; } - if (camelCase && type == Character.LOWERCASE_LETTER - && currentType == Character.UPPERCASE_LETTER) { + if (camelCase && type == Character.LOWERCASE_LETTER && currentType == Character.UPPERCASE_LETTER) { int newTokenStart = pos - 1; if (newTokenStart != tokenStart) { list.add(new String(c, tokenStart, newTokenStart - tokenStart)); @@ -3267,7 +3265,7 @@ if (isEmpty(str) || isEmpty(remove)) { return str; } - if (startsWithIgnoreCase(str, remove)){ + if (startsWithIgnoreCase(str, remove)) { return str.substring(remove.length()); } return str; @@ -3603,7 +3601,6 @@ * @since 2.4 */ public static String replaceEachRepeatedly(String text, String[] repl, String[] with) { - // timeToLive should be 0 if not used or nothing to replace, else it's // the length of the replace array int timeToLive = repl == null ? 0 : repl.length; @@ -3656,16 +3653,12 @@ * and/or size 0) * @since 2.4 */ - private static String replaceEach(String text, String[] repl, String[] with, - boolean repeat, int timeToLive) { + private static String replaceEach(String text, String[] repl, String[] with, 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 - - if (text == null || text.length() == 0 || - repl == null || repl.length == 0 || - with == null || with.length == 0) - { + + if (text == null || text.length() == 0 || repl == null || repl.length == 0 || with == null || with.length == 0) { return text; } @@ -3679,7 +3672,10 @@ // make sure lengths are ok, these need to be equal 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 @@ -3697,7 +3693,7 @@ continue; } tempIndex = text.indexOf(repl[i]); - + // see if we need to keep searching for this if (tempIndex == -1) { noMoreMatchesForReplIndex[i] = true; @@ -3721,15 +3717,15 @@ int increase = 0; // count the replacement text elements that are larger than their corresponding text being replaced - for (int i=0; i 0) { + if (greater > 0) { increase += 3 * greater; // assume 3 matches } } // 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); while (textIndex != -1) { @@ -3751,8 +3747,8 @@ continue; } 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) { noMoreMatchesForReplIndex[i] = true; } else { @@ -5571,14 +5567,14 @@ int shortestStrLen = Integer.MAX_VALUE; 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 // the bottom loop. - for (int i=0; i