Adding t/f and y/n options to toBooleanObject(String). LANG-649
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@996421 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5c9ffd1d9b
commit
077df4205a
|
@ -557,6 +557,20 @@ public class BooleanUtils {
|
|||
return null;
|
||||
}
|
||||
switch (str.length()) {
|
||||
case 1: {
|
||||
char ch0 = str.charAt(0);
|
||||
if ((ch0 == 'y' || ch0 == 'Y') ||
|
||||
(ch0 == 't' || ch0 == 'T'))
|
||||
{
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
if ((ch0 == 'n' || ch0 == 'N') ||
|
||||
(ch0 == 'f' || ch0 == 'F'))
|
||||
{
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
char ch0 = str.charAt(0);
|
||||
char ch1 = str.charAt(1);
|
||||
|
|
|
@ -241,6 +241,17 @@ public class BooleanUtilsTest extends TestCase {
|
|||
assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("ON"));
|
||||
assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("YES"));
|
||||
assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("TruE"));
|
||||
assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("TruE"));
|
||||
|
||||
assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("y"));
|
||||
assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("Y"));
|
||||
assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("t"));
|
||||
assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("T"));
|
||||
assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("f"));
|
||||
assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("F"));
|
||||
assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("n"));
|
||||
assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("N"));
|
||||
assertEquals(null, BooleanUtils.toBooleanObject("z"));
|
||||
|
||||
assertEquals(null, BooleanUtils.toBooleanObject("ab"));
|
||||
assertEquals(null, BooleanUtils.toBooleanObject("yoo"));
|
||||
|
|
Loading…
Reference in New Issue