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 "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -18,44 +18,44 @@
/**
* Null-safe CharSequence utility methods.
*
*
* @author Gary Gregory
*/
public class CharSequenceUtils {
/**
* Gets a CharSequence length or <code>0</code> if the CharSequence is
* <code>null</code>.
*
* @param cs
* a CharSequence or <code>null</code>
* @return CharSequence length or <code>0</code> if the CharSequence is
* <code>null</code>.
* @since 3.0
*/
public static int length(CharSequence cs) {
return cs == null ? 0 : cs.length();
}
/**
* Gets a CharSequence length or <code>0</code> if the CharSequence is
* <code>null</code>.
*
* @param cs
* a CharSequence or <code>null</code>
* @return CharSequence length or <code>0</code> if the CharSequence is
* <code>null</code>.
* @since 3.0
*/
public static int length(CharSequence cs) {
return cs == null ? 0 : cs.length();
}
/**
* Returns a new <code>CharSequence</code> that is a subsequence of this
* sequence starting with the <code>char</code> value at the specified
* 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
* empty sequence is returned. </p>
*
* @param cs
* the specified subsequence, may be null
* @param start
* the start index, inclusive
* @return a new subsequence or null
*
* @throws IndexOutOfBoundsException
* if <code>start</code> is negative or if <code>start</code> is
* greater than <code>length()</code>
* @since 3.0
*/
public static CharSequence subSequence(CharSequence cs, int start) {
return cs == null ? null : cs.subSequence(start, cs.length());
}
/**
* Returns a new <code>CharSequence</code> that is a subsequence of this
* sequence starting with the <code>char</code> value at the specified
* 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
* empty sequence is returned. </p>
*
* @param cs
* the specified subsequence, may be null
* @param start
* the start index, inclusive
* @return a new subsequence or null
*
* @throws IndexOutOfBoundsException
* if <code>start</code> is negative or if <code>start</code> is
* greater than <code>length()</code>
* @since 3.0
*/
public static CharSequence subSequence(CharSequence cs, int start) {
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 "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -620,7 +620,7 @@ public static String[] stripAll(String[] strs, String stripChars) {
* StringUtils.stripAccents("control") = "control"
* StringUtils.stripAccents("&ecute;clair") = "eclair"
* </pre>
*
*
* @param input String to be stripped
* @return String without accents on the text
*
@ -1482,12 +1482,12 @@ public static boolean containsAny(String cs, char[] searchChars) {
* <p>
* Checks if the CharSequence contains any character in the given set of characters.
* </p>
*
*
* <p>
* A <code>null</code> CharSequence will return <code>false</code>. A <code>null</code> search CharSequence will return
* <code>false</code>.
* </p>
*
*
* <pre>
* StringUtils.containsAny(null, *) = false
* StringUtils.containsAny("", *) = false
@ -1497,7 +1497,7 @@ public static boolean containsAny(String cs, char[] searchChars) {
* StringUtils.containsAny("zzabyycdxx", "by") = true
* StringUtils.containsAny("aba","z") = false
* </pre>
*
*
* @param cs
* the CharSequence to check, may be null
* @param searchChars
@ -2362,7 +2362,7 @@ public static String[] substringsBetween(String str, String open, String close)
}
if (list.isEmpty()) {
return null;
}
}
return list.toArray(new String [list.size()]);
}
@ -2622,8 +2622,8 @@ public static String[] splitByWholeSeparatorPreserveAllTokens(String str, String
* @return an array of parsed Strings, <code>null</code> 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;
@ -2692,7 +2692,7 @@ private static String[] splitByWholeSeparatorWorker(String str, String separator
// -----------------------------------------------------------------------
/**
* <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.
* Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
*
@ -2755,7 +2755,7 @@ public static String[] splitPreserveAllTokens(String str, char separatorChar) {
}
/**
* 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
* maximum array length.
*
@ -2801,7 +2801,7 @@ private static String[] splitWorker(String str, char separatorChar, boolean pres
}
/**
* <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
* separators. This is an alternative to using StringTokenizer.</p>
*
@ -2839,7 +2839,7 @@ public static String[] splitPreserveAllTokens(String str, String separatorChars)
/**
* <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>
*
* <p>The separator is not included in the returned String array.
@ -2878,8 +2878,8 @@ public static String[] splitPreserveAllTokens(String str, String separatorChars,
}
/**
* Performs the logic for the <code>split</code> and
* <code>splitPreserveAllTokens</code> methods that return a maximum array
* Performs the logic for the <code>split</code> and
* <code>splitPreserveAllTokens</code> methods that return a maximum array
* length.
*
* @param str the String to parse, may be <code>null</code>
@ -2979,7 +2979,7 @@ private static String[] splitWorker(String str, String separatorChars, int max,
/**
* <p>Splits a String by Character type as returned by
* <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>
* StringUtils.splitByCharacterType(null) = null
* StringUtils.splitByCharacterType("") = []
@ -3007,7 +3007,7 @@ public static String[] splitByCharacterType(String str) {
* <code>Character.UPPERCASE_LETTER</code>, if any, immediately
* preceding a token of type <code>Character.LOWERCASE_LETTER</code>
* 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>
* StringUtils.splitByCharacterTypeCamelCase(null) = null
* StringUtils.splitByCharacterTypeCamelCase("") = []
@ -3035,7 +3035,7 @@ public static String[] splitByCharacterTypeCamelCase(String str) {
* the character of type <code>Character.UPPERCASE_LETTER</code>, if any,
* immediately preceding a token of type <code>Character.LOWERCASE_LETTER</code>
* 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 camelCase whether to use so-called "camel-case" for letter types
* @return an array of parsed Strings, <code>null</code> if null String input
@ -3751,14 +3751,14 @@ public static String replace(String text, String searchString, String replacemen
* <p>
* Replaces all occurrences of Strings within another String.
* </p>
*
*
* <p>
* 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
* ignored. This will not repeat. For repeating replaces, call the
* overloaded method.
* </p>
*
*
* <pre>
* StringUtils.replaceEach(null, *, *) = null
* StringUtils.replaceEach("", *, *) = ""
@ -3772,7 +3772,7 @@ public static String replace(String text, String searchString, String replacemen
* (example of how it does not repeat)
* StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"}) = "dcte"
* </pre>
*
*
* @param text
* text to search and replace in, no-op if null
* @param searchList
@ -3794,14 +3794,14 @@ public static String replaceEach(String text, String[] searchList, String[] repl
* <p>
* Replaces all occurrences of Strings within another String.
* </p>
*
*
* <p>
* 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
* ignored. This will not repeat. For repeating replaces, call the
* overloaded method.
* </p>
*
*
* <pre>
* StringUtils.replaceEach(null, *, *, *) = null
* StringUtils.replaceEach("", *, *, *) = ""
@ -3818,7 +3818,7 @@ public static String replaceEach(String text, String[] searchList, String[] repl
* 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"
* </pre>
*
*
* @param text
* text to search and replace in, no-op if null
* @param searchList
@ -3846,13 +3846,13 @@ public static String replaceEachRepeatedly(String text, String[] searchList, Str
* <p>
* Replaces all occurrences of Strings within another String.
* </p>
*
*
* <p>
* 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
* ignored.
* ignored.
* </p>
*
*
* <pre>
* StringUtils.replaceEach(null, *, *, *) = null
* StringUtils.replaceEach("", *, *, *) = ""
@ -3868,14 +3868,14 @@ public static String replaceEachRepeatedly(String text, String[] searchList, Str
* 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
* </pre>
*
*
* @param text
* text to search and replace in, no-op if null
* @param searchList
* the Strings to search for, no-op if null
* @param replacementList
* 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
* @param timeToLive
* if less than 0 then there is a circular reference and endless
@ -3890,15 +3890,15 @@ public static String replaceEachRepeatedly(String text, String[] searchList, Str
* and/or size 0)
* @since 2.4
*/
private static String replaceEach(String text, String[] searchList, String[] replacementList,
boolean repeat, int timeToLive)
private static String replaceEach(String text, String[] searchList, String[] replacementList,
boolean repeat, int timeToLive)
{
// 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 || searchList == null ||
searchList.length == 0 || replacementList == null || replacementList.length == 0)
if (text == null || text.length() == 0 || searchList == null ||
searchList.length == 0 || replacementList == null || replacementList.length == 0)
{
return text;
}
@ -3930,8 +3930,8 @@ private static String replaceEach(String text, String[] searchList, String[] rep
// index of replace array that will replace the search string found
// NOTE: logic duplicated below START
for (int i = 0; i < searchLength; i++) {
if (noMoreMatchesForReplIndex[i] || searchList[i] == null ||
searchList[i].length() == 0 || replacementList[i] == null)
if (noMoreMatchesForReplIndex[i] || searchList[i] == null ||
searchList[i].length() == 0 || replacementList[i] == null)
{
continue;
}
@ -3989,8 +3989,8 @@ private static String replaceEach(String text, String[] searchList, String[] rep
// find the next earliest match
// NOTE: logic mostly duplicated above START
for (int i = 0; i < searchLength; i++) {
if (noMoreMatchesForReplIndex[i] || searchList[i] == null ||
searchList[i].length() == 0 || replacementList[i] == null)
if (noMoreMatchesForReplIndex[i] || searchList[i] == null ||
searchList[i].length() == 0 || replacementList[i] == null)
{
continue;
}
@ -4422,7 +4422,7 @@ public static String repeat(String str, String separator, int repeat) {
* <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.
* 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>
*
* @param repeat number of times to repeat delim
@ -4666,21 +4666,21 @@ public static String leftPad(String str, int size, String padStr) {
}
}
/**
* Gets a CharSequence length or <code>0</code> if the CharSequence is
* <code>null</code>.
*
* @param cs
* a CharSequence or <code>null</code>
* @return CharSequence length or <code>0</code> if the CharSequence is
* <code>null</code>.
* @since 2.4
* @deprecated See {@link CharSequenceUtils#length(CharSequence)}
*/
public static int length(CharSequence cs) {
return CharSequenceUtils.length(cs);
}
/**
* Gets a CharSequence length or <code>0</code> if the CharSequence is
* <code>null</code>.
*
* @param cs
* a CharSequence or <code>null</code>
* @return CharSequence length or <code>0</code> if the CharSequence is
* <code>null</code>.
* @since 2.4
* @deprecated See {@link CharSequenceUtils#length(CharSequence)}
*/
public static int length(CharSequence cs) {
return CharSequenceUtils.length(cs);
}
// Centering
//-----------------------------------------------------------------------
/**
@ -5178,10 +5178,10 @@ public static boolean isAlphanumericSpace(CharSequence cs) {
/**
* <p>Checks if the CharSequence contains only ASCII printable characters.</p>
*
*
* <p><code>null</code> will return <code>false</code>.
* An empty CharSequence (length()=0) will return <code>true</code>.</p>
*
*
* <pre>
* StringUtils.isAsciiPrintable(null) = false
* StringUtils.isAsciiPrintable("") = true
@ -5462,7 +5462,7 @@ public static String reverse(String str) {
if (str == null) {
return null;
}
return new StringBuilder(str).reverse().toString();
return new StringBuilder(str).reverse().toString();
}
/**
@ -5585,7 +5585,7 @@ public static String abbreviate(String str, int offset, int maxWidth) {
offset = str.length() - (maxWidth - 3);
}
final String abrevMarker = "...";
if (offset <= 4) {
if (offset <= 4) {
return str.substring(0, maxWidth - 3) + abrevMarker;
}
if (maxWidth < 7) {
@ -5596,7 +5596,7 @@ public static String abbreviate(String str, int offset, int maxWidth) {
}
return abrevMarker + str.substring(str.length() - (maxWidth - 3));
}
/**
* <p>Abbreviates a String to the length passed, replacing the middle characters with the supplied
* replacement String.</p>
@ -5630,7 +5630,7 @@ public static String abbreviateMiddle(String str, String middle, int length) {
if (isEmpty(str) || isEmpty(middle)) {
return str;
}
if (length >= str.length() || length < (middle.length()+2)) {
return str;
}
@ -5638,12 +5638,12 @@ public static String abbreviateMiddle(String str, String middle, int length) {
int targetSting = length-middle.length();
int startOffset = targetSting/2+targetSting%2;
int endOffset = str.length()-targetSting/2;
StringBuilder builder = new StringBuilder(length);
builder.append(str.substring(0,startOffset));
builder.append(middle);
builder.append(str.substring(endOffset));
return builder.toString();
}
@ -5818,9 +5818,9 @@ public static int indexOfDifference(CharSequence[] css) {
}
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>
*
* <p>For example,
@ -5848,8 +5848,8 @@ public static int indexOfDifference(CharSequence[] css) {
*
* @param strs array of String objects, entries may be null
* @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
* or if there is no common prefix.
* in the array; empty String if the array is null, the elements are all null
* or if there is no common prefix.
* @since 2.4
*/
public static String getCommonPrefix(String[] strs) {
@ -5870,8 +5870,8 @@ public static String getCommonPrefix(String[] strs) {
// we found a common initial character sequence
return strs[0].substring(0, smallestIndexOfDiff);
}
}
}
// Misc
//-----------------------------------------------------------------------
/**
@ -5914,19 +5914,19 @@ public static int getLevenshteinDistance(CharSequence s, CharSequence t) {
}
/*
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,
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,
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
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
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
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
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
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.
*/
@ -5941,7 +5941,7 @@ allows us to retain the previous cost counts as required by the algorithm (takin
if (n > m) {
// swap the input strings to consume less memory
CharSequence tmp = s;
CharSequence tmp = s;
s = t;
t = tmp;
n = m;
@ -5980,7 +5980,7 @@ allows us to retain the previous cost counts as required by the algorithm (takin
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
return p[n];
}
@ -6079,10 +6079,10 @@ private static boolean startsWith(String str, String prefix, boolean ignoreCase)
}
return str.regionMatches(ignoreCase, 0, prefix, 0, prefix.length());
}
/**
* <p>Check if a String starts with any of an array of specified strings.</p>
*
*
* <pre>
* StringUtils.startsWithAny(null, null) = 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 "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -23,70 +23,70 @@
/**
* Tests CharSequenceUtils
*
*
* @author Gary Gregory
*/
public class CharSequenceUtilsTest extends TestCase {
public void testLength_CharBuffer() {
Assert.assertEquals(0, CharSequenceUtils.length(CharBuffer.wrap("")));
Assert.assertEquals(1, CharSequenceUtils.length(CharBuffer.wrap("A")));
Assert.assertEquals(1, CharSequenceUtils.length(CharBuffer.wrap(" ")));
Assert.assertEquals(8, CharSequenceUtils.length(CharBuffer.wrap("ABCDEFGH")));
}
public void testLength_CharBuffer() {
Assert.assertEquals(0, CharSequenceUtils.length(CharBuffer.wrap("")));
Assert.assertEquals(1, CharSequenceUtils.length(CharBuffer.wrap("A")));
Assert.assertEquals(1, CharSequenceUtils.length(CharBuffer.wrap(" ")));
Assert.assertEquals(8, CharSequenceUtils.length(CharBuffer.wrap("ABCDEFGH")));
}
public void testLength_String() {
Assert.assertEquals(0, CharSequenceUtils.length(null));
Assert.assertEquals(0, CharSequenceUtils.length(""));
Assert.assertEquals(1, CharSequenceUtils.length("A"));
Assert.assertEquals(1, CharSequenceUtils.length(" "));
Assert.assertEquals(8, CharSequenceUtils.length("ABCDEFGH"));
}
public void testLength_String() {
Assert.assertEquals(0, CharSequenceUtils.length(null));
Assert.assertEquals(0, CharSequenceUtils.length(""));
Assert.assertEquals(1, CharSequenceUtils.length("A"));
Assert.assertEquals(1, CharSequenceUtils.length(" "));
Assert.assertEquals(8, CharSequenceUtils.length("ABCDEFGH"));
}
public void testLength_StringBuffer() {
Assert.assertEquals(0, CharSequenceUtils.length(new StringBuffer("")));
Assert.assertEquals(1, CharSequenceUtils.length(new StringBuffer("A")));
Assert.assertEquals(1, CharSequenceUtils.length(new StringBuffer(" ")));
Assert.assertEquals(8, CharSequenceUtils.length(new StringBuffer("ABCDEFGH")));
}
public void testLength_StringBuffer() {
Assert.assertEquals(0, CharSequenceUtils.length(new StringBuffer("")));
Assert.assertEquals(1, CharSequenceUtils.length(new StringBuffer("A")));
Assert.assertEquals(1, CharSequenceUtils.length(new StringBuffer(" ")));
Assert.assertEquals(8, CharSequenceUtils.length(new StringBuffer("ABCDEFGH")));
}
public void testLength_StringBuilder() {
Assert.assertEquals(0, CharSequenceUtils.length(new StringBuilder("")));
Assert.assertEquals(1, CharSequenceUtils.length(new StringBuilder("A")));
Assert.assertEquals(1, CharSequenceUtils.length(new StringBuilder(" ")));
Assert.assertEquals(8, CharSequenceUtils.length(new StringBuilder("ABCDEFGH")));
}
public void testLength_StringBuilder() {
Assert.assertEquals(0, CharSequenceUtils.length(new StringBuilder("")));
Assert.assertEquals(1, CharSequenceUtils.length(new StringBuilder("A")));
Assert.assertEquals(1, CharSequenceUtils.length(new StringBuilder(" ")));
Assert.assertEquals(8, CharSequenceUtils.length(new StringBuilder("ABCDEFGH")));
}
public void testSubSequence() {
//
// null input
//
Assert.assertEquals(null, CharSequenceUtils.subSequence(null, -1));
Assert.assertEquals(null, CharSequenceUtils.subSequence(null, 0));
Assert.assertEquals(null, CharSequenceUtils.subSequence(null, 1));
//
// non-null input
//
Assert.assertEquals(StringUtils.EMPTY, CharSequenceUtils.subSequence(StringUtils.EMPTY, 0));
Assert.assertEquals("012", CharSequenceUtils.subSequence("012", 0));
Assert.assertEquals("12", CharSequenceUtils.subSequence("012", 1));
Assert.assertEquals("2", CharSequenceUtils.subSequence("012", 2));
Assert.assertEquals(StringUtils.EMPTY, CharSequenceUtils.subSequence("012", 3));
//
// Exception expected
//
try {
Assert.assertEquals(null, CharSequenceUtils.subSequence(StringUtils.EMPTY, -1));
Assert.fail("Expected " + IndexOutOfBoundsException.class.getName());
} catch (IndexOutOfBoundsException e) {
// Expected
}
try {
Assert.assertEquals(null, CharSequenceUtils.subSequence(StringUtils.EMPTY, 1));
Assert.fail("Expected " + IndexOutOfBoundsException.class.getName());
} catch (IndexOutOfBoundsException e) {
// Expected
}
}
public void testSubSequence() {
//
// null input
//
Assert.assertEquals(null, CharSequenceUtils.subSequence(null, -1));
Assert.assertEquals(null, CharSequenceUtils.subSequence(null, 0));
Assert.assertEquals(null, CharSequenceUtils.subSequence(null, 1));
//
// non-null input
//
Assert.assertEquals(StringUtils.EMPTY, CharSequenceUtils.subSequence(StringUtils.EMPTY, 0));
Assert.assertEquals("012", CharSequenceUtils.subSequence("012", 0));
Assert.assertEquals("12", CharSequenceUtils.subSequence("012", 1));
Assert.assertEquals("2", CharSequenceUtils.subSequence("012", 2));
Assert.assertEquals(StringUtils.EMPTY, CharSequenceUtils.subSequence("012", 3));
//
// Exception expected
//
try {
Assert.assertEquals(null, CharSequenceUtils.subSequence(StringUtils.EMPTY, -1));
Assert.fail("Expected " + IndexOutOfBoundsException.class.getName());
} catch (IndexOutOfBoundsException e) {
// Expected
}
try {
Assert.assertEquals(null, CharSequenceUtils.subSequence(StringUtils.EMPTY, 1));
Assert.fail("Expected " + IndexOutOfBoundsException.class.getName());
} catch (IndexOutOfBoundsException e) {
// Expected
}
}
}

View File

@ -5,9 +5,9 @@
* 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 obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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";
/**
* Supplementary character U+20001
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
*/
private static final String CharU20001 = "\uD840\uDC01";
* Supplementary character U+20001
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
*/
private static final String CharU20001 = "\uD840\uDC01";
/**
* Incomplete supplementary character U+20000, high surrogate only.
* See http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
*/
private static final String CharUSuppCharHigh = "\uDC00";
/**
* Incomplete supplementary character U+20000, low surrogate only.
* 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_SUB_ARRAY = new String[] {"ob", "ba"};
private static final String[] FOOBAR_SUB_ARRAY = new String[] {"ob", "ba"};
public StringUtilsEqualsIndexOfTest(String name) {
super(name);
}
@ -164,14 +164,14 @@ public void testContainsAny_StringString() {
assertFalse(StringUtils.containsAny(null, (String) null));
assertFalse(StringUtils.containsAny(null, ""));
assertFalse(StringUtils.containsAny(null, "ab"));
assertFalse(StringUtils.containsAny("", (String) null));
assertFalse(StringUtils.containsAny("", ""));
assertFalse(StringUtils.containsAny("", "ab"));
assertFalse(StringUtils.containsAny("zzabyycdxx", (String) null));
assertFalse(StringUtils.containsAny("zzabyycdxx", ""));
assertTrue(StringUtils.containsAny("zzabyycdxx", "za"));
assertFalse(StringUtils.containsAny("zzabyycdxx", (String) null));
assertFalse(StringUtils.containsAny("zzabyycdxx", ""));
assertTrue(StringUtils.containsAny("zzabyycdxx", "za"));
assertTrue(StringUtils.containsAny("zzabyycdxx", "by"));
assertFalse(StringUtils.containsAny("ab", "z"));
}
@ -210,7 +210,7 @@ public void testContainsIgnoreCase_LocaleIndependence() {
Locale[] locales = { Locale.ENGLISH, new Locale("tr"), Locale.getDefault() };
String[][] tdata = {
String[][] tdata = {
{ "i", "I" },
{ "I", "i" },
{ "\u03C2", "\u03C3" },
@ -218,7 +218,7 @@ public void testContainsIgnoreCase_LocaleIndependence() {
{ "\u03A3", "\u03C3" },
};
String[][] fdata = {
String[][] fdata = {
{ "\u00DF", "SS" },
};
@ -241,16 +241,16 @@ public void testContainsIgnoreCase_LocaleIndependence() {
public void testContainsIgnoreCase_StringString() {
assertFalse(StringUtils.containsIgnoreCase(null, null));
// Null tests
assertFalse(StringUtils.containsIgnoreCase(null, ""));
assertFalse(StringUtils.containsIgnoreCase(null, "a"));
assertFalse(StringUtils.containsIgnoreCase(null, "abc"));
assertFalse(StringUtils.containsIgnoreCase("", null));
assertFalse(StringUtils.containsIgnoreCase("a", null));
assertFalse(StringUtils.containsIgnoreCase("abc", null));
// Match len = 0
assertTrue(StringUtils.containsIgnoreCase("", ""));
assertTrue(StringUtils.containsIgnoreCase("a", ""));
@ -263,7 +263,7 @@ public void testContainsIgnoreCase_StringString() {
assertFalse(StringUtils.containsIgnoreCase("", "A"));
assertTrue(StringUtils.containsIgnoreCase("a", "A"));
assertTrue(StringUtils.containsIgnoreCase("abc", "A"));
// Match len > 1
assertFalse(StringUtils.containsIgnoreCase("", "abc"));
assertFalse(StringUtils.containsIgnoreCase("a", "abc"));
@ -363,7 +363,7 @@ public void testContainsNone_StringWithBadSupplementaryChars() {
assertEquals(-1, CharU20001.indexOf(CharUSuppCharHigh));
assertEquals(true, StringUtils.containsNone(CharU20001, CharUSuppCharHigh));
assertEquals(0, CharU20001.indexOf(CharUSuppCharLow));
assertEquals(false, StringUtils.containsNone(CharU20001, CharUSuppCharLow));
assertEquals(false, StringUtils.containsNone(CharU20001, CharUSuppCharLow));
}
/**
@ -501,21 +501,21 @@ public void testIndexOf_StringInt() {
assertEquals(5, StringUtils.indexOf("aabaabaa", "b", 3));
assertEquals(-1, StringUtils.indexOf("aabaabaa", "b", 9));
assertEquals(2, StringUtils.indexOf("aabaabaa", "b", -1));
assertEquals(2,StringUtils.indexOf("aabaabaa", "", 2));
assertEquals(2,StringUtils.indexOf("aabaabaa", "", 2));
}
public void testIndexOfAny_StringCharArray() {
assertEquals(-1, StringUtils.indexOfAny(null, (char[]) null));
assertEquals(-1, StringUtils.indexOfAny(null, new char[0]));
assertEquals(-1, StringUtils.indexOfAny(null, new char[] {'a','b'}));
assertEquals(-1, StringUtils.indexOfAny("", (char[]) null));
assertEquals(-1, StringUtils.indexOfAny("", new char[0]));
assertEquals(-1, StringUtils.indexOfAny("", new char[] {'a','b'}));
assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", (char[]) null));
assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", new char[0]));
assertEquals(0, StringUtils.indexOfAny("zzabyycdxx", new char[] {'z','a'}));
assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", (char[]) null));
assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", new char[0]));
assertEquals(0, StringUtils.indexOfAny("zzabyycdxx", new char[] {'z','a'}));
assertEquals(3, StringUtils.indexOfAny("zzabyycdxx", new char[] {'b','y'}));
assertEquals(-1, StringUtils.indexOfAny("ab", new char[] {'z'}));
}
@ -527,21 +527,21 @@ public void testIndexOfAny_StringCharArrayWithSupplementaryChars() {
assertEquals(0, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20000.toCharArray()));
assertEquals(2, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20001.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() {
assertEquals(-1, StringUtils.indexOfAny(null, (String) null));
assertEquals(-1, StringUtils.indexOfAny(null, ""));
assertEquals(-1, StringUtils.indexOfAny(null, "ab"));
assertEquals(-1, StringUtils.indexOfAny("", (String) null));
assertEquals(-1, StringUtils.indexOfAny("", ""));
assertEquals(-1, StringUtils.indexOfAny("", "ab"));
assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", (String) null));
assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", ""));
assertEquals(0, StringUtils.indexOfAny("zzabyycdxx", "za"));
assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", (String) null));
assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", ""));
assertEquals(0, StringUtils.indexOfAny("zzabyycdxx", "za"));
assertEquals(3, StringUtils.indexOfAny("zzabyycdxx", "by"));
assertEquals(-1, StringUtils.indexOfAny("ab", "z"));
}
@ -570,53 +570,53 @@ public void testIndexOfAny_StringStringWithSupplementaryChars() {
assertEquals(0, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20000));
assertEquals(2, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20001));
assertEquals(0, StringUtils.indexOfAny(CharU20000, CharU20000));
assertEquals(-1, StringUtils.indexOfAny(CharU20000, CharU20001));
assertEquals(-1, StringUtils.indexOfAny(CharU20000, CharU20001));
}
public void testIndexOfAnyBut_StringCharArray() {
assertEquals(-1, StringUtils.indexOfAnyBut(null, (char[]) null));
assertEquals(-1, StringUtils.indexOfAnyBut(null, new char[0]));
assertEquals(-1, StringUtils.indexOfAnyBut(null, new char[] {'a','b'}));
assertEquals(-1, StringUtils.indexOfAnyBut("", (char[]) null));
assertEquals(-1, StringUtils.indexOfAnyBut("", new char[0]));
assertEquals(-1, StringUtils.indexOfAnyBut("", new char[] {'a','b'}));
assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", (char[]) null));
assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", new char[0]));
assertEquals(3, StringUtils.indexOfAnyBut("zzabyycdxx", new char[] {'z','a'}));
assertEquals(0, StringUtils.indexOfAnyBut("zzabyycdxx", new char[] {'b','y'}));
assertEquals(3, StringUtils.indexOfAnyBut("zzabyycdxx", new char[] {'z','a'}));
assertEquals(0, StringUtils.indexOfAnyBut("zzabyycdxx", new char[] {'b','y'}));
assertEquals(0, StringUtils.indexOfAnyBut("ab", new char[] {'z'}));
}
public void testIndexOfAnyBut_StringCharArrayWithSupplementaryChars() {
assertEquals(2, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20000.toCharArray()));
assertEquals(0, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20001.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() {
assertEquals(-1, StringUtils.indexOfAnyBut(null, (String) null));
assertEquals(-1, StringUtils.indexOfAnyBut(null, ""));
assertEquals(-1, StringUtils.indexOfAnyBut(null, "ab"));
assertEquals(-1, StringUtils.indexOfAnyBut("", (String) null));
assertEquals(-1, StringUtils.indexOfAnyBut("", ""));
assertEquals(-1, StringUtils.indexOfAnyBut("", "ab"));
assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", (String) null));
assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", ""));
assertEquals(3, StringUtils.indexOfAnyBut("zzabyycdxx", "za"));
assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", (String) null));
assertEquals(-1, StringUtils.indexOfAnyBut("zzabyycdxx", ""));
assertEquals(3, StringUtils.indexOfAnyBut("zzabyycdxx", "za"));
assertEquals(0, StringUtils.indexOfAnyBut("zzabyycdxx", "by"));
assertEquals(0, StringUtils.indexOfAnyBut("ab", "z"));
}
public void testIndexOfAnyBut_StringStringWithSupplementaryChars() {
assertEquals(2, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20000));
assertEquals(0, StringUtils.indexOfAnyBut(CharU20000 + CharU20001, CharU20001));
assertEquals(-1, StringUtils.indexOfAnyBut(CharU20000, CharU20000));
assertEquals(0, StringUtils.indexOfAnyBut(CharU20000, CharU20001));
assertEquals(0, StringUtils.indexOfAnyBut(CharU20000, CharU20001));
}
public void testIndexOfIgnoreCase_String() {
@ -738,7 +738,7 @@ public void testLastIndexOfIgnoreCase_String() {
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, -1));
assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, "", 0));
@ -761,7 +761,7 @@ public void testLastIndexOfIgnoreCase_StringInt() {
assertEquals(0, StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A", 0));
assertEquals(1, StringUtils.lastIndexOfIgnoreCase("aab", "AB", 1));
}
public void testLastOrdinalIndexOf() {
assertEquals(-1, StringUtils.lastOrdinalIndexOf(null, "*", 42) );
assertEquals(-1, StringUtils.lastOrdinalIndexOf("*", null, 42) );
@ -784,7 +784,7 @@ public void testOrdinalIndexOf() {
assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "b", Integer.MIN_VALUE));
assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "ab", Integer.MIN_VALUE));
assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "", Integer.MIN_VALUE));
assertEquals(-1, StringUtils.ordinalIndexOf(null, null, -1));
assertEquals(-1, StringUtils.ordinalIndexOf("", null, -1));
assertEquals(-1, StringUtils.ordinalIndexOf("", "", -1));
@ -816,7 +816,7 @@ public void testOrdinalIndexOf() {
assertEquals(5, StringUtils.ordinalIndexOf("aabaabaa", "b", 2));
assertEquals(4, StringUtils.ordinalIndexOf("aabaabaa", "ab", 2));
assertEquals(0, StringUtils.ordinalIndexOf("aabaabaa", "", 2));
assertEquals(-1, StringUtils.ordinalIndexOf(null, null, Integer.MAX_VALUE));
assertEquals(-1, StringUtils.ordinalIndexOf("", null, Integer.MAX_VALUE));
assertEquals(0, StringUtils.ordinalIndexOf("", "", Integer.MAX_VALUE));
@ -824,7 +824,7 @@ public void testOrdinalIndexOf() {
assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "b", Integer.MAX_VALUE));
assertEquals(-1, StringUtils.ordinalIndexOf("aabaabaa", "ab", Integer.MAX_VALUE));
assertEquals(0, StringUtils.ordinalIndexOf("aabaabaa", "", Integer.MAX_VALUE));
assertEquals(-1, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 0));
assertEquals(0, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 1));
assertEquals(1, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 2));