BooleanUtils
- public class org.apache.commons.lang3.BooleanUtils[source]
Operations on boolean primitives and Boolean objects.
This class tries to handle
nullinput gracefully. An exception will not be thrown for anullinput. Each method documents its behavior in more detail.#ThreadSafe#
- Since:
2.0
Constructors
Deprecated. |
- @Deprecated public BooleanUtils()[source]
Deprecated: TODO Make private in 4.0.
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.
Fields and constants
The false String |
|
The no String |
|
The off String |
|
The on String |
|
The true String |
|
The yes String |
Methods
Performs an ‘and’ operation on a set of booleans. |
|
Performs an ‘and’ operation on an array of Booleans. |
|
Returns a new array of possible values (like an enum would). |
|
Compares two |
|
Performs the given action for each Boolean |
|
Tests whether a |
|
Tests whether a |
|
Tests whether a |
|
Tests whether a |
|
Negates the specified boolean. |
|
Performs a one-hot on an array of booleans. |
|
Performs a one-hot on an array of booleans. |
|
Performs an ‘or’ operation on a set of booleans. |
|
Performs an ‘or’ operation on an array of Booleans. |
|
Returns a new array of possible values (like an enum would). |
|
Converts an int to a boolean using the convention that |
|
Converts an int to a boolean specifying the conversion values. |
|
Converts a Boolean to a boolean handling |
|
Converts an Integer to a boolean specifying the conversion values. |
|
Converts a String to a boolean (optimized for performance). |
|
Converts a String to a Boolean throwing an exception if no match found. |
|
Converts a Boolean to a boolean handling |
|
Converts an int to a Boolean using the convention that |
|
Converts an int to a Boolean specifying the conversion values. |
|
Converts an Integer to a Boolean using the convention that |
|
Converts an Integer to a Boolean specifying the conversion values. |
|
Converts a String to a Boolean. |
|
Converts a String to a Boolean throwing an exception if no match. |
|
Converts a boolean to an int using the convention that |
|
Converts a boolean to an int specifying the conversion values. |
|
Converts a Boolean to an int specifying the conversion values. |
|
Converts a boolean to an Integer using the convention that |
|
Converts a boolean to an Integer specifying the conversion values. |
|
Converts a Boolean to an Integer using the convention that |
|
Converts a Boolean to an Integer specifying the conversion values. |
|
Converts a boolean to a String returning one of the input Strings. |
|
Converts a Boolean to a String returning one of the input Strings. |
|
Converts a boolean to a String returning |
|
Converts a Boolean to a String returning |
|
Converts a boolean to a String returning |
|
Converts a Boolean to a String returning |
|
Converts a boolean to a String returning |
|
Converts a Boolean to a String returning |
|
Returns an unmodifiable list of Booleans |
|
Performs an xor on a set of booleans. |
|
Performs an xor on an array of Booleans. |
- public static boolean and(boolean... array)[source]
Performs an ‘and’ operation 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 of
booleans- Returns:
The result of the logical ‘and’ operation. That is
falseif any of the parameters isfalseandtrueotherwise.- Throws:
java.lang.NullPointerException – Thrown if
arrayisnull.java.lang.IllegalArgumentException – Thrown if
arrayis empty.
- Since:
3.0.1
- public static Boolean and(Boolean... array)[source]
Performs an ‘and’ operation 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 BooleanUtils.and(null, null) = Boolean.FALSE
Null array elements map to false, like
Boolean.parseBoolean(null)and its callers return false.- Parameters:
array – An array of
Booleans- Returns:
The result of the logical ‘and’ operation. That is
falseif any of the parameters isfalseandtrueotherwise.- Throws:
java.lang.NullPointerException – Thrown if
arrayisnull.java.lang.IllegalArgumentException – Thrown if
arrayis empty.
- Since:
3.0.1
- public static Boolean[] booleanValues()[source]
Returns a new array of possible values (like an enum would).
- Returns:
A new array of possible values (like an enum would).
- Since:
3.12.0
- public static int compare(boolean x, boolean y)[source]
Compares two
booleanvalues. This is the same functionality as provided in Java 7.- Parameters:
x – The first
booleanto comparey – The second
booleanto compare
- Returns:
The value
0ifx == y; a value less than0if!x && y; and a value greater than0ifx && !y- Since:
3.4
- public static void forEach(Consumer<Boolean> action)[source]
Performs the given action for each Boolean
BooleanUtils#values().- Parameters:
action – The action to be performed for each element
- Since:
3.13.0
- public static boolean isFalse(Boolean bool)[source]
Tests whether 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 returns
false- Returns:
trueonly if the input is non-nullandfalse- Since:
2.1
- public static boolean isNotFalse(Boolean bool)[source]
Tests whether 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 returns
true- Returns:
trueif the input isnullortrue- Since:
2.3
- public static boolean isNotTrue(Boolean bool)[source]
Tests whether 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 returns
true- Returns:
trueif the input is null or false- Since:
2.3
- public static boolean isTrue(Boolean bool)[source]
Tests whether 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,
nullreturnsfalse- Returns:
trueonly if the input is non-null and true- Since:
2.1
- public static Boolean negate(Boolean bool)[source]
Negates the specified boolean.
If
nullis passed in,nullwill be returned.NOTE: This returns
nulland will throw aNullPointerExceptionif 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
- public static boolean oneHot(boolean... array)[source]
Performs a one-hot on an array of booleans.
This implementation returns true if one, and only one, of the supplied values is true.
See also One-hot.
- Parameters:
array – An array of
booleans- Returns:
The result of the one-hot operations
- Throws:
java.lang.NullPointerException – Thrown if
arrayisnull.java.lang.IllegalArgumentException – Thrown if
arrayis empty.
- public static Boolean oneHot(Boolean... array)[source]
Performs a one-hot on an array of booleans.
This implementation returns true if one, and only one, of the supplied values is true.
Null array elements map to false, like
Boolean.parseBoolean(null)and its callers return false.See also One-hot.
- Parameters:
array – An array of
booleans- Returns:
The result of the one-hot operations
- Throws:
java.lang.NullPointerException – Thrown if
arrayisnull.java.lang.IllegalArgumentException – Thrown if
arrayis empty.
- public static boolean or(boolean... array)[source]
Performs an ‘or’ operation 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 of
booleans- Returns:
trueif any of the arguments istrue, and it returnsfalseotherwise.- Throws:
java.lang.NullPointerException – Thrown if
arrayisnull.java.lang.IllegalArgumentException – Thrown if
arrayis empty.
- Since:
3.0.1
- public static Boolean or(Boolean... array)[source]
Performs an ‘or’ operation 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 BooleanUtils.or(Boolean.TRUE, null) = Boolean.TRUE BooleanUtils.or(Boolean.FALSE, null) = Boolean.FALSE
Null array elements map to false, like
Boolean.parseBoolean(null)and its callers return false.- Parameters:
array – An array of
Booleans- Returns:
trueif any of the arguments istrue, and it returnsfalseotherwise.- Throws:
java.lang.NullPointerException – Thrown if
arrayisnull.java.lang.IllegalArgumentException – Thrown if
arrayis empty.
- Since:
3.0.1
- public static boolean[] primitiveValues()[source]
Returns a new array of possible values (like an enum would).
- Returns:
A new array of possible values (like an enum would).
- Since:
3.12.0
- public static boolean toBoolean(int value)[source]
Converts an int to a boolean using the convention that
zeroisfalse, everything else istrue.BooleanUtils.toBoolean(0) = false BooleanUtils.toBoolean(1) = true BooleanUtils.toBoolean(2) = true
- Parameters:
value – The int to convert
- Returns:
trueif non-zero,falseif zero
- public static boolean toBoolean(int value, int trueValue, int falseValue)[source]
Converts an int to a boolean specifying the conversion values.
If the
trueValueandfalseValueare the same number then the return value will betruein casevaluematches it.BooleanUtils.toBoolean(0, 1, 0) = false BooleanUtils.toBoolean(1, 1, 0) = true BooleanUtils.toBoolean(1, 1, 1) = true BooleanUtils.toBoolean(2, 1, 2) = false BooleanUtils.toBoolean(2, 2, 0) = true
- Parameters:
value – The
Integerto converttrueValue – The value to match for
truefalseValue – The value to match for
false
- Returns:
trueorfalse- Throws:
java.lang.IllegalArgumentException – Thrown if
valuedoes not match neithertrueValuenofalseValue.
- public static boolean toBoolean(Boolean bool)[source]
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
- public static boolean toBoolean(Integer value, Integer trueValue, Integer falseValue)[source]
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 convert
trueValue – The value to match for
true, may benullfalseValue – The value to match for
false, may benull
- Returns:
trueorfalse- Throws:
java.lang.IllegalArgumentException – Thrown if no match.
- public static boolean toBoolean(String str)[source]
Converts a String to a boolean (optimized 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.toBoolean("y") = true BooleanUtils.toBoolean("n") = false BooleanUtils.toBoolean("t") = true BooleanUtils.toBoolean("f") = false
- Parameters:
str – The String to check
- Returns:
The boolean value of the string,
falseif no match or the String is null
- public static boolean toBoolean(String str, String trueString, String falseString)[source]
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 check
trueString – The String to match for
true(case-sensitive), may benullfalseString – The String to match for
false(case-sensitive), may benull
- Returns:
The boolean value of the string
- Throws:
java.lang.IllegalArgumentException – Thrown if the String doesn’t match.
- public static boolean toBooleanDefaultIfNull(Boolean bool, boolean valueIfNull)[source]
Converts a Boolean to a boolean handling
null.BooleanUtils.toBooleanDefaultIfNull(Boolean.TRUE, false) = true BooleanUtils.toBooleanDefaultIfNull(Boolean.TRUE, true) = true BooleanUtils.toBooleanDefaultIfNull(Boolean.FALSE, true) = false BooleanUtils.toBooleanDefaultIfNull(Boolean.FALSE, false) = false BooleanUtils.toBooleanDefaultIfNull(null, true) = true BooleanUtils.toBooleanDefaultIfNull(null, false) = false
- Parameters:
bool – The boolean object to convert to primitive
valueIfNull – The boolean value to return if the parameter
boolisnull
- Returns:
trueorfalse
- public static Boolean toBooleanObject(int value)[source]
Converts an int to a Boolean using the convention that
zeroisfalse, everything else istrue.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
- public static Boolean toBooleanObject(int value, int trueValue, int falseValue, int nullValue)[source]
Converts an int to a Boolean specifying the conversion values.
NOTE: This method may return
nulland may throw aNullPointerExceptionif unboxed to aboolean.The checks are done first for the
trueValue, then for thefalseValueand finally for thenullValue.BooleanUtils.toBooleanObject(0, 0, 2, 3) = Boolean.TRUE BooleanUtils.toBooleanObject(0, 0, 0, 3) = Boolean.TRUE BooleanUtils.toBooleanObject(0, 0, 0, 0) = Boolean.TRUE BooleanUtils.toBooleanObject(2, 1, 2, 3) = Boolean.FALSE BooleanUtils.toBooleanObject(2, 1, 2, 2) = Boolean.FALSE BooleanUtils.toBooleanObject(3, 1, 2, 3) = null
- Parameters:
value – The Integer to convert
trueValue – The value to match for
truefalseValue – The value to match for
falsenullValue – The value to match for
null
- Returns:
Boolean.TRUE, Boolean.FALSE, or
null- Throws:
java.lang.IllegalArgumentException – Thrown if no match.
- public static Boolean toBooleanObject(Integer value)[source]
Converts an Integer to a Boolean using the convention that
zeroisfalse, every other numeric value istrue.nullwill be converted tonull.NOTE: This method may return
nulland may throw aNullPointerExceptionif unboxed to aboolean.BooleanUtils.toBooleanObject(Integer.valueOf(0)) = Boolean.FALSE BooleanUtils.toBooleanObject(Integer.valueOf(1)) = Boolean.TRUE BooleanUtils.toBooleanObject(Integer.valueOf(null)) = null
- Parameters:
value – The Integer to convert
- Returns:
Boolean.TRUE if non-zero, Boolean.FALSE if zero,
nullifnullinput
- public static Boolean toBooleanObject(Integer value, Integer trueValue, Integer falseValue, Integer nullValue)[source]
Converts an Integer to a Boolean specifying the conversion values.
NOTE: This method may return
nulland may throw aNullPointerExceptionif unboxed to aboolean.The checks are done first for the
trueValue, then for thefalseValueand finally for thenullValue.BooleanUtils.toBooleanObject(Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(2), Integer.valueOf(3)) = Boolean.TRUE BooleanUtils.toBooleanObject(Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(3)) = Boolean.TRUE BooleanUtils.toBooleanObject(Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0)) = Boolean.TRUE BooleanUtils.toBooleanObject(Integer.valueOf(2), Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3)) = Boolean.FALSE BooleanUtils.toBooleanObject(Integer.valueOf(2), Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(2)) = Boolean.FALSE BooleanUtils.toBooleanObject(Integer.valueOf(3), Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3)) = null
- Parameters:
value – The Integer to convert
trueValue – The value to match for
true, may benullfalseValue – The value to match for
false, may benullnullValue – The value to match for
null, may benull
- Returns:
Boolean.TRUE, Boolean.FALSE, or
null- Throws:
java.lang.IllegalArgumentException – Thrown if no match.
- public static Boolean toBooleanObject(String str)[source]
Converts a String to a Boolean.
'true','on','y','t','yes'or'1'(case insensitive) will returntrue.'false','off','n','f','no'or'0'(case insensitive) will returnfalse. Otherwise,nullis returned.NOTE: This method may return
nulland may throw aNullPointerExceptionif unboxed to aboolean.// 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("1") = Boolean.TRUE BooleanUtils.toBooleanObject("0") = Boolean.FALSE 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
- public static Boolean toBooleanObject(String str, String trueString, String falseString, String nullString)[source]
Converts a String to a Boolean throwing an exception if no match.
NOTE: This method may return
nulland may throw aNullPointerExceptionif unboxed to aboolean.BooleanUtils.toBooleanObject("true", "true", "false", "null") = Boolean.TRUE BooleanUtils.toBooleanObject(null, null, "false", "null") = Boolean.TRUE BooleanUtils.toBooleanObject(null, null, null, "null") = Boolean.TRUE BooleanUtils.toBooleanObject(null, null, null, null) = Boolean.TRUE BooleanUtils.toBooleanObject("false", "true", "false", "null") = Boolean.FALSE BooleanUtils.toBooleanObject("false", "true", "false", "false") = Boolean.FALSE BooleanUtils.toBooleanObject(null, "true", null, "false") = Boolean.FALSE BooleanUtils.toBooleanObject(null, "true", null, null) = Boolean.FALSE BooleanUtils.toBooleanObject("null", "true", "false", "null") = null
- Parameters:
str – The String to check
trueString – The String to match for
true(case-sensitive), may benullfalseString – The String to match for
false(case-sensitive), may benullnullString – The String to match for
null(case-sensitive), may benull
- Returns:
The Boolean value of the string,
nullif either the String matchesnullStringor ifnullinput andnullStringisnull- Throws:
java.lang.IllegalArgumentException – Thrown if the String doesn’t match.
- public static int toInteger(boolean bool)[source]
Converts a boolean to an int using the convention that
trueis1andfalseis0.BooleanUtils.toInteger(true) = 1 BooleanUtils.toInteger(false) = 0
- Parameters:
bool – The boolean to convert
- Returns:
one if
true, zero iffalse
- public static int toInteger(boolean bool, int trueValue, int falseValue)[source]
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 convert
trueValue – The value to return if
truefalseValue – The value to return if
false
- Returns:
The appropriate value
- public static int toInteger(Boolean bool, int trueValue, int falseValue, int nullValue)[source]
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 convert
trueValue – The value to return if
truefalseValue – The value to return if
falsenullValue – The value to return if
null
- Returns:
The appropriate value
- public static Integer toIntegerObject(boolean bool)[source]
Converts a boolean to an Integer using the convention that
trueis1andfalseis0.BooleanUtils.toIntegerObject(true) = Integer.valueOf(1) BooleanUtils.toIntegerObject(false) = Integer.valueOf(0)
- Parameters:
bool – The boolean to convert
- Returns:
one if
true, zero iffalse
- public static Integer toIntegerObject(boolean bool, Integer trueValue, Integer falseValue)[source]
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 convert
trueValue – The value to return if
true, may benullfalseValue – The value to return if
false, may benull
- Returns:
The appropriate value
- public static Integer toIntegerObject(Boolean bool)[source]
Converts a Boolean to an 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
- public static Integer toIntegerObject(Boolean bool, Integer trueValue, Integer falseValue, Integer nullValue)[source]
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 convert
trueValue – The value to return if
true, may benullfalseValue – The value to return if
false, may benullnullValue – The value to return if
null, may benull
- Returns:
The appropriate value
- public static String toString(boolean bool, String trueString, String falseString)[source]
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 check
trueString – The String to return if
true, may benullfalseString – The String to return if
false, may benull
- Returns:
one of the two input Strings
- public static String toString(Boolean bool, String trueString, String falseString, String nullString)[source]
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 check
trueString – The String to return if
true, may benullfalseString – The String to return if
false, may benullnullString – The String to return if
null, may benull
- Returns:
one of the three input Strings
- public static String toStringOnOff(boolean bool)[source]
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
- public static String toStringOnOff(Boolean bool)[source]
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
- public static String toStringTrueFalse(boolean bool)[source]
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
- public static String toStringTrueFalse(Boolean bool)[source]
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
- public static String toStringYesNo(boolean bool)[source]
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
- public static String toStringYesNo(Boolean bool)[source]
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
- public static List<Boolean> values()[source]
Returns an unmodifiable list of Booleans
[false, true].- Returns:
An unmodifiable list of Booleans
[false, true].- Since:
3.13.0
- public static boolean xor(boolean... array)[source]
Performs an xor on a set of booleans.
This behaves like an XOR gate; it returns true if the number of true values is odd, and false if the number of true values is zero or even.
BooleanUtils.xor(true, true) = false BooleanUtils.xor(false, false) = false BooleanUtils.xor(true, false) = true BooleanUtils.xor(true, false, false) = true BooleanUtils.xor(true, true, true) = true BooleanUtils.xor(true, true, true, true) = false
- Parameters:
array – An array of
booleans- Returns:
true if the number of true values in the array is odd; otherwise returns false.
- Throws:
java.lang.NullPointerException – Thrown if
arrayisnull.java.lang.IllegalArgumentException – Thrown if
arrayis empty.
- public static Boolean xor(Boolean... array)[source]
Performs an xor on an array of Booleans.
BooleanUtils.xor(Boolean.TRUE, Boolean.TRUE) = Boolean.FALSE BooleanUtils.xor(Boolean.FALSE, Boolean.FALSE) = Boolean.FALSE BooleanUtils.xor(Boolean.TRUE, Boolean.FALSE) = Boolean.TRUE BooleanUtils.xor(Boolean.TRUE, Boolean.FALSE, Boolean.FALSE) = Boolean.TRUE BooleanUtils.xor(Boolean.FALSE, null) = Boolean.FALSE BooleanUtils.xor(Boolean.TRUE, null) = Boolean.TRUE
Null array elements map to false, like
Boolean.parseBoolean(null)and its callers return false.- Parameters:
array – An array of
Booleans- Returns:
The result of the xor operations
- Throws:
java.lang.NullPointerException – Thrown if
arrayisnull.java.lang.IllegalArgumentException – Thrown if
arrayis empty.