public class BooleanUtils
extends java.lang.Object
This class tries to handle null
input gracefully.
An exception will not be thrown for a null
input.
Each method documents its behavior in more detail.
#ThreadSafe#
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
FALSE
The false String
"false" . |
static java.lang.String |
NO
The no String
"no" . |
static java.lang.String |
OFF
The off String
"off" . |
static java.lang.String |
ON
The on String
"on" . |
static java.lang.String |
TRUE
The true String
"true" . |
static java.lang.String |
YES
The yes String
"yes" . |
Constructor and Description |
---|
BooleanUtils()
BooleanUtils instances should NOT be constructed in standard programming. |
Modifier and Type | Method and Description |
---|---|
static boolean |
and(boolean... array)
Performs an 'and' operation on a set of booleans.
|
static java.lang.Boolean |
and(java.lang.Boolean... array)
Performs an 'and' operation on an array of Booleans.
|
static java.lang.Boolean[] |
booleanValues()
Returns a new array of possible values (like an enum would).
|
static int |
compare(boolean x,
boolean y)
Compares two
boolean values. |
static void |
forEach(java.util.function.Consumer<java.lang.Boolean> action)
Performs the given action for each Boolean
values() . |
static boolean |
isFalse(java.lang.Boolean bool)
Checks if a
Boolean value is false ,
handling null by returning false . |
static boolean |
isNotFalse(java.lang.Boolean bool)
Checks if a
Boolean value is not false ,
handling null by returning true . |
static boolean |
isNotTrue(java.lang.Boolean bool)
Checks if a
Boolean value is not true ,
handling null by returning true . |
static boolean |
isTrue(java.lang.Boolean bool)
Checks if a
Boolean value is true ,
handling null by returning false . |
static java.lang.Boolean |
negate(java.lang.Boolean bool)
Negates the specified boolean.
|
static boolean |
oneHot(boolean... array)
Performs a one-hot on an array of booleans.
|
static java.lang.Boolean |
oneHot(java.lang.Boolean... array)
Performs a one-hot on an array of booleans.
|
static boolean |
or(boolean... array)
Performs an 'or' operation on a set of booleans.
|
static java.lang.Boolean |
or(java.lang.Boolean... array)
Performs an 'or' operation on an array of Booleans.
|
static boolean[] |
primitiveValues()
Returns a new array of possible values (like an enum would).
|
static boolean |
toBoolean(java.lang.Boolean bool)
Converts a Boolean to a boolean handling
null
by returning false . |
static boolean |
toBoolean(int value)
Converts an int to a boolean using the convention that
zero
is false , everything else is true . |
static boolean |
toBoolean(java.lang.Integer value,
java.lang.Integer trueValue,
java.lang.Integer falseValue)
Converts an Integer to a boolean specifying the conversion values.
|
static boolean |
toBoolean(int value,
int trueValue,
int falseValue)
Converts an int to a boolean specifying the conversion values.
|
static boolean |
toBoolean(java.lang.String str)
Converts a String to a boolean (optimised for performance).
|
static boolean |
toBoolean(java.lang.String str,
java.lang.String trueString,
java.lang.String falseString)
Converts a String to a Boolean throwing an exception if no match found.
|
static boolean |
toBooleanDefaultIfNull(java.lang.Boolean bool,
boolean valueIfNull)
Converts a Boolean to a boolean handling
null . |
static java.lang.Boolean |
toBooleanObject(int value)
Converts an int to a Boolean using the convention that
zero
is false , everything else is true . |
static java.lang.Boolean |
toBooleanObject(java.lang.Integer value)
Converts an Integer to a Boolean using the convention that
zero
is false , every other numeric value is true . |
static java.lang.Boolean |
toBooleanObject(java.lang.Integer value,
java.lang.Integer trueValue,
java.lang.Integer falseValue,
java.lang.Integer nullValue)
Converts an Integer to a Boolean specifying the conversion values.
|
static java.lang.Boolean |
toBooleanObject(int value,
int trueValue,
int falseValue,
int nullValue)
Converts an int to a Boolean specifying the conversion values.
|
static java.lang.Boolean |
toBooleanObject(java.lang.String str)
Converts a String to a Boolean.
|
static java.lang.Boolean |
toBooleanObject(java.lang.String str,
java.lang.String trueString,
java.lang.String falseString,
java.lang.String nullString)
Converts a String to a Boolean throwing an exception if no match.
|
static int |
toInteger(boolean bool)
Converts a boolean to an int using the convention that
true is 1 and false is 0 . |
static int |
toInteger(boolean bool,
int trueValue,
int falseValue)
Converts a boolean to an int specifying the conversion values.
|
static int |
toInteger(java.lang.Boolean bool,
int trueValue,
int falseValue,
int nullValue)
Converts a Boolean to an int specifying the conversion values.
|
static java.lang.Integer |
toIntegerObject(boolean bool)
Converts a boolean to an Integer using the convention that
true is 1 and false is 0 . |
static java.lang.Integer |
toIntegerObject(java.lang.Boolean bool)
Converts a Boolean to a Integer using the convention that
zero is false . |
static java.lang.Integer |
toIntegerObject(boolean bool,
java.lang.Integer trueValue,
java.lang.Integer falseValue)
Converts a boolean to an Integer specifying the conversion values.
|
static java.lang.Integer |
toIntegerObject(java.lang.Boolean bool,
java.lang.Integer trueValue,
java.lang.Integer falseValue,
java.lang.Integer nullValue)
Converts a Boolean to an Integer specifying the conversion values.
|
static java.lang.String |
toString(boolean bool,
java.lang.String trueString,
java.lang.String falseString)
Converts a boolean to a String returning one of the input Strings.
|
static java.lang.String |
toString(java.lang.Boolean bool,
java.lang.String trueString,
java.lang.String falseString,
java.lang.String nullString)
Converts a Boolean to a String returning one of the input Strings.
|
static java.lang.String |
toStringOnOff(boolean bool)
Converts a boolean to a String returning
'on'
or 'off' . |
static java.lang.String |
toStringOnOff(java.lang.Boolean bool)
Converts a Boolean to a String returning
'on' ,
'off' , or null . |
static java.lang.String |
toStringTrueFalse(boolean bool)
Converts a boolean to a String returning
'true'
or 'false' . |
static java.lang.String |
toStringTrueFalse(java.lang.Boolean bool)
Converts a Boolean to a String returning
'true' ,
'false' , or null . |
static java.lang.String |
toStringYesNo(boolean bool)
Converts a boolean to a String returning
'yes'
or 'no' . |
static java.lang.String |
toStringYesNo(java.lang.Boolean bool)
Converts a Boolean to a String returning
'yes' ,
'no' , or null . |
static java.util.List<java.lang.Boolean> |
values()
Returns an unmodifiable list of Booleans
[false, true] . |
static boolean |
xor(boolean... array)
Performs an xor on a set of booleans.
|
static java.lang.Boolean |
xor(java.lang.Boolean... array)
Performs an xor on an array of Booleans.
|
public static final java.lang.String FALSE
"false"
.public static final java.lang.String NO
"no"
.public static final java.lang.String OFF
"off"
.public static final java.lang.String ON
"on"
.public static final java.lang.String TRUE
"true"
.public static final java.lang.String YES
"yes"
.public BooleanUtils()
BooleanUtils
instances should NOT be constructed in standard programming.
Instead, the class should be used as BooleanUtils.negate(true);
.
This constructor is public to permit tools that require a JavaBean instance to operate.
public static boolean and(boolean... array)
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
array
- an array of boolean
sfalse
if any of the parameters is false
and true
otherwise.java.lang.NullPointerException
- if array
is null
java.lang.IllegalArgumentException
- if array
is empty.public static java.lang.Boolean and(java.lang.Boolean... array)
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.
array
- an array of Boolean
sfalse
if any of the parameters is false
and true
otherwise.java.lang.NullPointerException
- if array
is null
java.lang.IllegalArgumentException
- if array
is empty.public static java.lang.Boolean[] booleanValues()
public static int compare(boolean x, boolean y)
boolean
values. This is the same functionality as provided in Java 7.x
- the first boolean
to comparey
- the second boolean
to compare0
if x == y
;
a value less than 0
if !x && y
; and
a value greater than 0
if x && !y
public static void forEach(java.util.function.Consumer<java.lang.Boolean> action)
values()
.action
- The action to be performed for each elementpublic static boolean isFalse(java.lang.Boolean bool)
Boolean
value is false
,
handling null
by returning false
.
BooleanUtils.isFalse(Boolean.TRUE) = false BooleanUtils.isFalse(Boolean.FALSE) = true BooleanUtils.isFalse(null) = false
bool
- the boolean to check, null returns false
true
only if the input is non-null
and false
public static boolean isNotFalse(java.lang.Boolean bool)
Boolean
value is not false
,
handling null
by returning true
.
BooleanUtils.isNotFalse(Boolean.TRUE) = true BooleanUtils.isNotFalse(Boolean.FALSE) = false BooleanUtils.isNotFalse(null) = true
bool
- the boolean to check, null returns true
true
if the input is null
or true
public static boolean isNotTrue(java.lang.Boolean bool)
Boolean
value is not true
,
handling null
by returning true
.
BooleanUtils.isNotTrue(Boolean.TRUE) = false BooleanUtils.isNotTrue(Boolean.FALSE) = true BooleanUtils.isNotTrue(null) = true
bool
- the boolean to check, null returns true
true
if the input is null or falsepublic static boolean isTrue(java.lang.Boolean bool)
Boolean
value is true
,
handling null
by returning false
.
BooleanUtils.isTrue(Boolean.TRUE) = true BooleanUtils.isTrue(Boolean.FALSE) = false BooleanUtils.isTrue(null) = false
bool
- the boolean to check, null
returns false
true
only if the input is non-null and truepublic static java.lang.Boolean negate(java.lang.Boolean bool)
If null
is passed in, null
will 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;
bool
- the Boolean to negate, may be nullnull
if null
inputpublic static boolean oneHot(boolean... array)
This implementation returns true if one, and only one, of the supplied values is true.
See also One-hot.
array
- an array of boolean
sjava.lang.NullPointerException
- if array
is null
java.lang.IllegalArgumentException
- if array
is empty.public static java.lang.Boolean oneHot(java.lang.Boolean... array)
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.
array
- an array of boolean
sjava.lang.NullPointerException
- if array
is null
java.lang.IllegalArgumentException
- if array
is empty.public static boolean or(boolean... array)
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
array
- an array of boolean
strue
if any of the arguments is true
, and it returns false
otherwise.java.lang.NullPointerException
- if array
is null
java.lang.IllegalArgumentException
- if array
is empty.public static java.lang.Boolean or(java.lang.Boolean... array)
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.
array
- an array of Boolean
strue
if any of the arguments is true
, and it returns false
otherwise.java.lang.NullPointerException
- if array
is null
java.lang.IllegalArgumentException
- if array
is empty.public static boolean[] primitiveValues()
public static boolean toBoolean(java.lang.Boolean bool)
null
by returning false
.
BooleanUtils.toBoolean(Boolean.TRUE) = true BooleanUtils.toBoolean(Boolean.FALSE) = false BooleanUtils.toBoolean(null) = false
bool
- the boolean to converttrue
or false
, null
returns false
public static boolean toBoolean(int value)
zero
is false
, everything else is true
.
BooleanUtils.toBoolean(0) = false BooleanUtils.toBoolean(1) = true BooleanUtils.toBoolean(2) = true
value
- the int to converttrue
if non-zero, false
if zeropublic static boolean toBoolean(int value, int trueValue, int falseValue)
If the trueValue
and falseValue
are the same number then
the return value will be true
in case value
matches 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
value
- the Integer
to converttrueValue
- the value to match for true
falseValue
- the value to match for false
true
or false
java.lang.IllegalArgumentException
- if value
does not match neither
trueValue
no falseValue
public static boolean toBoolean(java.lang.Integer value, java.lang.Integer trueValue, java.lang.Integer falseValue)
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
value
- the Integer to converttrueValue
- the value to match for true
, may be null
falseValue
- the value to match for false
, may be null
true
or false
java.lang.IllegalArgumentException
- if no matchpublic static boolean toBoolean(java.lang.String str)
'true'
, 'on'
, 'y'
, 't'
or 'yes'
(case insensitive) will return true
. Otherwise,
false
is 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
str
- the String to checkfalse
if no match or the String is nullpublic static boolean toBoolean(java.lang.String str, java.lang.String trueString, java.lang.String falseString)
BooleanUtils.toBoolean("true", "true", "false") = true BooleanUtils.toBoolean("false", "true", "false") = false
str
- the String to checktrueString
- the String to match for true
(case-sensitive), may be null
falseString
- the String to match for false
(case-sensitive), may be null
java.lang.IllegalArgumentException
- if the String doesn't matchpublic static boolean toBooleanDefaultIfNull(java.lang.Boolean bool, boolean valueIfNull)
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
bool
- the boolean object to convert to primitivevalueIfNull
- the boolean value to return if the parameter bool
is null
true
or false
public static java.lang.Boolean toBooleanObject(int value)
zero
is false
, everything else is true
.
BooleanUtils.toBoolean(0) = Boolean.FALSE BooleanUtils.toBoolean(1) = Boolean.TRUE BooleanUtils.toBoolean(2) = Boolean.TRUE
value
- the int to convertnull
if null
public static java.lang.Boolean toBooleanObject(int value, int trueValue, int falseValue, int nullValue)
NOTE: This method may return null
and may throw a NullPointerException
if unboxed to a boolean
.
The checks are done first for the trueValue
, then for the falseValue
and
finally for the nullValue
.
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
value
- the Integer to converttrueValue
- the value to match for true
falseValue
- the value to match for false
nullValue
- the value to match for null
null
java.lang.IllegalArgumentException
- if no matchpublic static java.lang.Boolean toBooleanObject(java.lang.Integer value)
zero
is false
, every other numeric value is true
.
null
will be converted to null
.
NOTE: This method may return null
and may throw a NullPointerException
if unboxed to a boolean
.
BooleanUtils.toBooleanObject(Integer.valueOf(0)) = Boolean.FALSE BooleanUtils.toBooleanObject(Integer.valueOf(1)) = Boolean.TRUE BooleanUtils.toBooleanObject(Integer.valueOf(null)) = null
value
- the Integer to convertnull
if null
inputpublic static java.lang.Boolean toBooleanObject(java.lang.Integer value, java.lang.Integer trueValue, java.lang.Integer falseValue, java.lang.Integer nullValue)
NOTE: This method may return null
and may throw a NullPointerException
if unboxed to a boolean
.
The checks are done first for the trueValue
, then for the falseValue
and
finally for the nullValue
.
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
value
- the Integer to converttrueValue
- the value to match for true
, may be null
falseValue
- the value to match for false
, may be null
nullValue
- the value to match for null
, may be null
null
java.lang.IllegalArgumentException
- if no matchpublic static java.lang.Boolean toBooleanObject(java.lang.String str)
'true'
, 'on'
, 'y'
, 't'
, 'yes'
or '1'
(case insensitive) will return true
.
'false'
, 'off'
, 'n'
, 'f'
, 'no'
or '0'
(case insensitive) will return false
.
Otherwise, null
is returned.
NOTE: This method may return null
and may 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("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
str
- the String to check; upper and lower case are treated as the samenull
if no match or null
inputpublic static java.lang.Boolean toBooleanObject(java.lang.String str, java.lang.String trueString, java.lang.String falseString, java.lang.String nullString)
NOTE: This method may return null
and may throw a NullPointerException
if unboxed to a boolean
.
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
str
- the String to checktrueString
- the String to match for true
(case-sensitive), may be null
falseString
- the String to match for false
(case-sensitive), may be null
nullString
- the String to match for null
(case-sensitive), may be null
null
if either the String matches nullString
or if null
input and nullString
is null
java.lang.IllegalArgumentException
- if the String doesn't matchpublic static int toInteger(boolean bool)
true
is 1
and false
is 0
.
BooleanUtils.toInteger(true) = 1 BooleanUtils.toInteger(false) = 0
bool
- the boolean to converttrue
, zero if false
public static int toInteger(boolean bool, int trueValue, int falseValue)
BooleanUtils.toInteger(true, 1, 0) = 1 BooleanUtils.toInteger(false, 1, 0) = 0
bool
- the to converttrueValue
- the value to return if true
falseValue
- the value to return if false
public static int toInteger(java.lang.Boolean bool, int trueValue, int falseValue, int nullValue)
BooleanUtils.toInteger(Boolean.TRUE, 1, 0, 2) = 1 BooleanUtils.toInteger(Boolean.FALSE, 1, 0, 2) = 0 BooleanUtils.toInteger(null, 1, 0, 2) = 2
bool
- the Boolean to converttrueValue
- the value to return if true
falseValue
- the value to return if false
nullValue
- the value to return if null
public static java.lang.Integer toIntegerObject(boolean bool)
true
is 1
and false
is 0
.
BooleanUtils.toIntegerObject(true) = Integer.valueOf(1) BooleanUtils.toIntegerObject(false) = Integer.valueOf(0)
bool
- the boolean to converttrue
, zero if false
public static java.lang.Integer toIntegerObject(boolean bool, java.lang.Integer trueValue, java.lang.Integer falseValue)
BooleanUtils.toIntegerObject(true, Integer.valueOf(1), Integer.valueOf(0)) = Integer.valueOf(1) BooleanUtils.toIntegerObject(false, Integer.valueOf(1), Integer.valueOf(0)) = Integer.valueOf(0)
bool
- the to converttrueValue
- the value to return if true
, may be null
falseValue
- the value to return if false
, may be null
public static java.lang.Integer toIntegerObject(java.lang.Boolean bool)
zero
is false
.
null
will be converted to null
.
BooleanUtils.toIntegerObject(Boolean.TRUE) = Integer.valueOf(1) BooleanUtils.toIntegerObject(Boolean.FALSE) = Integer.valueOf(0)
bool
- the Boolean to convertnull
if null
public static java.lang.Integer toIntegerObject(java.lang.Boolean bool, java.lang.Integer trueValue, java.lang.Integer falseValue, java.lang.Integer nullValue)
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)
bool
- the Boolean to converttrueValue
- the value to return if true
, may be null
falseValue
- the value to return if false
, may be null
nullValue
- the value to return if null
, may be null
public static java.lang.String toString(boolean bool, java.lang.String trueString, java.lang.String falseString)
BooleanUtils.toString(true, "true", "false") = "true" BooleanUtils.toString(false, "true", "false") = "false"
bool
- the Boolean to checktrueString
- the String to return if true
, may be null
falseString
- the String to return if false
, may be null
public static java.lang.String toString(java.lang.Boolean bool, java.lang.String trueString, java.lang.String falseString, java.lang.String nullString)
BooleanUtils.toString(Boolean.TRUE, "true", "false", null) = "true" BooleanUtils.toString(Boolean.FALSE, "true", "false", null) = "false" BooleanUtils.toString(null, "true", "false", null) = null;
bool
- the Boolean to checktrueString
- the String to return if true
, may be null
falseString
- the String to return if false
, may be null
nullString
- the String to return if null
, may be null
public static java.lang.String toStringOnOff(boolean bool)
'on'
or 'off'
.
BooleanUtils.toStringOnOff(true) = "on" BooleanUtils.toStringOnOff(false) = "off"
bool
- the Boolean to check'on'
, 'off'
, or null
public static java.lang.String toStringOnOff(java.lang.Boolean bool)
'on'
,
'off'
, or null
.
BooleanUtils.toStringOnOff(Boolean.TRUE) = "on" BooleanUtils.toStringOnOff(Boolean.FALSE) = "off" BooleanUtils.toStringOnOff(null) = null;
bool
- the Boolean to check'on'
, 'off'
, or null
public static java.lang.String toStringTrueFalse(boolean bool)
'true'
or 'false'
.
BooleanUtils.toStringTrueFalse(true) = "true" BooleanUtils.toStringTrueFalse(false) = "false"
bool
- the Boolean to check'true'
, 'false'
, or null
public static java.lang.String toStringTrueFalse(java.lang.Boolean bool)
'true'
,
'false'
, or null
.
BooleanUtils.toStringTrueFalse(Boolean.TRUE) = "true" BooleanUtils.toStringTrueFalse(Boolean.FALSE) = "false" BooleanUtils.toStringTrueFalse(null) = null;
bool
- the Boolean to check'true'
, 'false'
, or null
public static java.lang.String toStringYesNo(boolean bool)
'yes'
or 'no'
.
BooleanUtils.toStringYesNo(true) = "yes" BooleanUtils.toStringYesNo(false) = "no"
bool
- the Boolean to check'yes'
, 'no'
, or null
public static java.lang.String toStringYesNo(java.lang.Boolean bool)
'yes'
,
'no'
, or null
.
BooleanUtils.toStringYesNo(Boolean.TRUE) = "yes" BooleanUtils.toStringYesNo(Boolean.FALSE) = "no" BooleanUtils.toStringYesNo(null) = null;
bool
- the Boolean to check'yes'
, 'no'
, or null
public static java.util.List<java.lang.Boolean> values()
[false, true]
.[false, true]
.public static boolean xor(boolean... array)
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
array
- an array of boolean
sjava.lang.NullPointerException
- if array
is null
java.lang.IllegalArgumentException
- if array
is empty.public static java.lang.Boolean xor(java.lang.Boolean... array)
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.
array
- an array of Boolean
sjava.lang.NullPointerException
- if array
is null
java.lang.IllegalArgumentException
- if array
is empty.Copyright © 2010 - 2023 Adobe. All Rights Reserved