Tab police (and trailing spaces)

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@923551 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2010-03-16 02:34:00 +00:00
parent 2fdfb4a387
commit 311dc94070
4 changed files with 226 additions and 226 deletions

View File

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -18,44 +18,44 @@ package org.apache.commons.lang3;
/** /**
* Null-safe CharSequence utility methods. * Null-safe CharSequence utility methods.
* *
* @author Gary Gregory * @author Gary Gregory
*/ */
public class CharSequenceUtils { public class CharSequenceUtils {
/** /**
* Gets a CharSequence length or <code>0</code> if the CharSequence is * Gets a CharSequence length or <code>0</code> if the CharSequence is
* <code>null</code>. * <code>null</code>.
* *
* @param cs * @param cs
* a CharSequence or <code>null</code> * a CharSequence or <code>null</code>
* @return CharSequence length or <code>0</code> if the CharSequence is * @return CharSequence length or <code>0</code> if the CharSequence is
* <code>null</code>. * <code>null</code>.
* @since 3.0 * @since 3.0
*/ */
public static int length(CharSequence cs) { public static int length(CharSequence cs) {
return cs == null ? 0 : cs.length(); return cs == null ? 0 : cs.length();
} }
/** /**
* Returns a new <code>CharSequence</code> that is a subsequence of this * Returns a new <code>CharSequence</code> that is a subsequence of this
* sequence starting with the <code>char</code> value at the specified * sequence starting with the <code>char</code> value at the specified
* index. The length (in <code>char</code>s) of the returned sequence is * index. The length (in <code>char</code>s) of the returned sequence is
* <code>length() - start</code>, so if <code>start == end</code> then an * <code>length() - start</code>, so if <code>start == end</code> then an
* empty sequence is returned. </p> * empty sequence is returned. </p>
* *
* @param cs * @param cs
* the specified subsequence, may be null * the specified subsequence, may be null
* @param start * @param start
* the start index, inclusive * the start index, inclusive
* @return a new subsequence or null * @return a new subsequence or null
* *
* @throws IndexOutOfBoundsException * @throws IndexOutOfBoundsException
* if <code>start</code> is negative or if <code>start</code> is * if <code>start</code> is negative or if <code>start</code> is
* greater than <code>length()</code> * greater than <code>length()</code>
* @since 3.0 * @since 3.0
*/ */
public static CharSequence subSequence(CharSequence cs, int start) { public static CharSequence subSequence(CharSequence cs, int start) {
return cs == null ? null : cs.subSequence(start, cs.length()); return cs == null ? null : cs.subSequence(start, cs.length());
} }
} }

