Minor performance tweaks, and some extra tests
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137450 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
59b77af292
commit
4e070edf4b
|
@ -99,7 +99,7 @@ import org.apache.commons.lang.math.NumberUtils;
|
||||||
* @author Arun Mammen Thomas
|
* @author Arun Mammen Thomas
|
||||||
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
|
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
* @version $Id: StringUtils.java,v 1.63 2003/07/18 23:57:43 scolebourne Exp $
|
* @version $Id: StringUtils.java,v 1.64 2003/07/19 00:22:50 scolebourne Exp $
|
||||||
*/
|
*/
|
||||||
public class StringUtils {
|
public class StringUtils {
|
||||||
|
|
||||||
|
@ -1954,6 +1954,7 @@ public class StringUtils {
|
||||||
* StringUtils.rightPad("bat", -1, "yz") = "bat"
|
* StringUtils.rightPad("bat", -1, "yz") = "bat"
|
||||||
* StringUtils.rightPad("bat", 1, null) = IllegalArgumentException
|
* StringUtils.rightPad("bat", 1, null) = IllegalArgumentException
|
||||||
* StringUtils.rightPad("bat", 1, "") = IllegalArgumentException
|
* StringUtils.rightPad("bat", 1, "") = IllegalArgumentException
|
||||||
|
* StringUtils.rightPad(null, 1, "") = IllegalArgumentException
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param str the String to pad out, may be null
|
* @param str the String to pad out, may be null
|
||||||
|
@ -1964,13 +1965,13 @@ public class StringUtils {
|
||||||
* @throws IllegalArgumentException if padStr is the empty String or null
|
* @throws IllegalArgumentException if padStr is the empty String or null
|
||||||
*/
|
*/
|
||||||
public static String rightPad(String str, int size, String padStr) {
|
public static String rightPad(String str, int size, String padStr) {
|
||||||
if (str == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
int padLen;
|
int padLen;
|
||||||
if (padStr == null || (padLen = padStr.length()) == 0) {
|
if (padStr == null || (padLen = padStr.length()) == 0) {
|
||||||
throw new IllegalArgumentException("Pad String must not be null or empty");
|
throw new IllegalArgumentException("Pad String must not be null or empty");
|
||||||
}
|
}
|
||||||
|
if (str == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
int strLen = str.length();
|
int strLen = str.length();
|
||||||
int pads = size - strLen;
|
int pads = size - strLen;
|
||||||
if (padLen == 1 && pads <= PAD_LIMIT) {
|
if (padLen == 1 && pads <= PAD_LIMIT) {
|
||||||
|
@ -2073,6 +2074,7 @@ public class StringUtils {
|
||||||
* StringUtils.leftPad("bat", -1, "yz") = "bat"
|
* StringUtils.leftPad("bat", -1, "yz") = "bat"
|
||||||
* StringUtils.leftPad("bat", 1, null) = IllegalArgumentException
|
* StringUtils.leftPad("bat", 1, null) = IllegalArgumentException
|
||||||
* StringUtils.leftPad("bat", 1, "") = IllegalArgumentException
|
* StringUtils.leftPad("bat", 1, "") = IllegalArgumentException
|
||||||
|
* StringUtils.leftPad(null, 1, "") = IllegalArgumentException
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param str the String to pad out, may be null
|
* @param str the String to pad out, may be null
|
||||||
|
@ -2083,13 +2085,13 @@ public class StringUtils {
|
||||||
* @throws IllegalArgumentException if padStr is the empty String or null
|
* @throws IllegalArgumentException if padStr is the empty String or null
|
||||||
*/
|
*/
|
||||||
public static String leftPad(String str, int size, String padStr) {
|
public static String leftPad(String str, int size, String padStr) {
|
||||||
if (str == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
int padLen;
|
int padLen;
|
||||||
if (padStr == null || (padLen = padStr.length()) == 0) {
|
if (padStr == null || (padLen = padStr.length()) == 0) {
|
||||||
throw new IllegalArgumentException("Pad String must not be null or empty");
|
throw new IllegalArgumentException("Pad String must not be null or empty");
|
||||||
}
|
}
|
||||||
|
if (str == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
int strLen = str.length();
|
int strLen = str.length();
|
||||||
int pads = size - strLen;
|
int pads = size - strLen;
|
||||||
if (padLen == 1 && pads <= PAD_LIMIT) {
|
if (padLen == 1 && pads <= PAD_LIMIT) {
|
||||||
|
@ -2129,6 +2131,7 @@ public class StringUtils {
|
||||||
* <pre>
|
* <pre>
|
||||||
* StringUtils.center(null, -1) = null
|
* StringUtils.center(null, -1) = null
|
||||||
* StringUtils.center(null, 4) = null
|
* StringUtils.center(null, 4) = null
|
||||||
|
* StringUtils.center("ab", -1) = "ab"
|
||||||
* StringUtils.center("", 4) = " "
|
* StringUtils.center("", 4) = " "
|
||||||
* StringUtils.center("ab", 4) = " ab "
|
* StringUtils.center("ab", 4) = " ab "
|
||||||
* StringUtils.center("abcd", 2) = "abcd"
|
* StringUtils.center("abcd", 2) = "abcd"
|
||||||
|
@ -2140,18 +2143,15 @@ public class StringUtils {
|
||||||
* @return centered String, <code>null</code> if null String input
|
* @return centered String, <code>null</code> if null String input
|
||||||
*/
|
*/
|
||||||
public static String center(String str, int size) {
|
public static String center(String str, int size) {
|
||||||
if (str == null) {
|
if (str == null || size <= 0) {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (size < 0) {
|
|
||||||
size = 0;
|
|
||||||
}
|
|
||||||
int sz = str.length();
|
|
||||||
int p = size - sz;
|
|
||||||
if (p < 1) {
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
str = leftPad(str, sz + p / 2, ' ');
|
int strLen = str.length();
|
||||||
|
int pads = size - strLen;
|
||||||
|
if (pads <= 0) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
str = leftPad(str, strLen + pads / 2, ' ');
|
||||||
str = rightPad(str, size, ' ');
|
str = rightPad(str, size, ' ');
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
@ -2167,6 +2167,7 @@ public class StringUtils {
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* StringUtils.center(null, -1, " ") = null
|
* StringUtils.center(null, -1, " ") = null
|
||||||
|
* StringUtils.center("ab", -1, " ") = "ab"
|
||||||
* StringUtils.center(null, 4, " ") = null
|
* StringUtils.center(null, 4, " ") = null
|
||||||
* StringUtils.center("", 4, " ") = " "
|
* StringUtils.center("", 4, " ") = " "
|
||||||
* StringUtils.center("ab", 4, " ") = " ab"
|
* StringUtils.center("ab", 4, " ") = " ab"
|
||||||
|
@ -2175,6 +2176,7 @@ public class StringUtils {
|
||||||
* StringUtils.center("a", 4, "yz") = "yayz"
|
* StringUtils.center("a", 4, "yz") = "yayz"
|
||||||
* StringUtils.center("abc", 4, null) = IllegalArgumentException
|
* StringUtils.center("abc", 4, null) = IllegalArgumentException
|
||||||
* StringUtils.center("abc", 4, "") = IllegalArgumentException
|
* StringUtils.center("abc", 4, "") = IllegalArgumentException
|
||||||
|
* StringUtils.center(null, 4, "") = IllegalArgumentException
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param str the String to center, may be null
|
* @param str the String to center, may be null
|
||||||
|
@ -2184,21 +2186,18 @@ public class StringUtils {
|
||||||
* @throws IllegalArgumentException if padStr is <code>null</code> or empty
|
* @throws IllegalArgumentException if padStr is <code>null</code> or empty
|
||||||
*/
|
*/
|
||||||
public static String center(String str, int size, String padStr) {
|
public static String center(String str, int size, String padStr) {
|
||||||
if (str == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (padStr == null || padStr.length() == 0) {
|
if (padStr == null || padStr.length() == 0) {
|
||||||
throw new IllegalArgumentException("Pad String must not be null or empty");
|
throw new IllegalArgumentException("Pad String must not be null or empty");
|
||||||
}
|
}
|
||||||
if (size < 0) {
|
if (str == null || size <= 0) {
|
||||||
size = 0;
|
|
||||||
}
|
|
||||||
int sz = str.length();
|
|
||||||
int p = size - sz;
|
|
||||||
if (p < 1) {
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
str = leftPad(str, sz + p / 2, padStr);
|
int strLen = str.length();
|
||||||
|
int pads = size - strLen;
|
||||||
|
if (pads <= 0) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
str = leftPad(str, strLen + pads / 2, padStr);
|
||||||
str = rightPad(str, size, padStr);
|
str = rightPad(str, size, padStr);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
@ -2283,21 +2282,17 @@ public class StringUtils {
|
||||||
* @return the stripped String, <code>null</code> if null String input
|
* @return the stripped String, <code>null</code> if null String input
|
||||||
*/
|
*/
|
||||||
public static String stripStart(String str, String stripChars) {
|
public static String stripStart(String str, String stripChars) {
|
||||||
if (str == null) {
|
int strLen;
|
||||||
return null;
|
if (str == null || (strLen = str.length()) == 0) {
|
||||||
}
|
|
||||||
int sz = str.length();
|
|
||||||
if (sz == 0) {
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
int start = 0;
|
int start = 0;
|
||||||
if (stripChars == null) {
|
if (stripChars == null) {
|
||||||
while ((start != sz) && Character.isWhitespace(str.charAt(start))) {
|
while ((start != strLen) && Character.isWhitespace(str.charAt(start))) {
|
||||||
start++;
|
start++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while ((start != sz) && (stripChars.indexOf(str.charAt(start)) != -1)) {
|
while ((start != strLen) && (stripChars.indexOf(str.charAt(start)) != -1)) {
|
||||||
start++;
|
start++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2327,11 +2322,8 @@ public class StringUtils {
|
||||||
* @return the stripped String, <code>null</code> if null String input
|
* @return the stripped String, <code>null</code> if null String input
|
||||||
*/
|
*/
|
||||||
public static String stripEnd(String str, String stripChars) {
|
public static String stripEnd(String str, String stripChars) {
|
||||||
if (str == null) {
|
int end;
|
||||||
return null;
|
if (str == null || (end = str.length()) == 0) {
|
||||||
}
|
|
||||||
int end = str.length();
|
|
||||||
if (end == 0) {
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2396,12 +2388,12 @@ public class StringUtils {
|
||||||
* @return the stripped Strings, <code>null</code> if null array input
|
* @return the stripped Strings, <code>null</code> if null array input
|
||||||
*/
|
*/
|
||||||
public static String[] stripAll(String[] strs, String stripChars) {
|
public static String[] stripAll(String[] strs, String stripChars) {
|
||||||
if ((strs == null) || (strs.length == 0)) {
|
int strsLen;
|
||||||
|
if (strs == null || (strsLen = strs.length) == 0) {
|
||||||
return strs;
|
return strs;
|
||||||
}
|
}
|
||||||
int sz = strs.length;
|
String[] newArr = new String[strsLen];
|
||||||
String[] newArr = new String[sz];
|
for (int i = 0; i < strsLen; i++) {
|
||||||
for (int i = 0; i < sz; i++) {
|
|
||||||
newArr[i] = strip(strs[i], stripChars);
|
newArr[i] = strip(strs[i], stripChars);
|
||||||
}
|
}
|
||||||
return newArr;
|
return newArr;
|
||||||
|
@ -2466,13 +2458,11 @@ public class StringUtils {
|
||||||
* @return the capitalised String, <code>null</code> if null String input
|
* @return the capitalised String, <code>null</code> if null String input
|
||||||
*/
|
*/
|
||||||
public static String capitalise(String str) {
|
public static String capitalise(String str) {
|
||||||
if (str == null) {
|
int strLen;
|
||||||
return null;
|
if (str == null || (strLen = str.length()) == 0) {
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
if (str.length() == 0) {
|
return new StringBuffer(strLen)
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return new StringBuffer(str.length())
|
|
||||||
.append(Character.toTitleCase(str.charAt(0)))
|
.append(Character.toTitleCase(str.charAt(0)))
|
||||||
.append(str.substring(1))
|
.append(str.substring(1))
|
||||||
.toString();
|
.toString();
|
||||||
|
@ -2494,13 +2484,11 @@ public class StringUtils {
|
||||||
* @return the uncapitalised String, <code>null</code> if null String input
|
* @return the uncapitalised String, <code>null</code> if null String input
|
||||||
*/
|
*/
|
||||||
public static String uncapitalise(String str) {
|
public static String uncapitalise(String str) {
|
||||||
if (str == null) {
|
int strLen;
|
||||||
return null;
|
if (str == null || (strLen = str.length()) == 0) {
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
if (str.length() == 0) {
|
return new StringBuffer(strLen)
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return new StringBuffer(str.length())
|
|
||||||
.append(Character.toLowerCase(str.charAt(0)))
|
.append(Character.toLowerCase(str.charAt(0)))
|
||||||
.append(str.substring(1))
|
.append(str.substring(1))
|
||||||
.toString();
|
.toString();
|
||||||
|
@ -2528,17 +2516,17 @@ public class StringUtils {
|
||||||
* @return the changed String, <code>null</code> if null String input
|
* @return the changed String, <code>null</code> if null String input
|
||||||
*/
|
*/
|
||||||
public static String swapCase(String str) {
|
public static String swapCase(String str) {
|
||||||
if (str == null) {
|
int strLen;
|
||||||
return null;
|
if (str == null || (strLen = str.length()) == 0) {
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
int sz = str.length();
|
StringBuffer buffer = new StringBuffer(strLen);
|
||||||
StringBuffer buffer = new StringBuffer(sz);
|
|
||||||
|
|
||||||
boolean whitespace = true;
|
boolean whitespace = true;
|
||||||
char ch = 0;
|
char ch = 0;
|
||||||
char tmp = 0;
|
char tmp = 0;
|
||||||
|
|
||||||
for (int i = 0; i < sz; i++) {
|
for (int i = 0; i < strLen; i++) {
|
||||||
ch = str.charAt(i);
|
ch = str.charAt(i);
|
||||||
if (Character.isUpperCase(ch)) {
|
if (Character.isUpperCase(ch)) {
|
||||||
tmp = Character.toLowerCase(ch);
|
tmp = Character.toLowerCase(ch);
|
||||||
|
@ -2568,6 +2556,7 @@ public class StringUtils {
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* StringUtils.capitaliseAllWords(null) = null
|
* StringUtils.capitaliseAllWords(null) = null
|
||||||
|
* StringUtils.capitaliseAllWords("") = ""
|
||||||
* StringUtils.capitaliseAllWords("i am FINE") = "I Am FINE"
|
* StringUtils.capitaliseAllWords("i am FINE") = "I Am FINE"
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -2575,14 +2564,15 @@ public class StringUtils {
|
||||||
* @return capitalised String, <code>null</code> if null String input
|
* @return capitalised String, <code>null</code> if null String input
|
||||||
*/
|
*/
|
||||||
public static String capitaliseAllWords(String str) {
|
public static String capitaliseAllWords(String str) {
|
||||||
if (str == null) {
|
int strLen;
|
||||||
return null;
|
if (str == null || (strLen = str.length()) == 0) {
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
int sz = str.length();
|
StringBuffer buffer = new StringBuffer(strLen);
|
||||||
StringBuffer buffer = new StringBuffer(sz);
|
|
||||||
boolean whitespace = true;
|
boolean whitespace = true;
|
||||||
for (int i = 0; i < sz; i++) {
|
char[] strChars = str.toCharArray();
|
||||||
char ch = str.charAt(i);
|
for (int i = 0; i < strLen; i++) {
|
||||||
|
char ch = strChars[i];
|
||||||
if (Character.isWhitespace(ch)) {
|
if (Character.isWhitespace(ch)) {
|
||||||
buffer.append(ch);
|
buffer.append(ch);
|
||||||
whitespace = true;
|
whitespace = true;
|
||||||
|
@ -2605,6 +2595,7 @@ public class StringUtils {
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* StringUtils.uncapitaliseAllWords(null) = null
|
* StringUtils.uncapitaliseAllWords(null) = null
|
||||||
|
* StringUtils.uncapitaliseAllWords("") = ""
|
||||||
* StringUtils.uncapitaliseAllWords("I Am FINE") = "i am fINE"
|
* StringUtils.uncapitaliseAllWords("I Am FINE") = "i am fINE"
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -2612,20 +2603,21 @@ public class StringUtils {
|
||||||
* @return uncapitalised String, <code>null</code> if null String input
|
* @return uncapitalised String, <code>null</code> if null String input
|
||||||
*/
|
*/
|
||||||
public static String uncapitaliseAllWords(String str) {
|
public static String uncapitaliseAllWords(String str) {
|
||||||
if (str == null) {
|
int strLen;
|
||||||
return null;
|
if (str == null || (strLen = str.length()) == 0) {
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
int sz = str.length();
|
StringBuffer buffer = new StringBuffer(strLen);
|
||||||
StringBuffer buffer = new StringBuffer(sz);
|
boolean whitespace = true;
|
||||||
boolean space = true;
|
char[] strChars = str.toCharArray();
|
||||||
for (int i = 0; i < sz; i++) {
|
for (int i = 0; i < strLen; i++) {
|
||||||
char ch = str.charAt(i);
|
char ch = strChars[i];
|
||||||
if (Character.isWhitespace(ch)) {
|
if (Character.isWhitespace(ch)) {
|
||||||
buffer.append(ch);
|
buffer.append(ch);
|
||||||
space = true;
|
whitespace = true;
|
||||||
} else if (space) {
|
} else if (whitespace) {
|
||||||
buffer.append(Character.toLowerCase(ch));
|
buffer.append(Character.toLowerCase(ch));
|
||||||
space = false;
|
whitespace = false;
|
||||||
} else {
|
} else {
|
||||||
buffer.append(ch);
|
buffer.append(ch);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ import junit.textui.TestRunner;
|
||||||
* @author <a href="mailto:fredrik@westermarck.com>Fredrik Westermarck</a>
|
* @author <a href="mailto:fredrik@westermarck.com>Fredrik Westermarck</a>
|
||||||
* @author Holger Krauth
|
* @author Holger Krauth
|
||||||
* @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
|
* @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
|
||||||
* @version $Id: StringUtilsTest.java,v 1.27 2003/07/18 23:57:43 scolebourne Exp $
|
* @version $Id: StringUtilsTest.java,v 1.28 2003/07/19 00:22:50 scolebourne Exp $
|
||||||
*/
|
*/
|
||||||
public class StringUtilsTest extends TestCase {
|
public class StringUtilsTest extends TestCase {
|
||||||
|
|
||||||
|
@ -311,6 +311,9 @@ public class StringUtilsTest extends TestCase {
|
||||||
public void testCenter() {
|
public void testCenter() {
|
||||||
assertEquals(null, StringUtils.center(null, -1));
|
assertEquals(null, StringUtils.center(null, -1));
|
||||||
assertEquals(null, StringUtils.center(null, 4));
|
assertEquals(null, StringUtils.center(null, 4));
|
||||||
|
assertEquals("ab", StringUtils.center("ab", 0));
|
||||||
|
assertEquals("ab", StringUtils.center("ab", -1));
|
||||||
|
assertEquals("ab", StringUtils.center("ab", 1));
|
||||||
assertEquals(" ", StringUtils.center("", 4));
|
assertEquals(" ", StringUtils.center("", 4));
|
||||||
assertEquals(" ab ", StringUtils.center("ab", 4));
|
assertEquals(" ab ", StringUtils.center("ab", 4));
|
||||||
assertEquals("abcd", StringUtils.center("abcd", 2));
|
assertEquals("abcd", StringUtils.center("abcd", 2));
|
||||||
|
@ -319,12 +322,20 @@ public class StringUtilsTest extends TestCase {
|
||||||
|
|
||||||
assertEquals(null, StringUtils.center(null, -1, " "));
|
assertEquals(null, StringUtils.center(null, -1, " "));
|
||||||
assertEquals(null, StringUtils.center(null, 4, " "));
|
assertEquals(null, StringUtils.center(null, 4, " "));
|
||||||
|
assertEquals("ab", StringUtils.center("ab", 0, " "));
|
||||||
|
assertEquals("ab", StringUtils.center("ab", -1, " "));
|
||||||
|
assertEquals("ab", StringUtils.center("ab", 1, " "));
|
||||||
assertEquals(" ", StringUtils.center("", 4, " "));
|
assertEquals(" ", StringUtils.center("", 4, " "));
|
||||||
assertEquals(" ab ", StringUtils.center("ab", 4, " "));
|
assertEquals(" ab ", StringUtils.center("ab", 4, " "));
|
||||||
assertEquals("abcd", StringUtils.center("abcd", 2, " "));
|
assertEquals("abcd", StringUtils.center("abcd", 2, " "));
|
||||||
assertEquals(" a ", StringUtils.center("a", 4, " "));
|
assertEquals(" a ", StringUtils.center("a", 4, " "));
|
||||||
assertEquals("yayz", StringUtils.center("a", 4, "yz"));
|
assertEquals("yayz", StringUtils.center("a", 4, "yz"));
|
||||||
assertEquals("yzyayzy", StringUtils.center("a", 7, "yz"));
|
assertEquals("yzyayzy", StringUtils.center("a", 7, "yz"));
|
||||||
|
try {
|
||||||
|
StringUtils.center(null, 4, null);
|
||||||
|
fail();
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
StringUtils.center("abc", 4, null);
|
StringUtils.center("abc", 4, null);
|
||||||
fail();
|
fail();
|
||||||
|
@ -476,6 +487,10 @@ public class StringUtilsTest extends TestCase {
|
||||||
assertEquals("1234-+-+", StringUtils.rightPad ("1234", 8, "-+") );
|
assertEquals("1234-+-+", StringUtils.rightPad ("1234", 8, "-+") );
|
||||||
assertEquals("123456-+~", StringUtils.rightPad ("123456", 9, "-+~") );
|
assertEquals("123456-+~", StringUtils.rightPad ("123456", 9, "-+~") );
|
||||||
assertEquals("123456-+", StringUtils.rightPad ("123456", 8, "-+~") );
|
assertEquals("123456-+", StringUtils.rightPad ("123456", 8, "-+~") );
|
||||||
|
try {
|
||||||
|
StringUtils.rightPad(null, 6, null);
|
||||||
|
fail();
|
||||||
|
} catch (IllegalArgumentException ex) {}
|
||||||
try {
|
try {
|
||||||
StringUtils.rightPad("123456", 6, null);
|
StringUtils.rightPad("123456", 6, null);
|
||||||
fail();
|
fail();
|
||||||
|
@ -492,6 +507,10 @@ public class StringUtilsTest extends TestCase {
|
||||||
assertEquals("-+-+1234", StringUtils.leftPad("1234", 8, "-+") );
|
assertEquals("-+-+1234", StringUtils.leftPad("1234", 8, "-+") );
|
||||||
assertEquals("-+~123456", StringUtils.leftPad("123456", 9, "-+~") );
|
assertEquals("-+~123456", StringUtils.leftPad("123456", 9, "-+~") );
|
||||||
assertEquals("-+123456", StringUtils.leftPad("123456", 8, "-+~") );
|
assertEquals("-+123456", StringUtils.leftPad("123456", 8, "-+~") );
|
||||||
|
try {
|
||||||
|
StringUtils.leftPad(null, 6, null);
|
||||||
|
fail();
|
||||||
|
} catch (IllegalArgumentException ex) {}
|
||||||
try {
|
try {
|
||||||
StringUtils.leftPad("123456", 6, null);
|
StringUtils.leftPad("123456", 6, null);
|
||||||
fail();
|
fail();
|
||||||
|
|
Loading…
Reference in New Issue