[
https://issues.apache.org/jira/browse/LANG-922?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13799265#comment-13799265
]
Matt Benson commented on LANG-922:
----------------------------------
To implement the idea of {{isExactlyOneTrue()}} you _would_ have to scan the
entire array. As to the use case argument, I have seen code that checks
whether a majority of items are {{true}}, thus could extrapolate:
{code}
public class ArrayUtils {
public static <T> double relativeFrequency(T item, T... array) {
if (isEmpty(array)) {
return Double.NaN;
}
final int frequency = frequency(item, array);
return (double) frequency / array.length;
}
public static <T> int frequency(T item, T... array) {
if (array == null) {
return 0;
}
int result = 0;
for (T t : array) {
if (ObjectUtils.equals(item, t)) {
result++;
}
}
return result;
}
}
{code}
Which might conceivably used for fuzzy type operations.
> Add isOneTrue(booleans...) to BooleanUtils to preserve old behavior of
> BooleanUtils.xor(booleans...)
> ----------------------------------------------------------------------------------------------------
>
> Key: LANG-922
> URL: https://issues.apache.org/jira/browse/LANG-922
> Project: Commons Lang
> Issue Type: Bug
> Components: lang.*
> Reporter: Benedikt Ritter
> Assignee: Benedikt Ritter
> Fix For: 3.2
>
>
> The old implementation (prior to r1532476) of BooleanUtils.xor(boolean...)
> checked if the provided array contained exactly one boolean with value true.
> This was changed because it is not the correct behavior for an XOR operation.
> To preserve the behavior we should add BooleanUtils.isOneTrue(boolean...) and
> BooleanUtils.isOneTrue(Boolean...) (and possibly the equivalents for
> isOneFalse).
--
This message was sent by Atlassian JIRA
(v6.1#6144)