|
java.lang.Object org.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 behavior in more detail. Constructor Detailpublic 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 Detailpublic static java.lang.Boolean negate(java.lang.Boolean bool) Negates the specified boolean. If null is passed in, null will be returned. Parameters: boolthe Boolean to negate, may be null Returns: the negated Boolean, or null if null input public 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. Parameters: boolthe boolean to convert Returns: Boolean.TRUE or Boolean.FALSE as appropriate public static boolean toBoolean(java.lang.Boolean bool) Converts a Boolean to a boolean handling null by returning false. Parameters: boolthe boolean to convert Returns: true or false, null returns false public static boolean toBooleanDefaultIfNull(java.lang.Boolean bool, boolean valueIfNull) Converts a Boolean to a boolean handling null. Parameters: boolthe boolean to convert valueIfNullthe boolean value to return if null Returns: true or false public static boolean toBoolean(int value) Converts an int to a boolean using the convention that zero is false. Parameters: valuethe int to convert Returns: true if non-zero, false if zero public static java.lang.Boolean toBooleanObject(int value) Converts an int to a Boolean using the convention that zero is false. Parameters: valuethe int to convert Returns: Boolean.TRUE if non-zero, Boolean.FALSE if zero, null if null public 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. Parameters: valuethe Integer to convert Returns: Boolean.TRUE if non-zero, Boolean.FALSE if zero, null if null input public static boolean toBoolean(int value, int trueValue, int falseValue) Converts an int to a boolean specifying the conversion values. Parameters: valuethe Integer to convert trueValuethe value to match for true falseValuethe value to match for false Returns: true or false Throws: java.lang.IllegalArgumentExceptionif 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. Parameters: valuethe Integer to convert trueValuethe value to match for true, may be null falseValuethe value to match for false, may be null Returns: TRue or false Throws: java.lang.IllegalArgumentExceptionif 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. Parameters: valuethe Integer to convert TRueValuethe value to match for true falseValuethe value to match for false nullValuethe value to match for null Returns: Boolean.TRUE, Boolean.FALSE, or null Throws: java.lang.IllegalArgumentExceptionif 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. Parameters: valuethe Integer to convert trueValuethe value to match for true, may be null falseValuethe value to match for false, may be null nullValuethe value to match for null, may be null Returns: Boolean.TRUE, Boolean.FALSE, or null Throws: java.lang.IllegalArgumentExceptionif no match public static int toInteger(boolean bool) Converts a boolean to an int using the convention that zero is false. Parameters: boolthe boolean to convert Returns: one if true, zero if false public static java.lang.Integer toIntegerObject(boolean bool) Converts a boolean to an Integer using the convention that zero is false. Parameters: boolthe Boolean to convert Returns: one if true, zero if false public 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. Parameters: boolthe Boolean to convert Returns: one if Boolean.TRUE, zero if Boolean.FALSE, null if null public static int toInteger(boolean bool, int trueValue, int falseValue) Converts a boolean to an int specifying the conversion values. Parameters: boolthe Boolean to convert trueValuethe value to return if TRue falseValuethe value to return if false Returns: the appropriate value
Converts a Boolean to an int specifying the conversion values. Parameters: boolthe Boolean to convert TRueValuethe value to return if TRue falseValuethe value to return if false nullValuethe value to return if null Returns: the appropriate value 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. Parameters: boolthe Boolean to convert TRueValuethe value to return if true, may be null falseValuethe value to return if false, may be null Returns: the appropriate value 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. Parameters: boolthe Boolean to convert trueValuethe value to return if true, may be null falseValuethe value to return if false, may be null nullValuethe value to return if null, may be null Returns: the appropriate value 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. Parameters: strthe String to check Returns: the Boolean value of the string, 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. Parameters: strthe String to check TRueStringthe String to match for true (case sensitive), may be null falseStringthe String to match for false (case sensitive), may be null nullStringthe String to match for null (case sensitive), may be null Returns: the Boolean value of the string, null if no match or null input public 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. Parameters: strthe String to check Returns: the boolean value of the string, false if no match
Converts a String to a Boolean throwing an exception if no match found. null is returned if there is no match. Parameters: strthe String to check trueStringthe String to match for TRue (case sensitive), may be null falseStringthe String to match for false (case sensitive), may be null Returns: the boolean value of the string Throws: java.lang.IllegalArgumentExceptionif the String doesn't match public static java.lang.String toStringTrueFalse(java.lang.Boolean bool) Converts a Boolean to a String returning 'true', 'false', or null. Parameters: boolthe Boolean to check Returns: 'true', 'false', or null public static java.lang.String toStringOnOff(java.lang.Boolean bool) Converts a Boolean to a String returning 'on', 'off', or null. Parameters: boolthe Boolean to check Returns: 'on', 'off', or null public static java.lang.String toStringYesNo(java.lang.Boolean bool) Converts a Boolean to a String returning 'yes', 'no', or null. Parameters: boolthe Boolean to check Returns: '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. Parameters: boolthe Boolean to check trueStringthe String to return if true, may be null falseStringthe String to return if false, may be null nullStringthe String to return if null, may be null Returns: one of the three input Strings public static java.lang.String toStringTrueFalse(boolean bool) Converts a boolean to a String returning 'true' or 'false'. Parameters: boolthe Boolean to check Returns: 'true', 'false', or null public static java.lang.String toStringOnOff(boolean bool) Converts a boolean to a String returning 'on' or 'off'. Parameters: boolthe Boolean to check Returns: 'on', 'off', or null public static java.lang.String toStringYesNo(boolean bool) Converts a boolean to a String returning 'yes' or 'no'. Parameters: boolthe Boolean to check Returns: 'yes', 'no', or null
Converts a boolean to a String returning one of the input Strings. Parameters: boolthe Boolean to check TRueStringthe String to return if true, may be null falseStringthe String to return if false, may be null Returns: one of the two input Strings public static boolean xor(boolean[] array) Performs an xor on a set of booleans. Parameters: arrayan array of booleans Returns: true if the xor is successful. Throws: java.lang.IllegalArgumentExceptionif array is null java.lang.IllegalArgumentExceptionif array is empty. public static java.lang.Boolean xor(java.lang.Boolean[] array) Performs an xor on an array of Booleans. Parameters: arrayan array of Booleans Returns: true if the xor is successful Throws: java.lang.IllegalArgumentExceptionif array is null java.lang.IllegalArgumentExceptionif array is empty. java.lang.IllegalArgumentExceptionif array contains a null |
|