From 11fc6950e92aee644fa1d7f6e88a9ee4184f8c74 Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Wed, 6 Feb 2008 20:21:57 +0000 Subject: [PATCH] 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 --- .../org/apache/commons/lang/StringUtils.java | 152 +++++++++--------- 1 file changed, 74 insertions(+), 78 deletions(-) diff --git a/src/java/org/apache/commons/lang/StringUtils.java b/src/java/org/apache/commons/lang/StringUtils.java index 413a5dbfe..63b1a032e 100644 --- a/src/java/org/apache/commons/lang/StringUtils.java +++ b/src/java/org/apache/commons/lang/StringUtils.java @@ -1163,8 +1163,7 @@ public class StringUtils { * @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 @@ public class StringUtils { } /** - *

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 @@ public class StringUtils {
      * 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 @@ public class StringUtils { * @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 @@ public class StringUtils { * @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 @@ public class StringUtils { * @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 @@ public class StringUtils { 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 @@ public class StringUtils { 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 @@ public class StringUtils { * @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 @@ public class StringUtils { * 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 @@ public class StringUtils { // 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 @@ public class StringUtils { 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 @@ public class StringUtils { 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 @@ public class StringUtils { 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 @@ public class StringUtils { 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