Class BooleanUtils
Operations on boolean primitives and Boolean objects.
This class tries to handle null input gracefully.
An exception will not be thrown for a null input.
Each method documents its behaviour in more detail.
#ThreadSafe#
- Since:
- 2.0
-
Constructor Summary
ConstructorsConstructorDescriptionBooleanUtilsinstances should NOT be constructed in standard programming. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanand(boolean... array) Performs an and on a set of booleans.static BooleanPerforms an and on an array of Booleans.static intcompare(boolean x, boolean y) Compares twobooleanvalues.static booleanChecks if aBooleanvalue isfalse, handlingnullby returningfalse.static booleanisNotFalse(Boolean bool) Checks if aBooleanvalue is notfalse, handlingnullby returningtrue.static booleanChecks if aBooleanvalue is nottrue, handlingnullby returningtrue.static booleanChecks if aBooleanvalue istrue, handlingnullby returningfalse.static BooleanNegates the specified boolean.static booleanor(boolean... array) Performs an or on a set of booleans.static BooleanPerforms an or on an array of Booleans.static booleantoBoolean(int value) Converts an int to a boolean using the convention thatzeroisfalse.static booleantoBoolean(int value, int trueValue, int falseValue) Converts an int to a boolean specifying the conversion values.static booleanConverts a Boolean to a boolean handlingnullby returningfalse.static booleanConverts an Integer to a boolean specifying the conversion values.static booleanConverts a String to a boolean (optimised for performance).static booleanConverts a String to a Boolean throwing an exception if no match found.static booleantoBooleanDefaultIfNull(Boolean bool, boolean valueIfNull) Converts a Boolean to a boolean handlingnull.static BooleantoBooleanObject(int value) Converts an int to a Boolean using the convention thatzeroisfalse.static BooleantoBooleanObject(int value, int trueValue, int falseValue, int nullValue) Converts an int to a Boolean specifying the conversion values.static BooleantoBooleanObject(Integer value) Converts an Integer to a Boolean using the convention thatzeroisfalse.static BooleantoBooleanObject(Integer value, Integer trueValue, Integer falseValue, Integer nullValue) Converts an Integer to a Boolean specifying the conversion values.static BooleantoBooleanObject(String str) Converts a String to a Boolean.static BooleantoBooleanObject(String str, String trueString, String falseString, String nullString) Converts a String to a Boolean throwing an exception if no match.static inttoInteger(boolean bool) Converts a boolean to an int using the convention thatzeroisfalse.static inttoInteger(boolean bool, int trueValue, int falseValue) Converts a boolean to an int specifying the conversion values.static intConverts a Boolean to an int specifying the conversion values.static IntegertoIntegerObject(boolean bool) Converts a boolean to an Integer using the convention thatzeroisfalse.static IntegertoIntegerObject(boolean bool, Integer trueValue, Integer falseValue) Converts a boolean to an Integer specifying the conversion values.static IntegertoIntegerObject(Boolean bool) Converts a Boolean to a Integer using the convention thatzeroisfalse.static IntegertoIntegerObject(Boolean bool, Integer trueValue, Integer falseValue, Integer nullValue) Converts a Boolean to an Integer specifying the conversion values.static StringConverts a boolean to a String returning one of the input Strings.static StringConverts a Boolean to a String returning one of the input Strings.static StringtoStringOnOff(boolean bool) Converts a boolean to a String returning'on'or'off'.static StringtoStringOnOff(Boolean bool) Converts a Boolean to a String returning'on','off', ornull.static StringtoStringTrueFalse(boolean bool) Converts a boolean to a String returning'true'or'false'.static StringtoStringTrueFalse(Boolean bool) Converts a Boolean to a String returning'true','false', ornull.static StringtoStringYesNo(boolean bool) Converts a boolean to a String returning'yes'or'no'.static StringtoStringYesNo(Boolean bool) Converts a Boolean to a String returning'yes','no', ornull.static booleanxor(boolean... array) Performs an xor on a set of booleans.static BooleanPerforms an xor on an array of Booleans.
-
Constructor Details
-
BooleanUtils
public BooleanUtils()BooleanUtilsinstances should NOT be constructed in standard programming. Instead, the class should be used asBooleanUtils.negate(true);.This constructor is public to permit tools that require a JavaBean instance to operate.
-
-
Method Details
-
negate
Negates the specified boolean.
If
nullis passed in,nullwill be returned.NOTE: This returns null and will throw a NullPointerException if unboxed to a boolean.
BooleanUtils.negate(Boolean.TRUE) = Boolean.FALSE; BooleanUtils.negate(Boolean.FALSE) = Boolean.TRUE; BooleanUtils.negate(null) = null;
- Parameters:
bool- the Boolean to negate, may be null- Returns:
- the negated Boolean, or
nullifnullinput
-
isTrue
Checks if a
Booleanvalue istrue, handlingnullby returningfalse.BooleanUtils.isTrue(Boolean.TRUE) = true BooleanUtils.isTrue(Boolean.FALSE) = false BooleanUtils.isTrue(null) = false
- Parameters:
bool- the boolean to check, null returnsfalse- Returns:
trueonly if the input is non-null and true- Since:
- 2.1
-
isNotTrue
Checks if a
Booleanvalue is nottrue, handlingnullby returningtrue.BooleanUtils.isNotTrue(Boolean.TRUE) = false BooleanUtils.isNotTrue(Boolean.FALSE) = true BooleanUtils.isNotTrue(null) = true
- Parameters:
bool- the boolean to check, null returnstrue- Returns:
trueif the input is null or false- Since:
- 2.3
-
isFalse
Checks if a
Booleanvalue isfalse, handlingnullby returningfalse.BooleanUtils.isFalse(Boolean.TRUE) = false BooleanUtils.isFalse(Boolean.FALSE) = true BooleanUtils.isFalse(null) = false
- Parameters:
bool- the boolean to check, null returnsfalse- Returns:
trueonly if the input is non-null and false- Since:
- 2.1
-
isNotFalse
Checks if a
Booleanvalue is notfalse, handlingnullby returningtrue.BooleanUtils.isNotFalse(Boolean.TRUE) = true BooleanUtils.isNotFalse(Boolean.FALSE) = false BooleanUtils.isNotFalse(null) = true
- Parameters:
bool- the boolean to check, null returnstrue- Returns:
trueif the input is null or true- Since:
- 2.3
-
toBoolean
Converts a Boolean to a boolean handling
nullby returningfalse.BooleanUtils.toBoolean(Boolean.TRUE) = true BooleanUtils.toBoolean(Boolean.FALSE) = false BooleanUtils.toBoolean(null) = false
- Parameters:
bool- the boolean to convert- Returns:
trueorfalse,nullreturnsfalse
-
toBooleanDefaultIfNull
Converts a Boolean to a boolean handling
null.BooleanUtils.toBooleanDefaultIfNull(Boolean.TRUE, false) = true BooleanUtils.toBooleanDefaultIfNull(Boolean.FALSE, true) = false BooleanUtils.toBooleanDefaultIfNull(null, true) = true
- Parameters:
bool- the boolean to convertvalueIfNull- the boolean value to return ifnull- Returns:
trueorfalse
-
toBoolean
public static boolean toBoolean(int value) Converts an int to a boolean using the convention that
zeroisfalse.BooleanUtils.toBoolean(0) = false BooleanUtils.toBoolean(1) = true BooleanUtils.toBoolean(2) = true
- Parameters:
value- the int to convert- Returns:
trueif non-zero,falseif zero
-
toBooleanObject
Converts an int to a Boolean using the convention that
zeroisfalse.BooleanUtils.toBoolean(0) = Boolean.FALSE BooleanUtils.toBoolean(1) = Boolean.TRUE BooleanUtils.toBoolean(2) = Boolean.TRUE
- Parameters:
value- the int to convert- Returns:
- Boolean.TRUE if non-zero, Boolean.FALSE if zero,
nullifnull
-
toBooleanObject
Converts an Integer to a Boolean using the convention that
zeroisfalse.nullwill be converted tonull.NOTE: This returns null and will throw a NullPointerException if unboxed to a boolean.
BooleanUtils.toBoolean(Integer.valueOf(0)) = Boolean.FALSE BooleanUtils.toBoolean(Integer.valueOf(1)) = Boolean.TRUE BooleanUtils.toBoolean(Integer.valueOf(null)) = null
- Parameters:
value- the Integer to convert- Returns:
- Boolean.TRUE if non-zero, Boolean.FALSE if zero,
nullifnullinput
-
toBoolean
public static boolean toBoolean(int value, int trueValue, int falseValue) Converts an int to a boolean specifying the conversion values.
BooleanUtils.toBoolean(0, 1, 0) = false BooleanUtils.toBoolean(1, 1, 0) = true BooleanUtils.toBoolean(2, 1, 2) = false BooleanUtils.toBoolean(2, 2, 0) = true
- Parameters:
value- the Integer to converttrueValue- the value to match fortruefalseValue- the value to match forfalse- Returns:
trueorfalse- Throws:
IllegalArgumentException- if no match
-
toBoolean
Converts an Integer to a boolean specifying the conversion values.
BooleanUtils.toBoolean(Integer.valueOf(0), Integer.valueOf(1), Integer.valueOf(0)) = false BooleanUtils.toBoolean(Integer.valueOf(1), Integer.valueOf(1), Integer.valueOf(0)) = true BooleanUtils.toBoolean(Integer.valueOf(2), Integer.valueOf(1), Integer.valueOf(2)) = false BooleanUtils.toBoolean(Integer.valueOf(2), Integer.valueOf(2), Integer.valueOf(0)) = true BooleanUtils.toBoolean(null, null, Integer.valueOf(0)) = true
- Parameters:
value- the Integer to converttrueValue- the value to match fortrue, may benullfalseValue- the value to match forfalse, may benull- Returns:
trueorfalse- Throws:
IllegalArgumentException- if no match
-
toBooleanObject
Converts an int to a Boolean specifying the conversion values.
NOTE: This returns null and will throw a NullPointerException if unboxed to a boolean.
BooleanUtils.toBooleanObject(0, 0, 2, 3) = Boolean.TRUE BooleanUtils.toBooleanObject(2, 1, 2, 3) = Boolean.FALSE BooleanUtils.toBooleanObject(3, 1, 2, 3) = null
- Parameters:
value- the Integer to converttrueValue- the value to match fortruefalseValue- the value to match forfalsenullValue- the value to to match fornull- Returns:
- Boolean.TRUE, Boolean.FALSE, or
null - Throws:
IllegalArgumentException- if no match
-
toBooleanObject
public static Boolean toBooleanObject(Integer value, Integer trueValue, Integer falseValue, Integer nullValue) Converts an Integer to a Boolean specifying the conversion values.
NOTE: This returns null and will throw a NullPointerException if unboxed to a boolean.
BooleanUtils.toBooleanObject(Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(2), Integer.valueOf(3)) = Boolean.TRUE BooleanUtils.toBooleanObject(Integer.valueOf(2), Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3)) = Boolean.FALSE BooleanUtils.toBooleanObject(Integer.valueOf(3), Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3)) = null
- Parameters:
value- the Integer to converttrueValue- the value to match fortrue, may benullfalseValue- the value to match forfalse, may benullnullValue- the value to to match fornull, may benull- Returns:
- Boolean.TRUE, Boolean.FALSE, or
null - Throws:
IllegalArgumentException- if no match
-
toInteger
public static int toInteger(boolean bool) Converts a boolean to an int using the convention that
zeroisfalse.BooleanUtils.toInteger(true) = 1 BooleanUtils.toInteger(false) = 0
- Parameters:
bool- the boolean to convert- Returns:
- one if
true, zero iffalse
-
toIntegerObject
Converts a boolean to an Integer using the convention that
zeroisfalse.BooleanUtils.toIntegerObject(true) = Integer.valueOf(1) BooleanUtils.toIntegerObject(false) = Integer.valueOf(0)
- Parameters:
bool- the boolean to convert- Returns:
- one if
true, zero iffalse
-
toIntegerObject
Converts a Boolean to a Integer using the convention that
zeroisfalse.nullwill be converted tonull.BooleanUtils.toIntegerObject(Boolean.TRUE) = Integer.valueOf(1) BooleanUtils.toIntegerObject(Boolean.FALSE) = Integer.valueOf(0)
- Parameters:
bool- the Boolean to convert- Returns:
- one if Boolean.TRUE, zero if Boolean.FALSE,
nullifnull
-
toInteger
public static int toInteger(boolean bool, int trueValue, int falseValue) Converts a boolean to an int specifying the conversion values.
BooleanUtils.toInteger(true, 1, 0) = 1 BooleanUtils.toInteger(false, 1, 0) = 0
- Parameters:
bool- the to converttrueValue- the value to return iftruefalseValue- the value to return iffalse- Returns:
- the appropriate value
-
toInteger
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 BooleanUtils.toInteger(null, 1, 0, 2) = 2
- Parameters:
bool- the Boolean to converttrueValue- the value to return iftruefalseValue- the value to return iffalsenullValue- the value to return ifnull- Returns:
- the appropriate value
-
toIntegerObject
Converts a boolean to an Integer specifying the conversion values.
BooleanUtils.toIntegerObject(true, Integer.valueOf(1), Integer.valueOf(0)) = Integer.valueOf(1) BooleanUtils.toIntegerObject(false, Integer.valueOf(1), Integer.valueOf(0)) = Integer.valueOf(0)
- Parameters:
bool- the to converttrueValue- the value to return iftrue, may benullfalseValue- the value to return iffalse, may benull- Returns:
- the appropriate value
-
toIntegerObject
public static Integer toIntegerObject(Boolean bool, Integer trueValue, Integer falseValue, Integer nullValue) Converts a Boolean to an Integer specifying the conversion values.
BooleanUtils.toIntegerObject(Boolean.TRUE, Integer.valueOf(1), Integer.valueOf(0), Integer.valueOf(2)) = Integer.valueOf(1) BooleanUtils.toIntegerObject(Boolean.FALSE, Integer.valueOf(1), Integer.valueOf(0), Integer.valueOf(2)) = Integer.valueOf(0) BooleanUtils.toIntegerObject(null, Integer.valueOf(1), Integer.valueOf(0), Integer.valueOf(2)) = Integer.valueOf(2)
- Parameters:
bool- the Boolean to converttrueValue- the value to return iftrue, may benullfalseValue- the value to return iffalse, may benullnullValue- the value to return ifnull, may benull- Returns:
- the appropriate value
-
toBooleanObject
Converts a String to a Boolean.
'true','on','y','t'or'yes'(case insensitive) will returntrue.'false','off','n','f'or'no'(case insensitive) will returnfalse. Otherwise,nullis returned.NOTE: This returns null and will throw a NullPointerException if unboxed to a boolean.
// N.B. case is not significant BooleanUtils.toBooleanObject(null) = null BooleanUtils.toBooleanObject("true") = Boolean.TRUE BooleanUtils.toBooleanObject("T") = Boolean.TRUE // i.e. T[RUE] BooleanUtils.toBooleanObject("false") = Boolean.FALSE BooleanUtils.toBooleanObject("f") = Boolean.FALSE // i.e. f[alse] BooleanUtils.toBooleanObject("No") = Boolean.FALSE BooleanUtils.toBooleanObject("n") = Boolean.FALSE // i.e. n[o] BooleanUtils.toBooleanObject("on") = Boolean.TRUE BooleanUtils.toBooleanObject("ON") = Boolean.TRUE BooleanUtils.toBooleanObject("off") = Boolean.FALSE BooleanUtils.toBooleanObject("oFf") = Boolean.FALSE BooleanUtils.toBooleanObject("yes") = Boolean.TRUE BooleanUtils.toBooleanObject("Y") = Boolean.TRUE // i.e. Y[ES] BooleanUtils.toBooleanObject("blue") = null BooleanUtils.toBooleanObject("true ") = null // trailing space (too long) BooleanUtils.toBooleanObject("ono") = null // does not match on or no- Parameters:
str- the String to check; upper and lower case are treated as the same- Returns:
- the Boolean value of the string,
nullif no match ornullinput
-
toBooleanObject
public static Boolean toBooleanObject(String str, String trueString, String falseString, String nullString) Converts a String to a Boolean throwing an exception if no match.
NOTE: This returns null and will throw a NullPointerException if unboxed to a boolean.
BooleanUtils.toBooleanObject("true", "true", "false", "null") = Boolean.TRUE BooleanUtils.toBooleanObject("false", "true", "false", "null") = Boolean.FALSE BooleanUtils.toBooleanObject("null", "true", "false", "null") = null- Parameters:
str- the String to checktrueString- the String to match fortrue(case sensitive), may benullfalseString- the String to match forfalse(case sensitive), may benullnullString- the String to match fornull(case sensitive), may benull- Returns:
- the Boolean value of the string,
nullif either the String matchesnullStringor ifnullinput andnullStringisnull - Throws:
IllegalArgumentException- if the String doesn't match
-
toBoolean
Converts a String to a boolean (optimised for performance).
'true','on','y','t'or'yes'(case insensitive) will returntrue. Otherwise,falseis returned.This method performs 4 times faster (JDK1.4) than
Boolean.valueOf(String). However, this method accepts 'on' and 'yes', 't', 'y' as true values.BooleanUtils.toBoolean(null) = false BooleanUtils.toBoolean("true") = true BooleanUtils.toBoolean("TRUE") = true BooleanUtils.toBoolean("tRUe") = true BooleanUtils.toBoolean("on") = true BooleanUtils.toBoolean("yes") = true BooleanUtils.toBoolean("false") = false BooleanUtils.toBoolean("x gti") = false BooleanUtils.toBooleanObject("y") = true BooleanUtils.toBooleanObject("n") = false BooleanUtils.toBooleanObject("t") = true BooleanUtils.toBooleanObject("f") = false- Parameters:
str- the String to check- Returns:
- the boolean value of the string,
falseif no match or the String is null
-
toBoolean
Converts a String to a Boolean throwing an exception if no match found.
BooleanUtils.toBoolean("true", "true", "false") = true BooleanUtils.toBoolean("false", "true", "false") = false- Parameters:
str- the String to checktrueString- the String to match fortrue(case sensitive), may benullfalseString- the String to match forfalse(case sensitive), may benull- Returns:
- the boolean value of the string
- Throws:
IllegalArgumentException- if the String doesn't match
-
toStringTrueFalse
Converts a Boolean to a String returning
'true','false', ornull.BooleanUtils.toStringTrueFalse(Boolean.TRUE) = "true" BooleanUtils.toStringTrueFalse(Boolean.FALSE) = "false" BooleanUtils.toStringTrueFalse(null) = null;
- Parameters:
bool- the Boolean to check- Returns:
'true','false', ornull
-
toStringOnOff
Converts a Boolean to a String returning
'on','off', ornull.BooleanUtils.toStringOnOff(Boolean.TRUE) = "on" BooleanUtils.toStringOnOff(Boolean.FALSE) = "off" BooleanUtils.toStringOnOff(null) = null;
- Parameters:
bool- the Boolean to check- Returns:
'on','off', ornull
-
toStringYesNo
Converts a Boolean to a String returning
'yes','no', ornull.BooleanUtils.toStringYesNo(Boolean.TRUE) = "yes" BooleanUtils.toStringYesNo(Boolean.FALSE) = "no" BooleanUtils.toStringYesNo(null) = null;
- Parameters:
bool- the Boolean to check- Returns:
'yes','no', ornull
-
toString
public static String toString(Boolean bool, String trueString, String falseString, String nullString) 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" BooleanUtils.toString(null, "true", "false", null) = null;
- Parameters:
bool- the Boolean to checktrueString- the String to return iftrue, may benullfalseString- the String to return iffalse, may benullnullString- the String to return ifnull, may benull- Returns:
- one of the three input Strings
-
toStringTrueFalse
Converts a boolean to a String returning
'true'or'false'.BooleanUtils.toStringTrueFalse(true) = "true" BooleanUtils.toStringTrueFalse(false) = "false"
- Parameters:
bool- the Boolean to check- Returns:
'true','false', ornull
-
toStringOnOff
Converts a boolean to a String returning
'on'or'off'.BooleanUtils.toStringOnOff(true) = "on" BooleanUtils.toStringOnOff(false) = "off"
- Parameters:
bool- the Boolean to check- Returns:
'on','off', ornull
-
toStringYesNo
Converts a boolean to a String returning
'yes'or'no'.BooleanUtils.toStringYesNo(true) = "yes" BooleanUtils.toStringYesNo(false) = "no"
- Parameters:
bool- the Boolean to check- Returns:
'yes','no', ornull
-
toString
Converts a boolean to a String returning one of the input Strings.
BooleanUtils.toString(true, "true", "false") = "true" BooleanUtils.toString(false, "true", "false") = "false"
- Parameters:
bool- the Boolean to checktrueString- the String to return iftrue, may benullfalseString- the String to return iffalse, may benull- Returns:
- one of the two input Strings
-
and
public static boolean and(boolean... array) Performs an and on a set of booleans.
BooleanUtils.and(true, true) = true BooleanUtils.and(false, false) = false BooleanUtils.and(true, false) = false BooleanUtils.and(true, true, false) = false BooleanUtils.and(true, true, true) = true
- Parameters:
array- an array ofbooleans- Returns:
trueif the and is successful.- Throws:
IllegalArgumentException- ifarrayisnullIllegalArgumentException- ifarrayis empty.- Since:
- 3.0.1
-
and
Performs an and on an array of Booleans.
BooleanUtils.and(Boolean.TRUE, Boolean.TRUE) = Boolean.TRUE BooleanUtils.and(Boolean.FALSE, Boolean.FALSE) = Boolean.FALSE BooleanUtils.and(Boolean.TRUE, Boolean.FALSE) = Boolean.FALSE BooleanUtils.and(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE) = Boolean.TRUE BooleanUtils.and(Boolean.FALSE, Boolean.FALSE, Boolean.TRUE) = Boolean.FALSE BooleanUtils.and(Boolean.TRUE, Boolean.FALSE, Boolean.TRUE) = Boolean.FALSE
- Parameters:
array- an array ofBooleans- Returns:
trueif the and is successful.- Throws:
IllegalArgumentException- ifarrayisnullIllegalArgumentException- ifarrayis empty.IllegalArgumentException- ifarraycontains anull- Since:
- 3.0.1
-
or
public static boolean or(boolean... array) Performs an or on a set of booleans.
BooleanUtils.or(true, true) = true BooleanUtils.or(false, false) = false BooleanUtils.or(true, false) = true BooleanUtils.or(true, true, false) = true BooleanUtils.or(true, true, true) = true BooleanUtils.or(false, false, false) = false
- Parameters:
array- an array ofbooleans- Returns:
trueif the or is successful.- Throws:
IllegalArgumentException- ifarrayisnullIllegalArgumentException- ifarrayis empty.- Since:
- 3.0.1
-
or
Performs an or on an array of Booleans.
BooleanUtils.or(Boolean.TRUE, Boolean.TRUE) = Boolean.TRUE BooleanUtils.or(Boolean.FALSE, Boolean.FALSE) = Boolean.FALSE BooleanUtils.or(Boolean.TRUE, Boolean.FALSE) = Boolean.TRUE BooleanUtils.or(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE) = Boolean.TRUE BooleanUtils.or(Boolean.FALSE, Boolean.FALSE, Boolean.TRUE) = Boolean.TRUE BooleanUtils.or(Boolean.TRUE, Boolean.FALSE, Boolean.TRUE) = Boolean.TRUE BooleanUtils.or(Boolean.FALSE, Boolean.FALSE, Boolean.FALSE) = Boolean.FALSE
- Parameters:
array- an array ofBooleans- Returns:
trueif the or is successful.- Throws:
IllegalArgumentException- ifarrayisnullIllegalArgumentException- ifarrayis empty.IllegalArgumentException- ifarraycontains anull- Since:
- 3.0.1
-
xor
public static boolean xor(boolean... array) Performs an xor on a set of booleans.
BooleanUtils.xor(true, true) = false BooleanUtils.xor(false, false) = false BooleanUtils.xor(true, false) = true
- Parameters:
array- an array ofbooleans- Returns:
trueif the xor is successful.- Throws:
IllegalArgumentException- ifarrayisnullIllegalArgumentException- ifarrayis empty.
-
xor
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 BooleanUtils.xor(new Boolean[] { Boolean.TRUE, Boolean.FALSE }) = Boolean.TRUE- Parameters:
array- an array ofBooleans- Returns:
trueif the xor is successful.- Throws:
IllegalArgumentException- ifarrayisnullIllegalArgumentException- ifarrayis empty.IllegalArgumentException- ifarraycontains anull
-
compare
public static int compare(boolean x, boolean y) Compares two
booleanvalues. This is the same functionality as provided in Java 7.- Parameters:
x- the firstbooleanto comparey- the secondbooleanto compare- Returns:
- the value
0ifx == y; a value less than0if!x && y; and a value greater than0ifx && !y - Since:
- 3.4
-