commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject svn commit: r1133336 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/BooleanUtils.java test/java/org/apache/commons/lang3/BooleanUtilsTest.java
Date Wed, 08 Jun 2011 10:51:28 GMT
Author: scolebourne
Date: Wed Jun  8 10:51:27 2011
New Revision: 1133336

URL: http://svn.apache.org/viewvc?rev=1133336&view=rev
Log:
Fix Javadoc bug; Improve implementation and tests

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=1133336&r1=1133335&r2=1133336&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 Wed
Jun  8 10:51:27 2011
@@ -698,8 +698,6 @@ public class BooleanUtils {
     /**
      * <p>Converts a String to a Boolean throwing an exception if no match found.</p>
      *
-     * <p>null is returned if there is no match.</p>
-     *
      * <pre>
      *   BooleanUtils.toBoolean("true", "true", "false")  = true
      *   BooleanUtils.toBoolean("false", "true", "false") = false
@@ -712,17 +710,16 @@ public class BooleanUtils {
      * @throws IllegalArgumentException if the String doesn't match
      */
     public static boolean toBoolean(String str, String trueString, String falseString) {
-        if (str == null) {
-            if (trueString == null) {
+        if (str == trueString) {
+            return true;
+        } else if (str == falseString) {
+            return false;
+        } else if (str != null) {
+            if (str.equals(trueString)) {
                 return true;
-            }
-            if (falseString == null) {
+            } else if (str.equals(falseString)) {
                 return false;
             }
-        } else if (str.equals(trueString)) {
-            return true;
-        } else if (str.equals(falseString)) {
-            return false;
         }
         // no match
         throw new IllegalArgumentException("The String did not match either specified value");

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=1133336&r1=1133335&r2=1133336&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
Wed Jun  8 10:51:27 2011
@@ -327,13 +327,10 @@ public class BooleanUtilsTest extends Te
     public void test_toBoolean_String_String_String() {
         assertEquals(true, BooleanUtils.toBoolean((String) null, null, "N"));
         assertEquals(false, BooleanUtils.toBoolean((String) null, "Y", null));
-        try {
-            BooleanUtils.toBooleanObject((String) null, "Y", "N", "U");
-            fail();
-        } catch (IllegalArgumentException ex) {}
-        
         assertEquals(true, BooleanUtils.toBoolean("Y", "Y", "N"));
+        assertEquals(true, BooleanUtils.toBoolean("Y", new String("Y"), new String("N")));
         assertEquals(false, BooleanUtils.toBoolean("N", "Y", "N"));
+        assertEquals(false, BooleanUtils.toBoolean("N", new String("Y"), new String("N")));
         try {
             BooleanUtils.toBoolean(null, "Y", "N");
             fail();
@@ -342,6 +339,9 @@ public class BooleanUtilsTest extends Te
             BooleanUtils.toBoolean("X", "Y", "N");
             fail();
         } catch (IllegalArgumentException ex) {}
+        assertEquals(true, BooleanUtils.toBoolean((String) null, null, null));
+        assertEquals(true, BooleanUtils.toBoolean("Y", "Y", "Y"));
+        assertEquals(true, BooleanUtils.toBoolean("Y", new String("Y"), new String("Y")));
     }
 
     //-----------------------------------------------------------------------



Mime
View raw message