diff --git a/src/main/java/org/apache/commons/lang3/BooleanUtils.java b/src/main/java/org/apache/commons/lang3/BooleanUtils.java index 981beccb0..14f247db7 100644 --- a/src/main/java/org/apache/commons/lang3/BooleanUtils.java +++ b/src/main/java/org/apache/commons/lang3/BooleanUtils.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,7 +24,7 @@ import org.apache.commons.lang3.math.NumberUtils; *

This class tries to handle {@code null} input gracefully. * An exception will not be thrown for a {@code null} input. * Each method documents its behaviour in more detail.

- * + * *

#ThreadSafe#

* @since 2.0 * @version $Id$ @@ -46,7 +46,7 @@ public class BooleanUtils { //-------------------------------------------------------------------------- /** *

Negates the specified boolean.

- * + * *

If {@code null} is passed in, {@code null} will be returned.

* *

NOTE: This returns null and will throw a NullPointerException if autoboxed to a boolean.

@@ -56,7 +56,7 @@ public class BooleanUtils { * BooleanUtils.negate(Boolean.FALSE) = Boolean.TRUE; * BooleanUtils.negate(null) = null; * - * + * * @param bool the Boolean to negate, may be null * @return the negated Boolean, or {@code null} if {@code null} input */ @@ -66,7 +66,7 @@ public class BooleanUtils { } return bool.booleanValue() ? Boolean.FALSE : Boolean.TRUE; } - + // boolean Boolean methods //----------------------------------------------------------------------- /** @@ -158,10 +158,10 @@ public class BooleanUtils { public static boolean toBoolean(Boolean bool) { return bool != null && bool.booleanValue(); } - + /** *

Converts a Boolean to a boolean handling {@code null}.

- * + * *
      *   BooleanUtils.toBooleanDefaultIfNull(Boolean.TRUE, false) = true
      *   BooleanUtils.toBooleanDefaultIfNull(Boolean.FALSE, true) = false
@@ -178,13 +178,13 @@ public class BooleanUtils {
         }
         return bool.booleanValue();
     }
