Applying Joanne's subsequent patch from LANG-875 making appendIfMissing use the same logic for null as endsWith (by reusing endsWith).

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1476070 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2013-04-26 06:51:07 +00:00
parent f364bd1f14
commit 0e7401897a
2 changed files with 11 additions and 3 deletions

View File

@ -7125,7 +7125,7 @@ public class StringUtils {
}
if (suffixes != null && suffixes.length > 0) {
for (final CharSequence s : suffixes) {
if (isEmpty(s) || endsWith(str, s, ignoreCase)) {
if (endsWith(str, s, ignoreCase)) {
return str;
}
}
@ -7150,6 +7150,7 @@ public class StringUtils {
* StringUtils.appendIfMissing(null, null, null) = null
* StringUtils.appendIfMissing("abc", null, null) = "abc"
* StringUtils.appendIfMissing("", "xyz", null) = "xyz"
* StringUtils.appendIfMissing("abc", "xyz", new CharSequence[]{null}) = "abcxyz"
* StringUtils.appendIfMissing("abc", "xyz", "") = "abc"
* StringUtils.appendIfMissing("abc", "xyz", "mno") = "abcxyz"
* StringUtils.appendIfMissing("abcxyz", "xyz", "mno") = "abcxyz"
@ -7187,7 +7188,8 @@ public class StringUtils {
* StringUtils.appendIfMissingIgnoreCase(null, null, null) = null
* StringUtils.appendIfMissingIgnoreCase("abc", null, null) = "abc"
* StringUtils.appendIfMissingIgnoreCase("", "xyz", null) = "xyz"
* StringUtils.appendIfMissingIgnoreCase("abc", "xyz", "") = "a"
* StringUtils.appendIfMissingIgnoreCase("abc", "xyz", new CharSequence[]{null}) = "abcxyz"
* StringUtils.appendIfMissingIgnoreCase("abc", "xyz", "") = "abc"
* StringUtils.appendIfMissingIgnoreCase("abc", "xyz", "mno") = "axyz"
* StringUtils.appendIfMissingIgnoreCase("abcxyz", "xyz", "mno") = "abcxyz"
* StringUtils.appendIfMissingIgnoreCase("abcmno", "xyz", "mno") = "abcmno"
@ -7224,7 +7226,7 @@ public class StringUtils {
}
if (prefixes != null && prefixes.length > 0) {
for (final CharSequence p : prefixes) {
if (isEmpty(p) || startsWith(str, p, ignoreCase)) {
if (startsWith(str, p, ignoreCase)) {
return str;
}
}
@ -7249,6 +7251,7 @@ public class StringUtils {
* StringUtils.prependIfMissing(null, null, null) = null
* StringUtils.prependIfMissing("abc", null, null) = "abc"
* StringUtils.prependIfMissing("", "xyz", null) = "xyz"
* StringUtils.prependIfMissing("abc", "xyz", new CharSequence[]{null}) = "xyzabc"
* StringUtils.prependIfMissing("abc", "xyz", "") = "abc"
* StringUtils.prependIfMissing("abc", "xyz", "mno") = "xyzabc"
* StringUtils.prependIfMissing("xyzabc", "xyz", "mno") = "xyzabc"
@ -7286,6 +7289,7 @@ public class StringUtils {
* StringUtils.prependIfMissingIgnoreCase(null, null, null) = null
* StringUtils.prependIfMissingIgnoreCase("abc", null, null) = "abc"
* StringUtils.prependIfMissingIgnoreCase("", "xyz", null) = "xyz"
* StringUtils.prependIfMissingIgnoreCase("abc", "xyz", new CharSequence[]{null}) = "xyzabc"
* StringUtils.prependIfMissingIgnoreCase("abc", "xyz", "") = "abc"
* StringUtils.prependIfMissingIgnoreCase("abc", "xyz", "mno") = "xyzabc"
* StringUtils.prependIfMissingIgnoreCase("xyzabc", "xyz", "mno") = "xyzabc"

View File

@ -2239,6 +2239,7 @@ public class StringUtilsTest {
assertEquals("appendIfMissing(null,null,null)", null, StringUtils.appendIfMissing(null,null,(CharSequence[]) null));
assertEquals("appendIfMissing(abc,null,null)", "abc", StringUtils.appendIfMissing("abc",null,(CharSequence[]) null));
assertEquals("appendIfMissing(\"\",xyz,null))", "xyz", StringUtils.appendIfMissing("","xyz",(CharSequence[]) null));
assertEquals("appendIfMissing(abc,xyz,{null})", "abcxyz", StringUtils.appendIfMissing("abc","xyz",new CharSequence[]{null}));
assertEquals("appendIfMissing(abc,xyz,\"\")", "abc", StringUtils.appendIfMissing("abc","xyz",""));
assertEquals("appendIfMissing(abc,xyz,mno)", "abcxyz", StringUtils.appendIfMissing("abc","xyz","mno"));
assertEquals("appendIfMissing(abcxyz,xyz,mno)", "abcxyz", StringUtils.appendIfMissing("abcxyz","xyz","mno"));
@ -2262,6 +2263,7 @@ public class StringUtilsTest {
assertEquals("appendIfMissingIgnoreCase(null,null,null)", null, StringUtils.appendIfMissingIgnoreCase(null,null,(CharSequence[]) null));
assertEquals("appendIfMissingIgnoreCase(abc,null,null)", "abc", StringUtils.appendIfMissingIgnoreCase("abc",null,(CharSequence[]) null));
assertEquals("appendIfMissingIgnoreCase(\"\",xyz,null)", "xyz", StringUtils.appendIfMissingIgnoreCase("","xyz",(CharSequence[]) null));
assertEquals("appendIfMissingIgnoreCase(abc,xyz,{null})", "abcxyz", StringUtils.appendIfMissingIgnoreCase("abc","xyz",new CharSequence[]{null}));
assertEquals("appendIfMissingIgnoreCase(abc,xyz,\"\")", "abc", StringUtils.appendIfMissingIgnoreCase("abc","xyz",""));
assertEquals("appendIfMissingIgnoreCase(abc,xyz,mno)", "abcxyz", StringUtils.appendIfMissingIgnoreCase("abc","xyz","mno"));
assertEquals("appendIfMissingIgnoreCase(abcxyz,xyz,mno)", "abcxyz", StringUtils.appendIfMissingIgnoreCase("abcxyz","xyz","mno"));
@ -2285,6 +2287,7 @@ public class StringUtilsTest {
assertEquals("prependIfMissing(null,null null)", null, StringUtils.prependIfMissing(null,null,(CharSequence[]) null));
assertEquals("prependIfMissing(abc,null,null)", "abc", StringUtils.prependIfMissing("abc",null,(CharSequence[]) null));
assertEquals("prependIfMissing(\"\",xyz,null)", "xyz", StringUtils.prependIfMissing("","xyz",(CharSequence[]) null));
assertEquals("prependIfMissing(abc,xyz,{null})","xyzabc", StringUtils.prependIfMissing("abc","xyz",new CharSequence[]{null}));
assertEquals("prependIfMissing(abc,xyz,\"\")","abc", StringUtils.prependIfMissing("abc","xyz",""));
assertEquals("prependIfMissing(abc,xyz,mno)","xyzabc", StringUtils.prependIfMissing("abc","xyz","mno"));
assertEquals("prependIfMissing(xyzabc,xyz,mno)", "xyzabc", StringUtils.prependIfMissing("xyzabc","xyz","mno"));
@ -2308,6 +2311,7 @@ public class StringUtilsTest {
assertEquals("prependIfMissingIgnoreCase(null,null null)", null, StringUtils.prependIfMissingIgnoreCase(null,null,(CharSequence[]) null));
assertEquals("prependIfMissingIgnoreCase(abc,null,null)", "abc", StringUtils.prependIfMissingIgnoreCase("abc",null,(CharSequence[]) null));
assertEquals("prependIfMissingIgnoreCase(\"\",xyz,null)", "xyz", StringUtils.prependIfMissingIgnoreCase("","xyz",(CharSequence[]) null));
assertEquals("prependIfMissingIgnoreCase(abc,xyz,{null})","xyzabc", StringUtils.prependIfMissingIgnoreCase("abc","xyz",new CharSequence[]{null}));
assertEquals("prependIfMissingIgnoreCase(abc,xyz,\"\")","abc", StringUtils.prependIfMissingIgnoreCase("abc","xyz",""));
assertEquals("prependIfMissingIgnoreCase(abc,xyz,mno)","xyzabc", StringUtils.prependIfMissingIgnoreCase("abc","xyz","mno"));
assertEquals("prependIfMissingIgnoreCase(xyzabc,xyz,mno)", "xyzabc", StringUtils.prependIfMissingIgnoreCase("xyzabc","xyz","mno"));