View File

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -620,7 +620,7 @@ public class StringUtils {
* StringUtils.stripAccents("control") = "control" * StringUtils.stripAccents("control") = "control"
* StringUtils.stripAccents("&ecute;clair") = "eclair" * StringUtils.stripAccents("&ecute;clair") = "eclair"
* </pre> * </pre>
* *
* @param input String to be stripped * @param input String to be stripped
* @return String without accents on the text * @return String without accents on the text
* *
@ -1482,12 +1482,12 @@ public class StringUtils {
* <p> * <p>
* Checks if the CharSequence contains any character in the given set of characters. * Checks if the CharSequence contains any character in the given set of characters.
* </p> * </p>
* *
* <p> * <p>
* A <code>null</code> CharSequence will return <code>false</code>. A <code>null</code> search CharSequence will return * A <code>null</code> CharSequence will return <code>false</code>. A <code>null</code> search CharSequence will return
* <code>false</code>. * <code>false</code>.
* </p> * </p>
* *
* <pre> * <pre>
* StringUtils.containsAny(null, *) = false * StringUtils.containsAny(null, *) = false
* StringUtils.containsAny("", *) = false * StringUtils.containsAny("", *) = false
@ -1497,7 +1497,7 @@ 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 cs * @param cs
* the CharSequence to check, may be null * the CharSequence to check, may be null
* @param searchChars * @param searchChars
@ -2362,7 +2362,7 @@ public class StringUtils {
} }
if (list.isEmpty()) { if (list.isEmpty()) {
return null; return null;
} }
return list.toArray(new String [list.size()]); return list.toArray(new String [list.size()]);
} }
@ -2622,8 +2622,8 @@ 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, int max, private static String[] splitByWholeSeparatorWorker(String str, String separator, int max,
boolean preserveAllTokens) boolean preserveAllTokens)
{ {
if (str == null) { if (str == null) {
return null; return null;
@ -2692,7 +2692,7 @@ public class StringUtils {
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
/** /**
* <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
* adjacent separators. This is an alternative to using StringTokenizer. * adjacent separators. This is an alternative to using StringTokenizer.
* Whitespace is defined by {@link Character#isWhitespace(char)}.</p> * Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
* *
@ -2755,7 +2755,7 @@ public class StringUtils {
} }
/** /**
* Performs the logic for the <code>split</code> and * Performs the logic for the <code>split</code> and
* <code>splitPreserveAllTokens</code> methods that do not return a * <code>splitPreserveAllTokens</code> methods that do not return a
* maximum array length. * maximum array length.
* *
@ -2801,7 +2801,7 @@ public class StringUtils {
} }
/** /**
* <p>Splits the provided text into an array, separators specified, * <p>Splits the provided text into an array, separators specified,
* preserving all tokens, including empty tokens created by adjacent * preserving all tokens, including empty tokens created by adjacent
* separators. This is an alternative to using StringTokenizer.</p> * separators. This is an alternative to using StringTokenizer.</p>
* *
@ -2839,7 +2839,7 @@ public class StringUtils {
/** /**
* <p>Splits the provided text into an array with a maximum length, * <p>Splits the provided text into an array with a maximum length,
* separators specified, preserving all tokens, including empty tokens * separators specified, preserving all tokens, including empty tokens
* created by adjacent separators.</p> * created by adjacent separators.</p>
* *
* <p>The separator is not included in the returned String array. * <p>The separator is not included in the returned String array.
@ -2878,8 +2878,8 @@ public class StringUtils {
} }
/** /**
* Performs the logic for the <code>split</code> and * Performs the logic for the <code>split</code> and
* <code>splitPreserveAllTokens</code> methods that return a maximum array * <code>splitPreserveAllTokens</code> methods that return a maximum array
* length. * length.
* *
* @param str the String to parse, may be <code>null</code> * @param str the String to parse, may be <code>null</code>
@ -2979,7 +2979,7 @@ public class StringUtils {
/** /**
* <p>Splits a String by Character type as returned by * <p>Splits a String by Character type as returned by
* <code>java.lang.Character.getType(char)</code>. Groups of contiguous * <code>java.lang.Character.getType(char)</code>. Groups of contiguous
* characters of the same type are returned as complete tokens. * characters of the same type are returned as complete tokens.
* <pre> * <pre>
* StringUtils.splitByCharacterType(null) = null * StringUtils.splitByCharacterType(null) = null
* StringUtils.splitByCharacterType("") = [] * StringUtils.splitByCharacterType("") = []
@ -3007,7 +3007,7 @@ public class StringUtils {
* <code>Character.UPPERCASE_LETTER</code>, if any, immediately * <code>Character.UPPERCASE_LETTER</code>, if any, immediately
* preceding a token of type <code>Character.LOWERCASE_LETTER</code> * preceding a token of type <code>Character.LOWERCASE_LETTER</code>
* will belong to the following token rather than to the preceding, if any, * will belong to the following token rather than to the preceding, if any,
* <code>Character.UPPERCASE_LETTER</code> token. * <code>Character.UPPERCASE_LETTER</code> token.
* <pre> * <pre>
* StringUtils.splitByCharacterTypeCamelCase(null) = null * StringUtils.splitByCharacterTypeCamelCase(null) = null
* StringUtils.splitByCharacterTypeCamelCase("") = [] * StringUtils.splitByCharacterTypeCamelCase("") = []
@ -3035,7 +3035,7 @@ public class StringUtils {
* the character of type <code>Character.UPPERCASE_LETTER</code>, if any, * the character of type <code>Character.UPPERCASE_LETTER</code>, if any,
* immediately preceding a token of type <code>Character.LOWERCASE_LETTER</code> * immediately preceding a token of type <code>Character.LOWERCASE_LETTER</code>
* will belong to the following token rather than to the preceding, if any, * will belong to the following token rather than to the preceding, if any,
* <code>Character.UPPERCASE_LETTER</code> token. * <code>Character.UPPERCASE_LETTER</code> token.
* @param str the String to split, may be <code>null</code> * @param str the String to split, may be <code>null</code>
* @param camelCase whether to use so-called "camel-case" for letter types * @param camelCase whether to use so-called "camel-case" for letter types
* @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
@ -3751,14 +3751,14 @@ public class StringUtils {
* <p> * <p>
* Replaces all occurrences of Strings within another String. * Replaces all occurrences of Strings within another String.
* </p> * </p>
* *
* <p> * <p>
* A <code>null</code> reference passed to this method is a no-op, or if * A <code>null</code> reference passed to this method is a no-op, or if
* any "search string" or "string to replace" is null, that replace will be * any "search string" or "string to replace" is null, that replace will be
* ignored. This will not repeat. For repeating replaces, call the * ignored. This will not repeat. For repeating replaces, call the
* overloaded method. * overloaded method.
* </p> * </p>
* *
* <pre> * <pre>
* StringUtils.replaceEach(null, *, *) = null * StringUtils.replaceEach(null, *, *) = null
* StringUtils.replaceEach("", *, *) = "" * StringUtils.replaceEach("", *, *) = ""
@ -3772,7 +3772,7 @@ public class StringUtils {
* (example of how it does not repeat) * (example of how it does not repeat)
* StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"}) = "dcte" * StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"}) = "dcte"
* </pre> * </pre>
* *
* @param text * @param text
* text to search and replace in, no-op if null * text to search and replace in, no-op if null
* @param searchList * @param searchList
@ -3794,14 +3794,14 @@ public class StringUtils {
* <p> * <p>
* Replaces all occurrences of Strings within another String. * Replaces all occurrences of Strings within another String.
* </p> * </p>
* *
* <p> * <p>
* A <code>null</code> reference passed to this method is a no-op, or if * A <code>null</code> reference passed to this method is a no-op, or if
* any "search string" or "string to replace" is null, that replace will be * any "search string" or "string to replace" is null, that replace will be
* ignored. This will not repeat. For repeating replaces, call the * ignored. This will not repeat. For repeating replaces, call the
* overloaded method. * overloaded method.
* </p> * </p>
* *
* <pre> * <pre>
* StringUtils.replaceEach(null, *, *, *) = null * StringUtils.replaceEach(null, *, *, *) = null
* StringUtils.replaceEach("", *, *, *) = "" * StringUtils.replaceEach("", *, *, *) = ""
@ -3818,7 +3818,7 @@ public class StringUtils {
* StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "ab"}, true) = IllegalArgumentException * StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "ab"}, true) = IllegalArgumentException
* StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "ab"}, false) = "dcabe" * StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "ab"}, false) = "dcabe"
* </pre> * </pre>
* *
* @param text * @param text
* text to search and replace in, no-op if null * text to search and replace in, no-op if null
* @param searchList * @param searchList
@ -3846,13 +3846,13 @@ public class StringUtils {
* <p> * <p>
* Replaces all occurrences of Strings within another String. * Replaces all occurrences of Strings within another String.
* </p> * </p>
* *
* <p> * <p>
* A <code>null</code> reference passed to this method is a no-op, or if * A <code>null</code> reference passed to this method is a no-op, or if
* any "search string" or "string to replace" is null, that replace will be * any "search string" or "string to replace" is null, that replace will be
* ignored. * ignored.
* </p> * </p>
* *
* <pre> * <pre>
* StringUtils.replaceEach(null, *, *, *) = null * StringUtils.replaceEach(null, *, *, *) = null
* StringUtils.replaceEach("", *, *, *) = "" * StringUtils.replaceEach("", *, *, *) = ""
@ -3868,14 +3868,14 @@ public class StringUtils {
* StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"}, true) = "tcte" * StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"}, true) = "tcte"
* StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "ab"}, *) = IllegalArgumentException * StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "ab"}, *) = IllegalArgumentException
* </pre> * </pre>
* *
* @param text * @param text
* text to search and replace in, no-op if null * text to search and replace in, no-op if null
* @param searchList * @param searchList
* the Strings to search for, no-op if null * the Strings to search for, no-op if null
* @param replacementList * @param replacementList
* the Strings to replace them with, no-op if null * the Strings to replace them with, no-op if null
* @param repeat if true, then replace repeatedly * @param repeat if true, then replace repeatedly
* until there are no more possible replacements or timeToLive < 0 * until there are no more possible replacements or timeToLive < 0
* @param timeToLive * @param timeToLive
* if less than 0 then there is a circular reference and endless * if less than 0 then there is a circular reference and endless
@ -3890,15 +3890,15 @@ public class StringUtils {
* and/or size 0) * and/or size 0)
* @since 2.4 * @since 2.4
*/ */
private static String replaceEach(String text, String[] searchList, String[] replacementList, private static String replaceEach(String text, String[] searchList, String[] replacementList,
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 || searchList == null || if (text == null || text.length() == 0 || searchList == null ||
searchList.length == 0 || replacementList == null || replacementList.length == 0) searchList.length == 0 || replacementList == null || replacementList.length == 0)
{ {
return text; return text;
} }
@ -3930,8 +3930,8 @@ public class StringUtils {
// index of replace array that will replace the search string found // index of replace array that will replace the search string found
// 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].length() == 0 || replacementList[i] == null)
{ {
continue; continue;
} }
@ -3989,8 +3989,8 @@ public class StringUtils {
// find the next earliest match // find the next earliest match
// 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].length() == 0 || replacementList[i] == null)
{ {
continue; continue;
} }
@ -4422,7 +4422,7 @@ public class StringUtils {
* <a href="http://www.unicode.org/glossary/#supplementary_character">Unicode Supplementary Characters</a> * <a href="http://www.unicode.org/glossary/#supplementary_character">Unicode Supplementary Characters</a>
* as they require a pair of <code>char</code>s to be represented. * as they require a pair of <code>char</code>s to be represented.
* If you are needing to support full I18N of your applications * If you are needing to support full I18N of your applications
* consider using {@link #repeat(String, int)} instead. * consider using {@link #repeat(String, int)} instead.
* </p> * </p>
* *
* @param repeat number of times to repeat delim * @param repeat number of times to repeat delim
@ -4666,21 +4666,21 @@ public class StringUtils {
} }
} }
/** /**
* Gets a CharSequence length or <code>0</code> if the CharSequence is * Gets a CharSequence length or <code>0</code> if the CharSequence is
* <code>null</code>. * <code>null</code>.
* *
* @param cs * @param cs
* a CharSequence or <code>null</code> * a CharSequence or <code>null</code>
* @return CharSequence length or <code>0</code> if the CharSequence is * @return CharSequence length or <code>0</code> if the CharSequence is
* <code>null</code>. * <code>null</code>.
* @since 2.4 * @since 2.4
* @deprecated See {@link CharSequenceUtils#length(CharSequence)} * @deprecated See {@link CharSequenceUtils#length(CharSequence)}
*/ */
public static int length(CharSequence cs) { public static int length(CharSequence cs) {
return CharSequenceUtils.length(cs); return CharSequenceUtils.length(cs);
} }
// Centering // Centering
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
@ -5178,10 +5178,10 @@ public class StringUtils {
/** /**
* <p>Checks if the CharSequence contains only ASCII printable characters.</p> * <p>Checks if the CharSequence contains only ASCII printable characters.</p>
* *
* <p><code>null</code> will return <code>false</code>. * <p><code>null</code> will return <code>false</code>.
* An empty CharSequence (length()=0) will return <code>true</code>.</p> * An empty CharSequence (length()=0) will return <code>true</code>.</p>
* *
* <pre> * <pre>
* StringUtils.isAsciiPrintable(null) = false * StringUtils.isAsciiPrintable(null) = false
* StringUtils.isAsciiPrintable("") = true * StringUtils.isAsciiPrintable("") = true
@ -5462,7 +5462,7 @@ public class StringUtils {
if (str == null) { if (str == null) {
return null; return null;
} }
return new StringBuilder(str).reverse().toString(); return new StringBuilder(str).reverse().toString();
} }
/** /**
@ -5585,7 +5585,7 @@ public class StringUtils {
offset = str.length() - (maxWidth - 3); offset = str.length() - (maxWidth - 3);
} }
final String abrevMarker = "..."; final String abrevMarker = "...";
if (offset <= 4) { if (offset <= 4) {
return str.substring(0, maxWidth - 3) + abrevMarker; return str.substring(0, maxWidth - 3) + abrevMarker;
} }
if (maxWidth < 7) { if (maxWidth < 7) {
@ -5596,7 +5596,7 @@ public class StringUtils {
} }
return abrevMarker + str.substring(str.length() - (maxWidth - 3)); return abrevMarker + str.substring(str.length() - (maxWidth - 3));
} }
/** /**
* <p>Abbreviates a String to the length passed, replacing the middle characters with the supplied * <p>Abbreviates a String to the length passed, replacing the middle characters with the supplied
* replacement String.</p> * replacement String.</p>
@ -5630,7 +5630,7 @@ public class StringUtils {
if (isEmpty(str) || isEmpty(middle)) { if (isEmpty(str) || isEmpty(middle)) {
return str; return str;
} }
if (length >= str.length() || length < (middle.length()+2)) { if (length >= str.length() || length < (middle.length()+2)) {
return str; return str;
} }
@ -5638,12 +5638,12 @@ public class StringUtils {
int targetSting = length-middle.length(); int targetSting = length-middle.length();
int startOffset = targetSting/2+targetSting%2; int startOffset = targetSting/2+targetSting%2;
int endOffset = str.length()-targetSting/2; int endOffset = str.length()-targetSting/2;
StringBuilder builder = new StringBuilder(length); StringBuilder builder = new StringBuilder(length);
builder.append(str.substring(0,startOffset)); builder.append(str.substring(0,startOffset));
builder.append(middle); builder.append(middle);
builder.append(str.substring(endOffset)); builder.append(str.substring(endOffset));
return builder.toString(); return builder.toString();
} }
@ -5818,9 +5818,9 @@ public class StringUtils {
} }
return firstDiff; return firstDiff;
} }
/** /**
* <p>Compares all Strings in an array and returns the initial sequence of * <p>Compares all Strings in an array and returns the initial sequence of
* characters that is common to all of them.</p> * characters that is common to all of them.</p>
* *
* <p>For example, * <p>For example,
@ -5848,8 +5848,8 @@ public class StringUtils {
* *
* @param strs array of String objects, entries may be null * @param strs array of String objects, entries may be null
* @return the initial sequence of characters that are common to all Strings * @return the initial sequence of characters that are common to all Strings
* in the array; empty String if the array is null, the elements are all null * in the array; empty String if the array is null, the elements are all null
* or if there is no common prefix. * or if there is no common prefix.
* @since 2.4 * @since 2.4
*/ */
public static String getCommonPrefix(String[] strs) { public static String getCommonPrefix(String[] strs) {
@ -5870,8 +5870,8 @@ public class StringUtils {
// 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);
} }
} }
// Misc // Misc
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
@ -5914,19 +5914,19 @@ public class StringUtils {
} }
/* /*
The difference between this impl. and the previous is that, rather The difference between this impl. and the previous is that, rather
than creating and retaining a matrix of size s.length()+1 by t.length()+1, than creating and retaining a matrix of size s.length()+1 by t.length()+1,
we maintain two single-dimensional arrays of length s.length()+1. The first, d, we maintain two single-dimensional arrays of length s.length()+1. The first, d,
is the 'current working' distance array that maintains the newest distance cost is the 'current working' distance array that maintains the newest distance cost
counts as we iterate through the characters of String s. Each time we increment counts as we iterate through the characters of String s. Each time we increment
the index of String t we are comparing, d is copied to p, the second int[]. Doing so the index of String t we are comparing, d is copied to p, the second int[]. Doing so
allows us to retain the previous cost counts as required by the algorithm (taking allows us to retain the previous cost counts as required by the algorithm (taking
the minimum of the cost count to the left, up one, and diagonally up and to the left the minimum of the cost count to the left, up one, and diagonally up and to the left
of the current cost count being calculated). (Note that the arrays aren't really of the current cost count being calculated). (Note that the arrays aren't really
copied anymore, just switched...this is clearly much better than cloning an array copied anymore, just switched...this is clearly much better than cloning an array
or doing a System.arraycopy() each time through the outer loop.) or doing a System.arraycopy() each time through the outer loop.)
Effectively, the difference between the two implementations is this one does not Effectively, the difference between the two implementations is this one does not
cause an out of memory condition when calculating the LD over two very large strings. cause an out of memory condition when calculating the LD over two very large strings.
*/ */
@ -5941,7 +5941,7 @@ public class StringUtils {
if (n > m) { if (n > m) {
// swap the input strings to consume less memory // swap the input strings to consume less memory
CharSequence tmp = s; CharSequence tmp = s;
s = t; s = t;
t = tmp; t = tmp;
n = m; n = m;
@ -5980,7 +5980,7 @@ public class StringUtils {
d = _d; d = _d;
} }
// our last action in the above loop was to switch d and p, so p now // our last action in the above loop was to switch d and p, so p now
// actually has the most recent cost counts // actually has the most recent cost counts
return p[n]; return p[n];
} }
@ -6079,10 +6079,10 @@ public class StringUtils {
} }
return str.regionMatches(ignoreCase, 0, prefix, 0, prefix.length()); return str.regionMatches(ignoreCase, 0, prefix, 0, prefix.length());
} }
/** /**
* <p>Check if a String starts with any of an array of specified strings.</p> * <p>Check if a String starts with any of an array of specified strings.</p>
* *
* <pre> * <pre>
* StringUtils.startsWithAny(null, null) = false * StringUtils.startsWithAny(null, null) = false
* StringUtils.startsWithAny(null, new String[] {"abc"}) = false * StringUtils.startsWithAny(null, new String[] {"abc"}) = false

View File

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -23,70 +23,70 @@ import junit.framework.TestCase;
/** /**
* Tests CharSequenceUtils * Tests CharSequenceUtils
* *
* @author Gary Gregory * @author Gary Gregory
*/ */
public class CharSequenceUtilsTest extends TestCase { public class CharSequenceUtilsTest extends TestCase {
public void testLength_CharBuffer() { public void testLength_CharBuffer() {
Assert.assertEquals(0, CharSequenceUtils.length(CharBuffer.wrap(""))); Assert.assertEquals(0, CharSequenceUtils.length(CharBuffer.wrap("")));
Assert.assertEquals(1, CharSequenceUtils.length(CharBuffer.wrap("A"))); Assert.assertEquals(1, CharSequenceUtils.length(CharBuffer.wrap("A")));
Assert.assertEquals(1, CharSequenceUtils.length(CharBuffer.wrap(" "))); Assert.assertEquals(1, CharSequenceUtils.length(CharBuffer.wrap(" ")));
Assert.assertEquals(8, CharSequenceUtils.length(CharBuffer.wrap("ABCDEFGH"))); Assert.assertEquals(8, CharSequenceUtils.length(CharBuffer.wrap("ABCDEFGH")));
} }
public void testLength_String() { public void testLength_String() {
Assert.assertEquals(0, CharSequenceUtils.length(null)); Assert.assertEquals(0, CharSequenceUtils.length(null));
Assert.assertEquals(0, CharSequenceUtils.length("")); Assert.assertEquals(0, CharSequenceUtils.length(""));
Assert.assertEquals(1, CharSequenceUtils.length("A")); Assert.assertEquals(1, CharSequenceUtils.length("A"));
Assert.assertEquals(1, CharSequenceUtils.length(" ")); Assert.assertEquals(1, CharSequenceUtils.length(" "));
Assert.assertEquals(8, CharSequenceUtils.length("ABCDEFGH")); Assert.assertEquals(8, CharSequenceUtils.length("ABCDEFGH"));
} }
public void testLength_StringBuffer() { public void testLength_StringBuffer() {
Assert.assertEquals(0, CharSequenceUtils.length(new StringBuffer(""))); Assert.assertEquals(0, CharSequenceUtils.length(new StringBuffer("")));
Assert.assertEquals(1, CharSequenceUtils.length(new StringBuffer("A"))); Assert.assertEquals(1, CharSequenceUtils.length(new StringBuffer("A")));
Assert.assertEquals(1, CharSequenceUtils.length(new StringBuffer(" "))); Assert.assertEquals(1, CharSequenceUtils.length(new StringBuffer(" ")));
Assert.assertEquals(8, CharSequenceUtils.length(new StringBuffer("ABCDEFGH"))); Assert.assertEquals(8, CharSequenceUtils.length(new StringBuffer("ABCDEFGH")));
} }
public void testLength_StringBuilder() { public void testLength_StringBuilder() {
Assert.assertEquals(0, CharSequenceUtils.length(new StringBuilder(""))); Assert.assertEquals(0, CharSequenceUtils.length(new StringBuilder("")));
Assert.assertEquals(1, CharSequenceUtils.length(new StringBuilder("A"))); Assert.assertEquals(1, CharSequenceUtils.length(new StringBuilder("A")));
Assert.assertEquals(1, CharSequenceUtils.length(new StringBuilder(" "))); Assert.assertEquals(1, CharSequenceUtils.length(new StringBuilder(" ")));
Assert.assertEquals(8, CharSequenceUtils.length(new StringBuilder("ABCDEFGH"))); Assert.assertEquals(8, CharSequenceUtils.length(new StringBuilder("ABCDEFGH")));
} }
public void testSubSequence() { public void testSubSequence() {
// //
// null input // null input
// //
Assert.assertEquals(null, CharSequenceUtils.subSequence(null, -1)); Assert.assertEquals(null, CharSequenceUtils.subSequence(null, -1));
Assert.assertEquals(null, CharSequenceUtils.subSequence(null, 0)); Assert.assertEquals(null, CharSequenceUtils.subSequence(null, 0));
Assert.assertEquals(null, CharSequenceUtils.subSequence(null, 1)); Assert.assertEquals(null, CharSequenceUtils.subSequence(null, 1));
// //
// non-null input // non-null input
// //
Assert.assertEquals(StringUtils.EMPTY, CharSequenceUtils.subSequence(StringUtils.EMPTY, 0)); Assert.assertEquals(StringUtils.EMPTY, CharSequenceUtils.subSequence(StringUtils.EMPTY, 0));
Assert.assertEquals("012", CharSequenceUtils.subSequence("012", 0)); Assert.assertEquals("012", CharSequenceUtils.subSequence("012", 0));
Assert.assertEquals("12", CharSequenceUtils.subSequence("012", 1)); Assert.assertEquals("12", CharSequenceUtils.subSequence("012", 1));
Assert.assertEquals("2", CharSequenceUtils.subSequence("012", 2)); Assert.assertEquals("2", CharSequenceUtils.subSequence("012", 2));
Assert.assertEquals(StringUtils.EMPTY, CharSequenceUtils.subSequence("012", 3)); Assert.assertEquals(StringUtils.EMPTY, CharSequenceUtils.subSequence("012", 3));
// //
// Exception expected // Exception expected
// //
try { try {
Assert.assertEquals(null, CharSequenceUtils.subSequence(StringUtils.EMPTY, -1)); Assert.assertEquals(null, CharSequenceUtils.subSequence(StringUtils.EMPTY, -1));
Assert.fail("Expected " + IndexOutOfBoundsException.class.getName()); Assert.fail("Expected " + IndexOutOfBoundsException.class.getName());
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
// Expected // Expected
} }
try { try {
Assert.assertEquals(null, CharSequenceUtils.subSequence(StringUtils.EMPTY, 1)); Assert.assertEquals(null, CharSequenceUtils.subSequence(StringUtils.EMPTY, 1));
Assert.fail("Expected " + IndexOutOfBoundsException.class.getName()); Assert.fail("Expected " + IndexOutOfBoundsException.class.getName());
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
// Expected // Expected
} }
} }
} }

View File

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -36,16 +36,16 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
*/ */
private static final String CharU20000 = "\uD840\uDC00"; private static final String CharU20000 = "\uD840\uDC00";
/** /**
* Supplementary character U+20001 * Supplementary character U+20001
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/ * See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
*/ */
private static final String CharU20001 = "\uD840\uDC01"; private static final String CharU20001 = "\uD840\uDC01";
/** /**
* Incomplete supplementary character U+20000, high surrogate only. * Incomplete supplementary character U+20000, high surrogate only.
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/ * See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
*/ */
private static final String CharUSuppCharHigh = "\uDC00"; private static final String CharUSuppCharHigh = "\uDC00";
/** /**
* Incomplete supplementary character U+20000, low surrogate only. * Incomplete supplementary character U+20000, low surrogate only.
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/ * See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
@ -56,8 +56,8 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
private static final String FOOBAR = "foobar"; private static final String FOOBAR = "foobar";
private static final String[] FOOBAR_SUB_ARRAY = new String[] {"ob", "ba"}; private static final String[] FOOBAR_SUB_ARRAY = new String[] {"ob", "ba"};
public StringUtilsEqualsIndexOfTest(String name) { public StringUtilsEqualsIndexOfTest(String name) {
super(name); super(name);
} }
@ -164,14 +164,14 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
assertFalse(StringUtils.containsAny(null, (String) null)); assertFalse(StringUtils.containsAny(null, (String) null));
assertFalse(StringUtils.containsAny(null, "")); assertFalse(StringUtils.containsAny(null, ""));
assertFalse(StringUtils.containsAny(null, "ab")); assertFalse(StringUtils.containsAny(null, "ab"));
assertFalse(StringUtils.containsAny("", (String) null)); assertFalse(StringUtils.containsAny("", (String) null));
assertFalse(StringUtils.containsAny("", "")); assertFalse(StringUtils.containsAny("", ""));
assertFalse(StringUtils.containsAny("", "ab")); assertFalse(StringUtils.containsAny("", "ab"));
assertFalse(StringUtils.containsAny("zzabyycdxx", (String) null)); assertFalse(StringUtils.containsAny("zzabyycdxx", (String) null));
assertFalse(StringUtils.containsAny("zzabyycdxx", "")); assertFalse(StringUtils.containsAny("zzabyycdxx", ""));
assertTrue(StringUtils.containsAny("zzabyycdxx", "za")); assertTrue(StringUtils.containsAny("zzabyycdxx", "za"));
assertTrue(StringUtils.containsAny("zzabyycdxx", "by")); assertTrue(StringUtils.containsAny("zzabyycdxx", "by"));
assertFalse(StringUtils.containsAny("ab", "z")); assertFalse(StringUtils.containsAny("ab", "z"));
} }
@ -210,7 +210,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
Locale[] locales = { Locale.ENGLISH, new Locale("tr"), Locale.getDefault() }; Locale[] locales = { Locale.ENGLISH, new Locale("tr"), Locale.getDefault() };
String[][] tdata = { String[][] tdata = {
{ "i", "I" }, { "i", "I" },
{ "I", "i" }, { "I", "i" },
{ "\u03C2", "\u03C3" }, { "\u03C2", "\u03C3" },
@ -218,7 +218,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
{ "\u03A3", "\u03C3" }, { "\u03A3", "\u03C3" },
}; };
String[][] fdata = { String[][] fdata = {
{ "\u00DF", "SS" }, { "\u00DF", "SS" },
}; };
@ -241,16 +241,16 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
public void testContainsIgnoreCase_StringString() { public void testContainsIgnoreCase_StringString() {
assertFalse(StringUtils.containsIgnoreCase(null, null)); assertFalse(StringUtils.containsIgnoreCase(null, null));
// Null tests // Null tests
assertFalse(StringUtils.containsIgnoreCase(null, "")); assertFalse(StringUtils.containsIgnoreCase(null, ""));
assertFalse(StringUtils.containsIgnoreCase(null, "a")); assertFalse(StringUtils.containsIgnoreCase(null, "a"));
assertFalse(StringUtils.containsIgnoreCase(null, "abc")); assertFalse(StringUtils.containsIgnoreCase(null, "abc"));
assertFalse(StringUtils.containsIgnoreCase("", null)); assertFalse(StringUtils.containsIgnoreCase("", null));
assertFalse(StringUtils.containsIgnoreCase("a", null)); assertFalse(StringUtils.containsIgnoreCase("a", null));
assertFalse(StringUtils.containsIgnoreCase("abc", null)); assertFalse(StringUtils.containsIgnoreCase("abc", null));
// Match len = 0 // Match len = 0
assertTrue(StringUtils.containsIgnoreCase("", "")); assertTrue(StringUtils.containsIgnoreCase("", ""));
assertTrue(StringUtils.containsIgnoreCase("a", "")); assertTrue(StringUtils.containsIgnoreCase("a", ""));
@ -263,7 +263,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
assertFalse(StringUtils.containsIgnoreCase("", "A")); assertFalse(StringUtils.containsIgnoreCase("", "A"));
assertTrue(StringUtils.containsIgnoreCase("a", "A")); assertTrue(StringUtils.containsIgnoreCase("a", "A"));
assertTrue(StringUtils.containsIgnoreCase("abc", "A")); assertTrue(StringUtils.containsIgnoreCase("abc", "A"));
// Match len > 1 // Match len > 1
assertFalse(StringUtils.containsIgnoreCase("", "abc")); assertFalse(StringUtils.containsIgnoreCase("", "abc"));
assertFalse(StringUtils.containsIgnoreCase("a", "abc")); assertFalse(StringUtils.containsIgnoreCase("a", "abc"));
@ -363,7 +363,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
assertEquals(-1, CharU20001.indexOf(CharUSuppCharHigh)); assertEquals(-1, CharU20001.indexOf(CharUSuppCharHigh));
assertEquals(true, StringUtils.containsNone(CharU20001, CharUSuppCharHigh)); assertEquals(true, StringUtils.containsNone(CharU20001, CharUSuppCharHigh));
assertEquals(0, CharU20001.indexOf(CharUSuppCharLow)); assertEquals(0, CharU20001.indexOf(CharUSuppCharLow));
assertEquals(false, StringUtils.containsNone(CharU20001, CharUSuppCharLow)); assertEquals(false, StringUtils.containsNone(CharU20001, CharUSuppCharLow));
} }
/** /**
@ -501,21 +501,21 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
assertEquals(5, StringUtils.indexOf("aabaabaa", "b", 3)); assertEquals(5, StringUtils.indexOf("aabaabaa", "b", 3));
assertEquals(-1, StringUtils.indexOf("aabaabaa", "b", 9)); assertEquals(-1, StringUtils.indexOf("aabaabaa", "b", 9));
assertEquals(2, StringUtils.indexOf("aabaabaa", "b", -1)); assertEquals(2, StringUtils.indexOf("aabaabaa", "b", -1));
assertEquals(2,StringUtils.indexOf("aabaabaa", "", 2)); assertEquals(2,StringUtils.indexOf("aabaabaa", "", 2));
} }
public void testIndexOfAny_StringCharArray() { public void testIndexOfAny_StringCharArray() {
assertEquals(-1, StringUtils.indexOfAny(null, (char[]) null)); assertEquals(-1, StringUtils.indexOfAny(null, (char[]) null));
assertEquals(-1, StringUtils.indexOfAny(null, new char[0])); assertEquals(-1, StringUtils.indexOfAny(null, new char[0]));
assertEquals(-1, StringUtils.indexOfAny(null, new char[] {'a','b'})); assertEquals(-1, StringUtils.indexOfAny(null, new char[] {'a','b'}));
assertEquals(-1, StringUtils.indexOfAny("", (char[]) null)); assertEquals(-1, StringUtils.indexOfAny("", (char[]) null));
assertEquals(-1, StringUtils.indexOfAny("", new char[0])); assertEquals(-1, StringUtils.indexOfAny("", new char[0]));
assertEquals(-1, StringUtils.indexOfAny("", new char[] {'a','b'})); assertEquals(-1, StringUtils.indexOfAny("", new char[] {'a','b'}));
assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", (char[]) null)); assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", (char[]) null));
assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", new char[0])); assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", new char[0]));
assertEquals(0, StringUtils.indexOfAny("zzabyycdxx", new char[] {'z','a'})); assertEquals(0, StringUtils.indexOfAny("zzabyycdxx", new char[] {'z','a'}));
assertEquals(3, StringUtils.indexOfAny("zzabyycdxx", new char[] {'b','y'})); assertEquals(3, StringUtils.indexOfAny("zzabyycdxx", new char[] {'b','y'}));
assertEquals(-1, StringUtils.indexOfAny("ab", new char[] {'z'})); assertEquals(-1, StringUtils.indexOfAny("ab", new char[] {'z'}));
} }
@ -527,21 +527,21 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
assertEquals(0, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20000.toCharArray())); assertEquals(0, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20000.toCharArray()));
assertEquals(2, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20001.toCharArray())); assertEquals(2, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20001.toCharArray()));
assertEquals(0, StringUtils.indexOfAny(CharU20000, CharU20000.toCharArray())); assertEquals(0, StringUtils.indexOfAny(CharU20000, CharU20000.toCharArray()));
assertEquals(-1, StringUtils.indexOfAny(CharU20000, CharU20001.toCharArray())); assertEquals(-1, StringUtils.indexOfAny(CharU20000, CharU20001.toCharArray()));
} }
public void testIndexOfAny_StringString() { public void testIndexOfAny_StringString() {
assertEquals(-1, StringUtils.indexOfAny(null, (String) null)); assertEquals(-1, StringUtils.indexOfAny(null, (String) null));
assertEquals(-1, StringUtils.indexOfAny(null, "")); assertEquals(-1, StringUtils.indexOfAny(null, ""));
assertEquals(-1, StringUtils.indexOfAny(null, "ab")); assertEquals(-1, StringUtils.indexOfAny(null, "ab"));
assertEquals(-1, StringUtils.indexOfAny("", (String) null)); assertEquals(-1, StringUtils.indexOfAny("", (String) null));
assertEquals(-1, StringUtils.indexOfAny("", "")); assertEquals(-1, StringUtils.indexOfAny("", ""));
assertEquals(-1, StringUtils.indexOfAny("", "ab")); assertEquals(-1, StringUtils.indexOfAny("", "ab"));
assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", (String) null)); assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", (String) null));
assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", "")); assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", ""));
assertEquals(0, StringUtils.indexOfAny("zzabyycdxx", "za")); assertEquals(0, StringUtils.indexOfAny("zzabyycdxx", "za"));
assertEquals(3, StringUtils.indexOfAny("zzabyycdxx", "by")); assertEquals(3, StringUtils.indexOfAny("zzabyycdxx", "by"));
assertEquals(-1, StringUtils.indexOfAny("ab", "z")); assertEquals(-1, StringUtils.indexOfAny("ab", "z"));
} }
@ -570,53 +570,53 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
assertEquals(0, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20000)); assertEquals(0, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20000));
assertEquals(2, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20001)); assertEquals(2, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20001));
assertEquals(0, StringUtils.indexOfAny(CharU20000, CharU20000)); assertEquals(0, StringUtils.indexOfAny(CharU20000, CharU20000));
assertEquals(-1, StringUtils.indexOfAny(CharU20000, CharU20001)); assertEquals(-1, StringUtils.indexOfAny(CharU20000, CharU20001));
} }
public void testIndexOfAnyBut_StringCharArray() { public void testIndexOfAnyBut_StringCharArray() {
assertEquals(-1, StringUtils.indexOfAnyBut(null, (char[]) null)); assertEquals(-1, StringUtils.indexOfAnyBut(null, (char[]) null));
assertEquals(-1, StringUtils.indexOfAnyBut(null, new char[0])); assertEquals(-1, StringUtils.indexOfAnyBut(null, new char[0]));
assertEquals(-1, StringUtils.indexOfAnyBut(null, new char[] {'a','b'})); assertEquals(-1, StringUtils.indexOfAnyBut(null, new char[] {'a','b'}));
assertEquals(-1, StringUtils.indexOfAnyBut("", (char[]) null)); assertEquals(-1, StringUtils.indexOfAnyBut("", (char[]) null));
assertEquals(-1, StringUtils.indexOfAnyBut("", new char[0])); assertEquals(-1, StringUtils.indexOfAnyBut("", new char[0]));
assertEquals(-1, StringUtils.indexOfAnyBut("", new char[] {'a','b'})); assertEquals(-1, StringUtils.indexOfAnyBut("", new char[] {'a','b'}));
assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", (char[]) null)); assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", (char[]) null));
assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", new char[0])); assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", new char[0]));
assertEquals(3, StringUtils.indexOfAnyBut("zzabyycdxx", new char[] {'z','a'})); assertEquals(3, StringUtils.indexOfAnyBut("zzabyycdxx", new char[] {'z','a'}));
assertEquals(0, StringUtils.indexOfAnyBut("zzabyycdxx", new char[] {'b','y'})); assertEquals(0, StringUtils.indexOfAnyBut("zzabyycdxx", new char[] {'b','y'}));
assertEquals(0, StringUtils.indexOfAnyBut("ab", new char[] {'z'})); assertEquals(0, StringUtils.indexOfAnyBut("ab", new char[] {'z'}));
} }
public void testIndexOfAnyBut_StringCharArrayWithSupplementaryChars() { public void testIndexOfAnyBut_StringCharArrayWithSupplementaryChars() {
assertEquals(2, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20000.toCharArray())); assertEquals(2, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20000.toCharArray()));
assertEquals(0, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20001.toCharArray())); assertEquals(0, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20001.toCharArray()));
assertEquals(-1, StringUtils.indexOfAnyBut(CharU20000, CharU20000.toCharArray())); assertEquals(-1, StringUtils.indexOfAnyBut(CharU20000, CharU20000.toCharArray()));
assertEquals(0, StringUtils.indexOfAnyBut(CharU20000, CharU20001.toCharArray())); assertEquals(0, StringUtils.indexOfAnyBut(CharU20000, CharU20001.toCharArray()));
} }
public void testIndexOfAnyBut_StringString() { public void testIndexOfAnyBut_StringString() {
assertEquals(-1, StringUtils.indexOfAnyBut(null, (String) null)); assertEquals(-1, StringUtils.indexOfAnyBut(null, (String) null));
assertEquals(-1, StringUtils.indexOfAnyBut(null, "")); assertEquals(-1, StringUtils.indexOfAnyBut(null, ""));
assertEquals(-1, StringUtils.indexOfAnyBut(null, "ab")); assertEquals(-1, StringUtils.indexOfAnyBut(null, "ab"));
assertEquals(-1, StringUtils.indexOfAnyBut("", (String) null)); assertEquals(-1, StringUtils.indexOfAnyBut("", (String) null));
assertEquals(-1, StringUtils.indexOfAnyBut("", "")); assertEquals(-1, StringUtils.indexOfAnyBut("", ""));
assertEquals(-1, StringUtils.indexOfAnyBut("", "ab")); assertEquals(-1, StringUtils.indexOfAnyBut("", "ab"));
assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", (String) null)); assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", (String) null));
assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", "")); assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", ""));
assertEquals(3, StringUtils.indexOfAnyBut("zzabyycdxx", "za")); assertEquals(3, StringUtils.indexOfAnyBut("zzabyycdxx", "za"));
assertEquals(0, StringUtils.indexOfAnyBut("zzabyycdxx", "by")); assertEquals(0, StringUtils.indexOfAnyBut("zzabyycdxx", "by"));
assertEquals(0, StringUtils.indexOfAnyBut("ab", "z")); assertEquals(0, StringUtils.indexOfAnyBut("ab", "z"));
} }
public void testIndexOfAnyBut_StringStringWithSupplementaryChars() { public void testIndexOfAnyBut_StringStringWithSupplementaryChars() {
assertEquals(2, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20000)); assertEquals(2, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20000));
assertEquals(0, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20001)); assertEquals(0, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20001));
assertEquals(-1, StringUtils.indexOfAnyBut(CharU20000, CharU20000)); assertEquals(-1, StringUtils.indexOfAnyBut(CharU20000, CharU20000));
assertEquals(0, StringUtils.indexOfAnyBut(CharU20000, CharU20001)); assertEquals(0, StringUtils.indexOfAnyBut(CharU20000, CharU20001));
} }
public void testIndexOfIgnoreCase_String() { public void testIndexOfIgnoreCase_String() {
@ -738,7 +738,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
assertEquals(0, StringUtils.lastIndexOfIgnoreCase("aab", "AAB")); assertEquals(0, StringUtils.lastIndexOfIgnoreCase("aab", "AAB"));
} }
public void testLastIndexOfIgnoreCase_StringInt() { public void testLastIndexOfIgnoreCase_StringInt() {
assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, null, 0)); assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, null, 0));
assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, null, -1)); assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, null, -1));
assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, "", 0)); assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, "", 0));
@ -761,7 +761,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
assertEquals(0, StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A", 0)); assertEquals(0, StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A", 0));
assertEquals(1, StringUtils.lastIndexOfIgnoreCase("aab", "AB", 1)); assertEquals(1, StringUtils.lastIndexOfIgnoreCase("aab", "AB", 1));
} }
public void testLastOrdinalIndexOf() { public void testLastOrdinalIndexOf() {
assertEquals(-1, StringUtils.lastOrdinalIndexOf(null, "*", 42) ); assertEquals(-1, StringUtils.lastOrdinalIndexOf(null, "*", 42) );
assertEquals(-1, StringUtils.lastOrdinalIndexOf("*", null, 42) ); assertEquals(-1, StringUtils.lastOrdinalIndexOf("*", null, 42) );
@ -784,7 +784,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "b", Integer.MIN_VALUE)); assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "b", Integer.MIN_VALUE));
assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "ab", Integer.MIN_VALUE)); assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "ab", Integer.MIN_VALUE));
assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "", Integer.MIN_VALUE)); assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "", Integer.MIN_VALUE));
assertEquals(-1, StringUtils.ordinalIndexOf(null, null, -1)); assertEquals(-1, StringUtils.ordinalIndexOf(null, null, -1));
assertEquals(-1, StringUtils.ordinalIndexOf("", null, -1)); assertEquals(-1, StringUtils.ordinalIndexOf("", null, -1));
assertEquals(-1, StringUtils.ordinalIndexOf("", "", -1)); assertEquals(-1, StringUtils.ordinalIndexOf("", "", -1));
@ -816,7 +816,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
assertEquals(5, StringUtils.ordinalIndexOf("aabaabaa", "b", 2)); assertEquals(5, StringUtils.ordinalIndexOf("aabaabaa", "b", 2));
assertEquals(4, StringUtils.ordinalIndexOf("aabaabaa", "ab", 2)); assertEquals(4, StringUtils.ordinalIndexOf("aabaabaa", "ab", 2));
assertEquals(0, StringUtils.ordinalIndexOf("aabaabaa", "", 2)); assertEquals(0, StringUtils.ordinalIndexOf("aabaabaa", "", 2));
assertEquals(-1, StringUtils.ordinalIndexOf(null, null, Integer.MAX_VALUE)); assertEquals(-1, StringUtils.ordinalIndexOf(null, null, Integer.MAX_VALUE));
assertEquals(-1, StringUtils.ordinalIndexOf("", null, Integer.MAX_VALUE)); assertEquals(-1, StringUtils.ordinalIndexOf("", null, Integer.MAX_VALUE));
assertEquals(0, StringUtils.ordinalIndexOf("", "", Integer.MAX_VALUE)); assertEquals(0, StringUtils.ordinalIndexOf("", "", Integer.MAX_VALUE));
@ -824,7 +824,7 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "b", Integer.MAX_VALUE)); assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "b", Integer.MAX_VALUE));
assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "ab", Integer.MAX_VALUE)); assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "ab", Integer.MAX_VALUE));
assertEquals(0, StringUtils.ordinalIndexOf("aabaabaa", "", Integer.MAX_VALUE)); assertEquals(0, StringUtils.ordinalIndexOf("aabaabaa", "", Integer.MAX_VALUE));
assertEquals(-1, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 0)); assertEquals(-1, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 0));
assertEquals(0, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 1)); assertEquals(0, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 1));
assertEquals(1, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 2)); assertEquals(1, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 2));