|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.apache.commons.lang.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.
| Constructor Summary | |
BooleanUtils()
BooleanUtils instances should NOT be constructed in standard programming. |
|
| Method Summary | |
static java.lang.Boolean |
negate(java.lang.Boolean bool)
Negates the specified boolean. |
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. |
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. |
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(boolean bool)
Boolean factory that avoids creating new Boolean objecs all the time. |
static java.lang.Boolean |
toBooleanObject(int value)
Converts an int to a Boolean using the convention that zero
is false. |
static java.lang.Boolean |
toBooleanObject(java.lang.Integer value)
Converts an Integer to a Boolean using the convention that zero
is false. |
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 zero is false. |
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 zero is false. |
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 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. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public BooleanUtils()
BooleanUtils instances should NOT be constructed in standard programming.
Instead, the class should be used as BooleanUtils.toBooleanObject(true);.
This constructor is public to permit tools that require a JavaBean instance to operate.
| Method Detail |
public static java.lang.Boolean negate(java.lang.Boolean bool)
Negates the specified boolean.
If null is passed in, null will be returned.
bool - the Boolean to negate, may be null
null if null inputpublic static java.lang.Boolean toBooleanObject(boolean bool)
Boolean factory that avoids creating new Boolean objecs all the time.
This method was added to JDK1.4 but is available here for earlier JDKs.
bool - the boolean to convert
public static boolean toBoolean(java.lang.Boolean bool)
Converts a Boolean to a boolean handling null
by returning false.
bool - the boolean to convert
true or false,
null returns false
public static boolean toBooleanDefaultIfNull(java.lang.Boolean bool,
boolean valueIfNull)
Converts a Boolean to a boolean handling null.
bool - the boolean to convertvalueIfNull - the boolean value to return if null
true or falsepublic static boolean toBoolean(int value)
Converts an int to a boolean using the convention that zero
is false.
value - the int to convert
true if non-zero, false
if zeropublic static java.lang.Boolean toBooleanObject(int value)
Converts an int to a Boolean using the convention that zero
is false.
value - the int to convert
null if nullpublic static java.lang.Boolean toBooleanObject(java.lang.Integer value)
Converts an Integer to a Boolean using the convention that zero
is false.
null will be converted to null.
value - the Integer to convert
null if null input
public static boolean toBoolean(int value,
int trueValue,
int falseValue)
Converts an int to a boolean specifying the conversion values.
value - the Integer to converttrueValue - the value to match for truefalseValue - the value to match for false
true or false
java.lang.IllegalArgumentException - if no match
public 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.
value - the Integer to converttrueValue - the value to match for true,
may be nullfalseValue - the value to match for false,
may be null
true or false
java.lang.IllegalArgumentException - if no match
public static java.lang.Boolean toBooleanObject(int value,
int trueValue,
int falseValue,
int nullValue)
Converts an int to a Boolean specifying the conversion values.
value - the Integer to converttrueValue - the value to match for truefalseValue - the value to match for falsenullValue - the value to to match for null
null
java.lang.IllegalArgumentException - if no match
public 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.
value - the Integer to converttrueValue - the value to match for true,
may be nullfalseValue - the value to match for false,
may be nullnullValue - the value to to match for null,
may be null
null
java.lang.IllegalArgumentException - if no matchpublic static int toInteger(boolean bool)
Converts a boolean to an int using the convention that
zero is false.
bool - the boolean to convert
true, zero if falsepublic static java.lang.Integer toIntegerObject(boolean bool)
Converts a boolean to an Integer using the convention that
zero is false.
bool - the boolean to convert
true, zero if falsepublic static java.lang.Integer toIntegerObject(java.lang.Boolean bool)
Converts a Boolean to a Integer using the convention that
zero is false.
null will be converted to null.
bool - the Boolean to convert
null if null
public static int toInteger(boolean bool,
int trueValue,
int falseValue)
Converts a boolean to an int specifying the conversion values.
bool - the to converttrueValue - the value to return if truefalseValue - the value to return if false
public static int toInteger(java.lang.Boolean bool,
int trueValue,
int falseValue,
int nullValue)
Converts a Boolean to an int specifying the conversion values.
bool - the Boolean to converttrueValue - the value to return if truefalseValue - the value to return if falsenullValue - the value to return if null
public 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.
bool - the to converttrueValue - the value to return if true,
may be nullfalseValue - the value to return if false,
may be null
public 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.
bool - the Boolean to converttrueValue - the value to return if true,
may be nullfalseValue - the value to return if false,
may be nullnullValue - the value to return if null,
may be null
public static java.lang.Boolean toBooleanObject(java.lang.String str)
Converts a String to a Boolean.
'true', 'on' or 'yes'
(case insensitive) will return true.
'false', 'off' or 'no'
(case insensitive) will return false.
Otherwise, null is returned.
str - the String to check
null if no match or null input
public 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.
str - the String to checktrueString - the String to match for true
(case sensitive), may be nullfalseString - the String to match for false
(case sensitive), may be nullnullString - the String to match for null
(case sensitive), may be null
null if no match or null inputpublic static boolean toBoolean(java.lang.String str)
Converts a String to a boolean.
'true', 'on' or 'yes'
(case insensitive) will return true. Otherwise,
false is returned.
str - the String to check
false if no match
public 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.
null is returned if there is no match.
str - the String to checktrueString - the String to match for true
(case sensitive), may be nullfalseString - the String to match for false
(case sensitive), may be null
java.lang.IllegalArgumentException - if the String doesn't matchpublic static java.lang.String toStringTrueFalse(java.lang.Boolean bool)
Converts a Boolean to a String returning 'true',
'false', or null.
bool - the Boolean to check
'true', 'false',
or nullpublic static java.lang.String toStringOnOff(java.lang.Boolean bool)
Converts a Boolean to a String returning 'on',
'off', or null.
bool - the Boolean to check
'on', 'off',
or nullpublic static java.lang.String toStringYesNo(java.lang.Boolean bool)
Converts a Boolean to a String returning 'yes',
'no', or null.
bool - the Boolean to check
'yes', 'no',
or null
public 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.
bool - the Boolean to checktrueString - the String to return if true,
may be nullfalseString - the String to return if false,
may be nullnullString - the String to return if null,
may be null
public static java.lang.String toStringTrueFalse(boolean bool)
Converts a boolean to a String returning 'true'
or 'false'.
bool - the Boolean to check
'true', 'false',
or nullpublic static java.lang.String toStringOnOff(boolean bool)
Converts a boolean to a String returning 'on'
or 'off'.
bool - the Boolean to check
'on', 'off',
or nullpublic static java.lang.String toStringYesNo(boolean bool)
Converts a boolean to a String returning 'yes'
or 'no'.
bool - the Boolean to check
'yes', 'no',
or null
public 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.
bool - the Boolean to checktrueString - the String to return if true,
may be nullfalseString - the String to return if false,
may be null
public static boolean xor(boolean[] array)
Performs an xor on a set of booleans.
array - an array of booleans
- Returns:
true if the xor is successful.
- Throws:
java.lang.IllegalArgumentException - if array is null
java.lang.IllegalArgumentException - if array is empty.public static java.lang.Boolean xor(java.lang.Boolean[] array)
Performs an xor on an array of Booleans.
array - an array of Booleans
- Returns:
true if the xor is successful.
- Throws:
java.lang.IllegalArgumentException - if array is null
java.lang.IllegalArgumentException - if array is empty.
java.lang.IllegalArgumentException - if array contains a null
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||