commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r996421 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/BooleanUtils.java test/java/org/apache/commons/lang3/BooleanUtilsTest.java
Date Mon, 13 Sep 2010 05:36:39 GMT
Author: bayard
Date: Mon Sep 13 05:36:39 2010
New Revision: 996421

URL: http://svn.apache.org/viewvc?rev=996421&view=rev
Log:
Adding t/f and y/n options to toBooleanObject(String). LANG-649

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/BooleanUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/BooleanUtilsTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/BooleanUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/BooleanUtils.java?rev=996421&r1=996420&r2=996421&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/BooleanUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/BooleanUtils.java Mon
Sep 13 05:36:39 2010
@@ -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);

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/BooleanUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/BooleanUtilsTest.java?rev=996421&r1=996420&r2=996421&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/BooleanUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/BooleanUtilsTest.java
Mon Sep 13 05:36:39 2010
@@ -241,6 +241,17 @@ public class BooleanUtilsTest extends Te
         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"));



Mime
View raw message