@ NullSafe public static boolean xor ( Boolean ... values ) { boolean result = false ; // guilty until proven innocent. for ( Boolean value : nullSafeArray ( values , Boolean . class ) ) { boolean primitiveValue = valueOf ( value ) ; if ( result && primitiveValue ) { return false ; // short-circuit if we find more than 1 true value } result |= primitiveValue ; } return result ; }
Performs a logical exclusive OR on the array of Boolean values and returns true if and only if the Boolean array is not null and 1 and only 1 Boolean wrapper object evaluates to true as determined by the BooleanUtils . valueof method .