-    
+
     // Integer to Boolean methods
     //-----------------------------------------------------------------------
     /**
      * 

Converts an int to a boolean using the convention that {@code zero} * is {@code false}.

- * + * *
      *   BooleanUtils.toBoolean(0) = false
      *   BooleanUtils.toBoolean(1) = true
@@ -198,11 +198,11 @@ public class BooleanUtils {
     public static boolean toBoolean(int value) {
         return value != 0;
     }
-    
+
     /**
      * 

Converts an int to a Boolean using the convention that {@code zero} * is {@code false}.

- * + * *
      *   BooleanUtils.toBoolean(0) = Boolean.FALSE
      *   BooleanUtils.toBoolean(1) = Boolean.TRUE
@@ -216,11 +216,11 @@ public class BooleanUtils {
     public static Boolean toBooleanObject(int value) {
         return value == 0 ? Boolean.FALSE : Boolean.TRUE;
     }
-    
+
     /**
      * 

Converts an Integer to a Boolean using the convention that {@code zero} * is {@code false}.

- * + * *

{@code null} will be converted to {@code null}.

* *

NOTE: This returns null and will throw a NullPointerException if autoboxed to a boolean.

@@ -241,10 +241,10 @@ public class BooleanUtils { } return value.intValue() == 0 ? Boolean.FALSE : Boolean.TRUE; } - + /** *

Converts an int to a boolean specifying the conversion values.

- * + * *
      *   BooleanUtils.toBoolean(0, 1, 0) = false
      *   BooleanUtils.toBoolean(1, 1, 0) = true
@@ -268,10 +268,10 @@ public class BooleanUtils {
         // no match
         throw new IllegalArgumentException("The Integer did not match either specified value");
     }
-    
+
     /**
      * 

Converts an Integer to a boolean specifying the conversion values.

- * + * *
      *   BooleanUtils.toBoolean(new Integer(0), new Integer(1), new Integer(0)) = false
      *   BooleanUtils.toBoolean(new Integer(1), new Integer(1), new Integer(0)) = true
@@ -302,10 +302,10 @@ public class BooleanUtils {
         // no match
         throw new IllegalArgumentException("The Integer did not match either specified value");
     }
-    
+
     /**
      * 

Converts an int to a Boolean specifying the conversion values.

- * + * *

NOTE: This returns null and will throw a NullPointerException if autoboxed to a boolean.

* *
@@ -334,10 +334,10 @@ public class BooleanUtils {
         // no match
         throw new IllegalArgumentException("The Integer did not match any specified value");
     }
-    
+
     /**
      * 

Converts an Integer to a Boolean specifying the conversion values.

- * + * *

NOTE: This returns null and will throw a NullPointerException if autoboxed to a boolean.

* *
@@ -374,7 +374,7 @@ public class BooleanUtils {
         // no match
         throw new IllegalArgumentException("The Integer did not match any specified value");
     }
-    
+
     // Boolean to Integer methods
     //-----------------------------------------------------------------------
     /**
@@ -392,11 +392,11 @@ public class BooleanUtils {
     public static int toInteger(boolean bool) {
         return bool ? 1 : 0;
     }
-    
+
     /**
      * 

Converts a boolean to an Integer using the convention that * {@code zero} is {@code false}.

- * + * *
      *   BooleanUtils.toIntegerObject(true)  = new Integer(1)
      *   BooleanUtils.toIntegerObject(false) = new Integer(0)
@@ -408,7 +408,7 @@ public class BooleanUtils {
     public static Integer toIntegerObject(boolean bool) {
         return bool ? NumberUtils.INTEGER_ONE : NumberUtils.INTEGER_ZERO;
     }
-    
+
     /**
      * 

Converts a Boolean to a Integer using the convention that * {@code zero} is {@code false}.

@@ -429,10 +429,10 @@ public class BooleanUtils { } return bool.booleanValue() ? NumberUtils.INTEGER_ONE : NumberUtils.INTEGER_ZERO; } - + /** *

Converts a boolean to an int specifying the conversion values.

- * + * *
      *   BooleanUtils.toInteger(true, 1, 0)  = 1
      *   BooleanUtils.toInteger(false, 1, 0) = 0
@@ -446,10 +446,10 @@ public class BooleanUtils {
     public static int toInteger(boolean bool, int trueValue, int falseValue) {
         return bool ? trueValue : falseValue;
     }
-    
+
     /**
      * 

Converts a Boolean to an int specifying the conversion values.

- * + * *
      *   BooleanUtils.toInteger(Boolean.TRUE, 1, 0, 2)  = 1
      *   BooleanUtils.toInteger(Boolean.FALSE, 1, 0, 2) = 0
@@ -468,10 +468,10 @@ public class BooleanUtils {
         }
         return bool.booleanValue() ? trueValue : falseValue;
     }
-    
+
     /**
      * 

Converts a boolean to an Integer specifying the conversion values.

- * + * *
      *   BooleanUtils.toIntegerObject(true, new Integer(1), new Integer(0))  = new Integer(1)
      *   BooleanUtils.toIntegerObject(false, new Integer(1), new Integer(0)) = new Integer(0)
@@ -485,10 +485,10 @@ public class BooleanUtils {
     public static Integer toIntegerObject(boolean bool, Integer trueValue, Integer falseValue) {
         return bool ? trueValue : falseValue;
     }
-    
+
     /**
      * 

Converts a Boolean to an Integer specifying the conversion values.

- * + * *
      *   BooleanUtils.toIntegerObject(Boolean.TRUE, new Integer(1), new Integer(0), new Integer(2))  = new Integer(1)
      *   BooleanUtils.toIntegerObject(Boolean.FALSE, new Integer(1), new Integer(0), new Integer(2)) = new Integer(0)
@@ -507,12 +507,12 @@ public class BooleanUtils {
         }
         return bool.booleanValue() ? trueValue : falseValue;
     }
-    
+
     // String to Boolean methods
     //-----------------------------------------------------------------------
     /**
      * 

Converts a String to a Boolean.

- * + * *

{@code 'true'}, {@code 'on'} or {@code 'yes'} * (case insensitive) will return {@code true}. * {@code 'false'}, {@code 'off'} or {@code 'no'} @@ -538,7 +538,7 @@ public class BooleanUtils { public static Boolean toBooleanObject(String str) { // Previously used equalsIgnoreCase, which was fast for interned 'true'. // Non interned 'true' matched 15 times slower. - // + // // Optimisation provides same performance as before for interned 'true'. // Similar performance for null, 'false', and other strings not length 2/3/4. // 'true'/'TRUE' match 4 times slower, 'tRUE'/'True' 7 times slower. @@ -564,11 +564,11 @@ public class BooleanUtils { case 2: { char ch0 = str.charAt(0); char ch1 = str.charAt(1); - if ((ch0 == 'o' || ch0 == 'O') && + if ((ch0 == 'o' || ch0 == 'O') && (ch1 == 'n' || ch1 == 'N') ) { return Boolean.TRUE; } - if ((ch0 == 'n' || ch0 == 'N') && + if ((ch0 == 'n' || ch0 == 'N') && (ch1 == 'o' || ch1 == 'O') ) { return Boolean.FALSE; } @@ -668,11 +668,11 @@ public class BooleanUtils { //----------------------------------------------------------------------- /** *

Converts a String to a boolean (optimised for performance).

- * + * *

{@code 'true'}, {@code 'on'} or {@code 'yes'} * (case insensitive) will return {@code true}. Otherwise, * {@code false} is returned.

- * + * *

This method performs 4 times faster (JDK1.4) than * {@code Boolean.valueOf(String)}. However, this method accepts * 'on' and 'yes' as true values. @@ -694,10 +694,10 @@ public class BooleanUtils { public static boolean toBoolean(String str) { return toBooleanObject(str) == Boolean.TRUE; } - + /** *

Converts a String to a Boolean throwing an exception if no match found.

- * + * *

null is returned if there is no match.

* *
@@ -733,7 +733,7 @@ public class BooleanUtils {
     /**
      * 

Converts a Boolean to a String returning {@code 'true'}, * {@code 'false'}, or {@code null}.

- * + * *
      *   BooleanUtils.toStringTrueFalse(Boolean.TRUE)  = "true"
      *   BooleanUtils.toStringTrueFalse(Boolean.FALSE) = "false"
@@ -746,11 +746,11 @@ public class BooleanUtils {
     public static String toStringTrueFalse(Boolean bool) {
         return toString(bool, "true", "false", null);
     }
-    
+
     /**
      * 

Converts a Boolean to a String returning {@code 'on'}, * {@code 'off'}, or {@code null}.

- * + * *
      *   BooleanUtils.toStringOnOff(Boolean.TRUE)  = "on"
      *   BooleanUtils.toStringOnOff(Boolean.FALSE) = "off"
@@ -763,11 +763,11 @@ public class BooleanUtils {
     public static String toStringOnOff(Boolean bool) {
         return toString(bool, "on", "off", null);
     }
-    
+
     /**
      * 

Converts a Boolean to a String returning {@code 'yes'}, * {@code 'no'}, or {@code null}.

- * + * *
      *   BooleanUtils.toStringYesNo(Boolean.TRUE)  = "yes"
      *   BooleanUtils.toStringYesNo(Boolean.FALSE) = "no"
@@ -780,10 +780,10 @@ public class BooleanUtils {
     public static String toStringYesNo(Boolean bool) {
         return toString(bool, "yes", "no", null);
     }
-    
+
     /**
      * 

Converts a Boolean to a String returning one of the input Strings.

- * + * *
      *   BooleanUtils.toString(Boolean.TRUE, "true", "false", null)   = "true"
      *   BooleanUtils.toString(Boolean.FALSE, "true", "false", null)  = "false"
@@ -802,13 +802,13 @@ public class BooleanUtils {
         }
         return bool.booleanValue() ? trueString : falseString;
     }
-    
+
     // boolean to String methods
     //-----------------------------------------------------------------------
     /**
      * 

Converts a boolean to a String returning {@code 'true'} * or {@code 'false'}.

- * + * *
      *   BooleanUtils.toStringTrueFalse(true)   = "true"
      *   BooleanUtils.toStringTrueFalse(false)  = "false"
@@ -820,11 +820,11 @@ public class BooleanUtils {
     public static String toStringTrueFalse(boolean bool) {
         return toString(bool, "true", "false");
     }
-    
+
     /**
      * 

Converts a boolean to a String returning {@code 'on'} * or {@code 'off'}.

- * + * *
      *   BooleanUtils.toStringOnOff(true)   = "on"
      *   BooleanUtils.toStringOnOff(false)  = "off"
@@ -836,11 +836,11 @@ public class BooleanUtils {
     public static String toStringOnOff(boolean bool) {
         return toString(bool, "on", "off");
     }
-    
+
     /**
      * 

Converts a boolean to a String returning {@code 'yes'} * or {@code 'no'}.

- * + * *
      *   BooleanUtils.toStringYesNo(true)   = "yes"
      *   BooleanUtils.toStringYesNo(false)  = "no"
@@ -852,10 +852,10 @@ public class BooleanUtils {
     public static String toStringYesNo(boolean bool) {
         return toString(bool, "yes", "no");
     }
-    
+
     /**
      * 

Converts a boolean to a String returning one of the input Strings.

- * + * *
      *   BooleanUtils.toString(true, "true", "false")   = "true"
      *   BooleanUtils.toString(false, "true", "false")  = "false"
@@ -869,7 +869,7 @@ public class BooleanUtils {
     public static String toString(boolean bool, String trueString, String falseString) {
         return bool ? trueString : falseString;
     }
-    
+
     // xor methods
     // ----------------------------------------------------------------------
     /**
@@ -915,7 +915,7 @@ public class BooleanUtils {
 
     /**
      * 

Performs an xor on an array of Booleans.

- * + * *
      *   BooleanUtils.xor(new Boolean[] { Boolean.TRUE, Boolean.TRUE })   = Boolean.FALSE
      *   BooleanUtils.xor(new Boolean[] { Boolean.FALSE, Boolean.FALSE }) = Boolean.FALSE