In this case we should perhaps provide a #oneTrue(boolean...) method to
preserve the availability of the current behavior, which may also
occasionally have its place.

Matt


On Mon, Oct 14, 2013 at 11:10 PM, Henri Yandell <flame...@gmail.com> wrote:

> I think we treat it as a bug and fix. The code is fine for the explained
> use of an array of length 2, but fails when you move to larger chains.
> Given the common meaning of the name, I think people would have noticed if
> they'd needed xor to work for arrays > 2 and it didn't. So a) I think we
> can fix and b) I suspect it's not a highly used method.
>
> So rather than the note, I'm +1 to fixing the code.
>
> Hen
>
>
> On Mon, Oct 14, 2013 at 12:22 PM, Benedikt Ritter <brit...@apache.org
> >wrote:
>
> > 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