Thoughts? Maybe this should be renamed to "isOneTrue(boolean...)" in the
next major release?!

---------- Forwarded message ----------
From: <brit...@apache.org>
Date: 2013/10/14
Subject: svn commit: r1532031 -
/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/BooleanUtils.java
To: comm...@commons.apache.org


Author: britter
Date: Mon Oct 14 19:21:02 2013
New Revision: 1532031

URL: http://svn.apache.org/r1532031
Log:
Document (wrong?) behavior of xor methods

Modified:

commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/BooleanUtils.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=1532031&r1=1532030&r2=1532031&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 Oct 14 19:21:02 2013
@@ -1028,6 +1028,14 @@ public class BooleanUtils {
      *   BooleanUtils.xor(true, false)  = true
      * </pre>
      *
+     * <p>Note that this method behaves different from using the binary
XOR operator (^). Instead of combining the given
+     * booleans using the XOR operator from left to right, this method
counts the appearances of true in the given
+     * array. It will only return true if exactly one boolean in the given
array is true:</p>
+     * <pre>
+     *   true ^ true ^ false ^ true                 = true
+     *   BooleanUtils.xor(true, true, false, true)  = false
+     * </pre>
+     *
      * @param array  an array of {@code boolean}s
      * @return {@code true} if the xor is successful.
      * @throws IllegalArgumentException if {@code array} is {@code null}
@@ -1069,6 +1077,9 @@ public class BooleanUtils {
      *   BooleanUtils.xor(new Boolean[] { Boolean.TRUE, Boolean.FALSE })
 = Boolean.TRUE
      * </pre>
      *
+     * <p>Note that this method behaves different from using the binary
XOR operator (^). See
+     * {@link #xor(boolean...)}.</p>
+     *
      * @param array  an array of {@code Boolean}s
      * @return {@code true} if the xor is successful.
      * @throws IllegalArgumentException if {@code array} is {@code null}





-- 
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter

Reply via email to