org.apache.commons.lang

Class BooleanUtils


public class BooleanUtils
extends Object

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.

Since:
2.0

Constructor Summary

BooleanUtils()
BooleanUtils instances should NOT be constructed in standard programming.

Method Summary

static boolean
isFalse(Boolean bool)
Checks if a Boolean value is false, handling null by returning false.
static boolean
isNotFalse(Boolean bool)
Checks if a Boolean value is not false, handling null by returning true.
static boolean
isNotTrue(Boolean bool)
Checks if a Boolean value is not true, handling null by returning true.
static boolean
isTrue(Boolean bool)
Checks if a Boolean value is true, handling null by returning false.
static Boolean
negate(Boolean bool)
Negates the specified boolean.
static boolean
toBoolean(int value)
Converts an int to a boolean using the convention that zero is false.
static boolean
toBoolean(int value, int trueValue, int falseValue)
Converts an int to a boolean specifying the conversion values.
static boolean
toBoolean(Boolean bool)
Converts a Boolean to a boolean handling null by returning false.
static boolean
toBoolean(Integer value, Integer trueValue, Integer falseValue)
Converts an Integer to a boolean specifying the conversion values.
static boolean
toBoolean(String str)
Converts a String to a boolean (optimised for performance).
static boolean
toBoolean(String str, String trueString, String falseString)
Converts a String to a Boolean throwing an exception if no match found.
static boolean
toBooleanDefaultIfNull(Boolean bool, boolean valueIfNull)
Converts a Boolean to a boolean handling null.
static Boolean
toBooleanObject(boolean bool)
Boolean factory that avoids creating new Boolean objecs all the time.
static Boolean
toBooleanObject(int value)
Converts an int to a Boolean using the convention that zero is false.
static Boolean
toBooleanObject(int value, int trueValue, int falseValue, int nullValue)
Converts an int to a Boolean specifying the conversion values.
static Boolean
toBooleanObject(Integer value)
Converts an Integer to a Boolean using the convention that zero is false.
static Boolean
toBooleanObject(Integer value, Integer trueValue, Integer falseValue, Integer nullValue)
Converts an Integer to a Boolean specifying the conversion values.
static Boolean
toBooleanObject(String str)
Converts a String to a Boolean.
static Boolean
toBooleanObject(String str, String trueString, String falseString, 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(Boolean bool, int trueValue, int falseValue, int nullValue)
Converts a Boolean to an int specifying the conversion values.
static Integer
toIntegerObject(boolean bool)
Converts a boolean to an Integer using the convention that zero is false.
static Integer
toIntegerObject(boolean bool, Integer trueValue, Integer falseValue)
Converts a boolean to an Integer specifying the conversion values.
static Integer
toIntegerObject(Boolean bool)
Converts a Boolean to a Integer using the convention that zero is false.
static Integer
toIntegerObject(Boolean bool, Integer trueValue, Integer falseValue, Integer nullValue)
Converts a Boolean to an Integer specifying the conversion values.
static String
toString(boolean bool, String trueString, String falseString)
Converts a boolean to a String returning one of the input Strings.
static String
toString(Boolean bool, String trueString, String falseString, String nullString)
Converts a Boolean to a String returning one of the input Strings.
static String
toStringOnOff(boolean bool)
Converts a boolean to a String returning 'on' or 'off'.
static String
toStringOnOff(Boolean bool)
Converts a Boolean to a String returning 'on', 'off', or null.
static String
toStringTrueFalse(boolean bool)
Converts a boolean to a String returning 'true' or 'false'.
static String
toStringTrueFalse(Boolean bool)
Converts a Boolean to a String returning 'true', 'false', or null.
static String
toStringYesNo(boolean bool)
Converts a boolean to a String returning 'yes' or 'no'.
static String
toStringYesNo(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 Boolean
xor(Boolean[] array)
Performs an xor on an array of Booleans.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

BooleanUtils

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 Details

isFalse

public static boolean isFalse(Boolean bool)
Checks if a Boolean value is false, handling null by returning false.
   BooleanUtils.isFalse(Boolean.TRUE)  = false
   BooleanUtils.isFalse(Boolean.FALSE) = true
   BooleanUtils.isFalse(null)          = false
 
Parameters:
bool - the boolean to check, null returns false
Returns:
true only if the input is non-null and false
Since:
2.1

isNotFalse

public static boolean isNotFalse(Boolean bool)
Checks if a Boolean value is not false, handling null by returning true.
   BooleanUtils.isNotFalse(Boolean.TRUE)  = true
   BooleanUtils.isNotFalse(Boolean.FALSE) = false
   BooleanUtils.isNotFalse(null)          = true
 
Parameters:
bool - the boolean to check, null returns true
Returns:
true if the input is null or true
Since:
2.3

isNotTrue

public static boolean isNotTrue(Boolean bool)
Checks if a Boolean value is not true, handling null by returning true.
   BooleanUtils.isNotTrue(Boolean.TRUE)  = false
   BooleanUtils.isNotTrue(Boolean.FALSE) = true
   BooleanUtils.isNotTrue(null)          = true
 
Parameters:
bool - the boolean to check, null returns true
Returns:
true if the input is null or false
Since:
2.3

isTrue

public static boolean isTrue(Boolean bool)
Checks if a Boolean value is true, handling null by returning false.
   BooleanUtils.isTrue(Boolean.TRUE)  = true
   BooleanUtils.isTrue(Boolean.FALSE) = false
   BooleanUtils.isTrue(null)          = false
 
Parameters:
bool - the boolean to check, null returns false
Returns:
true only if the input is non-null and true
Since:
2.1

negate

public static Boolean negate(Boolean bool)
Negates the specified boolean.

If null is passed in, null will be returned.

   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 null if null input

toBoolean

public static boolean toBoolean(int value)
Converts an int to a boolean using the convention that zero is false.
   BooleanUtils.toBoolean(0) = false
   BooleanUtils.toBoolean(1) = true
   BooleanUtils.toBoolean(2) = true
 
Parameters:
value - the int to convert
Returns:
true if non-zero, false if zero
Usages and Demos :

View More Examples of toBoolean(int value)
   1: import org.apache.commons.lang.StringUtils;
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.math.NumberUtils;
   4:         ...
   5:     public boolean getPropertyAsBoolean(String key) {
   6:         return BooleanUtils.toBoolean((String) this.properties.get(key));
   7:     }
   8:         ...
   9:         
  10:         return BooleanUtils.toBoolean(value);
  11:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.StringUtils;
   4:         ...
   5:             if (StringUtils.isNotEmpty(activeString)) {
   6:                 si.active = BooleanUtils.toBoolean(activeString);
   7:             }
   8:             else {
   9:                 si.active = true;

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.StringUtils;
   4:         ...
   5:     public static boolean showPreview(HttpServletRequest req) {
   6:         return BooleanUtils.toBoolean((Boolean) req.getSession().getAttribute(MGNL_PREVIEW_ATTRIBUTE));
   7:     }
   8: }

View Full Code Here
   1: import org.andromda.cartridges.spring.SpringProfile;
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.ObjectUtils;
   4:         ...
   5:         {
   6:             result = BooleanUtils.toBoolean(value);
   7:         }
   8:         return result;
   9:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.dom4j.Document;
   4:         ...
   5:             
   6:             boolean skinDefault = BooleanUtils.toBoolean(skinElement.attributeValue("default"));
   7:             String skinName = skinElement.attributeValue("name");
   8:         ...
   9:             boolean skinXhtml = BooleanUtils.toBoolean(skinElement.attributeValue("xhtml"));
  10:         ...
  11:             boolean xslCache = BooleanUtils.toBoolean(xslElement.attributeValue("cache"));

View Full Code Here

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 convert
trueValue - the value to match for true
falseValue - the value to match for false
Returns:
true or false
Throws:
IllegalArgumentException - if no match

toBoolean

public static boolean toBoolean(Boolean bool)
Converts a Boolean to a boolean handling null by returning false.
   BooleanUtils.toBoolean(Boolean.TRUE)  = true
   BooleanUtils.toBoolean(Boolean.FALSE) = false
   BooleanUtils.toBoolean(null)          = false
 
Parameters:
bool - the boolean to convert
Returns:
true or false, null returns false
Usages and Demos :

View More Examples of toBoolean(Boolean bool)
   1: import org.apache.commons.lang.StringUtils;
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.math.NumberUtils;
   4:         ...
   5:     public boolean getPropertyAsBoolean(String key) {
   6:         return BooleanUtils.toBoolean((String) this.properties.get(key));
   7:     }
   8:         ...
   9:         
  10:         return BooleanUtils.toBoolean(value);
  11:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.StringUtils;
   4:         ...
   5:             if (StringUtils.isNotEmpty(activeString)) {
   6:                 si.active = BooleanUtils.toBoolean(activeString);
   7:             }
   8:             else {
   9:                 si.active = true;

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.StringUtils;
   4:         ...
   5:     public static boolean showPreview(HttpServletRequest req) {
   6:         return BooleanUtils.toBoolean((Boolean) req.getSession().getAttribute(MGNL_PREVIEW_ATTRIBUTE));
   7:     }
   8: }

View Full Code Here
   1: import org.andromda.cartridges.spring.SpringProfile;
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.ObjectUtils;
   4:         ...
   5:         {
   6:             result = BooleanUtils.toBoolean(value);
   7:         }
   8:         return result;
   9:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.dom4j.Document;
   4:         ...
   5:             
   6:             boolean skinDefault = BooleanUtils.toBoolean(skinElement.attributeValue("default"));
   7:             String skinName = skinElement.attributeValue("name");
   8:         ...
   9:             boolean skinXhtml = BooleanUtils.toBoolean(skinElement.attributeValue("xhtml"));
  10:         ...
  11:             boolean xslCache = BooleanUtils.toBoolean(xslElement.attributeValue("cache"));

View Full Code Here

toBoolean

public static boolean toBoolean(Integer value,
                                Integer trueValue,
                                Integer falseValue)
Converts an Integer to a boolean specifying the conversion values.
   BooleanUtils.toBoolean(new Integer(0), new Integer(1), new Integer(0)) = false
   BooleanUtils.toBoolean(new Integer(1), new Integer(1), new Integer(0)) = true
   BooleanUtils.toBoolean(new Integer(2), new Integer(1), new Integer(2)) = false
   BooleanUtils.toBoolean(new Integer(2), new Integer(2), new Integer(0)) = true
   BooleanUtils.toBoolean(null, null, new Integer(0))                     = true
 
Parameters:
value - the Integer to convert
trueValue - the value to match for true, may be null
falseValue - the value to match for false, may be null
Returns:
true or false
Throws:
IllegalArgumentException - if no match

toBoolean

public static boolean toBoolean(String str)
Converts a String to a boolean (optimised for performance).

'true', 'on' 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' 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
 
Parameters:
str - the String to check
Returns:
the boolean value of the string, false if no match
Usages and Demos :

View More Examples of toBoolean(String str)
   1: import org.apache.commons.lang.StringUtils;
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.math.NumberUtils;
   4:         ...
   5:     public boolean getPropertyAsBoolean(String key) {
   6:         return BooleanUtils.toBoolean((String) this.properties.get(key));
   7:     }
   8:         ...
   9:         
  10:         return BooleanUtils.toBoolean(value);
  11:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.StringUtils;
   4:         ...
   5:             if (StringUtils.isNotEmpty(activeString)) {
   6:                 si.active = BooleanUtils.toBoolean(activeString);
   7:             }
   8:             else {
   9:                 si.active = true;

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.StringUtils;
   4:         ...
   5:     public static boolean showPreview(HttpServletRequest req) {
   6:         return BooleanUtils.toBoolean((Boolean) req.getSession().getAttribute(MGNL_PREVIEW_ATTRIBUTE));
   7:     }
   8: }

View Full Code Here
   1: import org.andromda.cartridges.spring.SpringProfile;
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.ObjectUtils;
   4:         ...
   5:         {
   6:             result = BooleanUtils.toBoolean(value);
   7:         }
   8:         return result;
   9:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.dom4j.Document;
   4:         ...
   5:             
   6:             boolean skinDefault = BooleanUtils.toBoolean(skinElement.attributeValue("default"));
   7:             String skinName = skinElement.attributeValue("name");
   8:         ...
   9:             boolean skinXhtml = BooleanUtils.toBoolean(skinElement.attributeValue("xhtml"));
  10:         ...
  11:             boolean xslCache = BooleanUtils.toBoolean(xslElement.attributeValue("cache"));

View Full Code Here

toBoolean

public static boolean toBoolean(String str,
                                String trueString,
                                String falseString)
Converts a String to a Boolean throwing an exception if no match found.

null is returned if there is no match.

   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 be null
falseString - the String to match for false (case sensitive), may be null
Returns:
the boolean value of the string
Throws:
IllegalArgumentException - if the String doesn't match

toBooleanDefaultIfNull

public static boolean toBooleanDefaultIfNull(Boolean bool,
                                             boolean valueIfNull)
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 convert
valueIfNull - the boolean value to return if null
Returns:
true or false
Usages and Demos :

View More Examples of toBooleanDefaultIfNull(Boolean bool,boolean valueIfNull)
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.weblayouttag.WebLayoutRuntimeException;
   4:         ...
   5:     public boolean isFilter() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(filter,this.getDefaultFilter());
   7:     }
   8:         ...
   9:     public void setFilter(boolean filter) {
  10:         this.filter = BooleanUtils.toBooleanObject(filter);
  11:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.math.RandomUtils;
   4:         ...
   5:     public boolean isEscapeXml() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(escapeXml,true);
   7:     }
   8:         ...
   9:     public void setEscapeXml(boolean escapeXml) {
  10:         this.escapeXml = BooleanUtils.toBooleanObject(escapeXml);
  11:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.ObjectUtils;
   4:         ...
   5:     public boolean isFilter() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(filter,this.getDefaultFilter());
   7:     }
   8:         ...
   9:     public void setFilter(boolean filter) {
  10:         this.filter = BooleanUtils.toBooleanObject(filter);
  11:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.ObjectUtils;
   4:         ...
   5:     public boolean isFilter() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(filter,this.getDefaultFilter());
   7:     }
   8:         ...
   9:     public void setFilter(boolean filter) {
  10:         this.filter = BooleanUtils.toBooleanObject(filter);
  11:     }
  12:         ...
  13:     public boolean isRedisplay() {
  14:         return BooleanUtils.toBooleanDefaultIfNull(redisplay,this.getDefaultRedisplay());

View Full Code Here

toBooleanObject

public static 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.

   BooleanUtils.toBooleanObject(false) = Boolean.FALSE
   BooleanUtils.toBooleanObject(true)  = Boolean.TRUE
 
Parameters:
bool - the boolean to convert
Returns:
Boolean.TRUE or Boolean.FALSE as appropriate
Usages and Demos :

View More Examples of toBooleanObject(boolean bool)
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.weblayouttag.WebLayoutRuntimeException;
   4:         ...
   5:     public boolean isFilter() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(filter,this.getDefaultFilter());
   7:     }
   8:         ...
   9:     public void setFilter(boolean filter) {
  10:         this.filter = BooleanUtils.toBooleanObject(filter);
  11:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.math.RandomUtils;
   4:         ...
   5:     public boolean isEscapeXml() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(escapeXml,true);
   7:     }
   8:         ...
   9:     public void setEscapeXml(boolean escapeXml) {
  10:         this.escapeXml = BooleanUtils.toBooleanObject(escapeXml);
  11:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: 
   4:         ...
   5:     public Object getValue() {
   6:         return BooleanUtils.toBooleanObject(this.value);
   7:     }
   8: 
   9:     public int hashCode() {

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.ObjectUtils;
   4:         ...
   5:     public boolean isFilter() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(filter,this.getDefaultFilter());
   7:     }
   8:         ...
   9:     public void setFilter(boolean filter) {
  10:         this.filter = BooleanUtils.toBooleanObject(filter);
  11:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.ObjectUtils;
   4:         ...
   5:     public boolean isFilter() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(filter,this.getDefaultFilter());
   7:     }
   8:         ...
   9:     public void setFilter(boolean filter) {
  10:         this.filter = BooleanUtils.toBooleanObject(filter);
  11:     }
  12:         ...
  13:     public boolean isRedisplay() {
  14:         return BooleanUtils.toBooleanDefaultIfNull(redisplay,this.getDefaultRedisplay());

View Full Code Here

toBooleanObject

public static Boolean toBooleanObject(int value)
Converts an int to a Boolean using the convention that zero is false.
   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, null if null
Usages and Demos :

View More Examples of toBooleanObject(int value)
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.weblayouttag.WebLayoutRuntimeException;
   4:         ...
   5:     public boolean isFilter() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(filter,this.getDefaultFilter());
   7:     }
   8:         ...
   9:     public void setFilter(boolean filter) {
  10:         this.filter = BooleanUtils.toBooleanObject(filter);
  11:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.math.RandomUtils;
   4:         ...
   5:     public boolean isEscapeXml() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(escapeXml,true);
   7:     }
   8:         ...
   9:     public void setEscapeXml(boolean escapeXml) {
  10:         this.escapeXml = BooleanUtils.toBooleanObject(escapeXml);
  11:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: 
   4:         ...
   5:     public Object getValue() {
   6:         return BooleanUtils.toBooleanObject(this.value);
   7:     }
   8: 
   9:     public int hashCode() {

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.ObjectUtils;
   4:         ...
   5:     public boolean isFilter() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(filter,this.getDefaultFilter());
   7:     }
   8:         ...
   9:     public void setFilter(boolean filter) {
  10:         this.filter = BooleanUtils.toBooleanObject(filter);
  11:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.ObjectUtils;
   4:         ...
   5:     public boolean isFilter() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(filter,this.getDefaultFilter());
   7:     }
   8:         ...
   9:     public void setFilter(boolean filter) {
  10:         this.filter = BooleanUtils.toBooleanObject(filter);
  11:     }
  12:         ...
  13:     public boolean isRedisplay() {
  14:         return BooleanUtils.toBooleanDefaultIfNull(redisplay,this.getDefaultRedisplay());

View Full Code Here

toBooleanObject

public static Boolean toBooleanObject(int value,
                                      int trueValue,
                                      int falseValue,
                                      int nullValue)
Converts an int to a Boolean specifying the conversion values.
   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 convert
trueValue - the value to match for true
falseValue - the value to match for false
nullValue - the value to to match for null
Returns:
Boolean.TRUE, Boolean.FALSE, or null
Throws:
IllegalArgumentException - if no match

toBooleanObject

public static Boolean toBooleanObject(Integer value)
Converts an Integer to a Boolean using the convention that zero is false.

null will be converted to null.

   BooleanUtils.toBoolean(new Integer(0))    = Boolean.FALSE
   BooleanUtils.toBoolean(new Integer(1))    = Boolean.TRUE
   BooleanUtils.toBoolean(new Integer(null)) = null
 
Parameters:
value - the Integer to convert
Returns:
Boolean.TRUE if non-zero, Boolean.FALSE if zero, null if null input
Usages and Demos :

View More Examples of toBooleanObject(Integer value)
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.weblayouttag.WebLayoutRuntimeException;
   4:         ...
   5:     public boolean isFilter() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(filter,this.getDefaultFilter());
   7:     }
   8:         ...
   9:     public void setFilter(boolean filter) {
  10:         this.filter = BooleanUtils.toBooleanObject(filter);
  11:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.math.RandomUtils;
   4:         ...
   5:     public boolean isEscapeXml() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(escapeXml,true);
   7:     }
   8:         ...
   9:     public void setEscapeXml(boolean escapeXml) {
  10:         this.escapeXml = BooleanUtils.toBooleanObject(escapeXml);
  11:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: 
   4:         ...
   5:     public Object getValue() {
   6:         return BooleanUtils.toBooleanObject(this.value);
   7:     }
   8: 
   9:     public int hashCode() {

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.ObjectUtils;
   4:         ...
   5:     public boolean isFilter() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(filter,this.getDefaultFilter());
   7:     }
   8:         ...
   9:     public void setFilter(boolean filter) {
  10:         this.filter = BooleanUtils.toBooleanObject(filter);
  11:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.ObjectUtils;
   4:         ...
   5:     public boolean isFilter() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(filter,this.getDefaultFilter());
   7:     }
   8:         ...
   9:     public void setFilter(boolean filter) {
  10:         this.filter = BooleanUtils.toBooleanObject(filter);
  11:     }
  12:         ...
  13:     public boolean isRedisplay() {
  14:         return BooleanUtils.toBooleanDefaultIfNull(redisplay,this.getDefaultRedisplay());

View Full Code Here

toBooleanObject

public static Boolean toBooleanObject(Integer value,
                                      Integer trueValue,
                                      Integer falseValue,
                                      Integer nullValue)
Converts an Integer to a Boolean specifying the conversion values.
   BooleanUtils.toBooleanObject(new Integer(0), new Integer(0), new Integer(2), new Integer(3)) = Boolean.TRUE
   BooleanUtils.toBooleanObject(new Integer(2), new Integer(1), new Integer(2), new Integer(3)) = Boolean.FALSE
   BooleanUtils.toBooleanObject(new Integer(3), new Integer(1), new Integer(2), new Integer(3)) = null
 
Parameters:
value - the Integer to convert
trueValue - the value to match for true, may be null
falseValue - the value to match for false, may be null
nullValue - the value to to match for null, may be null
Returns:
Boolean.TRUE, Boolean.FALSE, or null
Throws:
IllegalArgumentException - if no match

toBooleanObject

public static Boolean toBooleanObject(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.

   BooleanUtils.toBooleanObject(null)    = null
   BooleanUtils.toBooleanObject("true")  = Boolean.TRUE
   BooleanUtils.toBooleanObject("false") = Boolean.FALSE
   BooleanUtils.toBooleanObject("on")    = Boolean.TRUE
   BooleanUtils.toBooleanObject("ON")    = Boolean.TRUE
   BooleanUtils.toBooleanObject("off")   = Boolean.FALSE
   BooleanUtils.toBooleanObject("oFf")   = Boolean.FALSE
   BooleanUtils.toBooleanObject("blue")  = null
 
Parameters:
str - the String to check
Returns:
the Boolean value of the string, null if no match or null input
Usages and Demos :

View More Examples of toBooleanObject(String str)
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.weblayouttag.WebLayoutRuntimeException;
   4:         ...
   5:     public boolean isFilter() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(filter,this.getDefaultFilter());
   7:     }
   8:         ...
   9:     public void setFilter(boolean filter) {
  10:         this.filter = BooleanUtils.toBooleanObject(filter);
  11:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.math.RandomUtils;
   4:         ...
   5:     public boolean isEscapeXml() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(escapeXml,true);
   7:     }
   8:         ...
   9:     public void setEscapeXml(boolean escapeXml) {
  10:         this.escapeXml = BooleanUtils.toBooleanObject(escapeXml);
  11:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: 
   4:         ...
   5:     public Object getValue() {
   6:         return BooleanUtils.toBooleanObject(this.value);
   7:     }
   8: 
   9:     public int hashCode() {

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.ObjectUtils;
   4:         ...
   5:     public boolean isFilter() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(filter,this.getDefaultFilter());
   7:     }
   8:         ...
   9:     public void setFilter(boolean filter) {
  10:         this.filter = BooleanUtils.toBooleanObject(filter);
  11:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: import org.apache.commons.lang.ObjectUtils;
   4:         ...
   5:     public boolean isFilter() {
   6:         return BooleanUtils.toBooleanDefaultIfNull(filter,this.getDefaultFilter());
   7:     }
   8:         ...
   9:     public void setFilter(boolean filter) {
  10:         this.filter = BooleanUtils.toBooleanObject(filter);
  11:     }
  12:         ...
  13:     public boolean isRedisplay() {
  14:         return BooleanUtils.toBooleanDefaultIfNull(redisplay,this.getDefaultRedisplay());

View Full Code Here

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.
   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 check
trueString - 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
Returns:
the Boolean value of the string, null if either the String matches nullString or if null input and nullString is null
Throws:
IllegalArgumentException - if the String doesn't match

toInteger

public static int toInteger(boolean bool)
Converts a boolean to an int using the convention that zero is false.
   BooleanUtils.toInteger(true)  = 1
   BooleanUtils.toInteger(false) = 0
 
Parameters:
bool - the boolean to convert
Returns:
one if true, zero if false

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 convert
trueValue - the value to return if true
falseValue - the value to return if false
Returns:
the appropriate value

toInteger

public static int toInteger(Boolean bool,
                            int trueValue,
                            int falseValue,
                            int nullValue)
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 true
falseValue - the value to return if false
nullValue - the value to return if null
Returns:
the appropriate value

toIntegerObject

public static Integer toIntegerObject(boolean bool)
Converts a boolean to an Integer using the convention that zero is false.
   BooleanUtils.toIntegerObject(true)  = new Integer(1)
   BooleanUtils.toIntegerObject(false) = new Integer(0)
 
Parameters:
bool - the boolean to convert
Returns:
one if true, zero if false

toIntegerObject

public static Integer toIntegerObject(boolean bool,
                                      Integer trueValue,
                                      Integer falseValue)
Converts a boolean to an Integer specifying the conversion values.
   BooleanUtils.toIntegerObject(true, new Integer(1), new Integer(0))  = new Integer(1)
   BooleanUtils.toIntegerObject(false, new Integer(1), new Integer(0)) = new Integer(0)
 
Parameters:
bool - the to convert
trueValue - the value to return if true, may be null
falseValue - the value to return if false, may be null
Returns:
the appropriate value

toIntegerObject

public static Integer toIntegerObject(Boolean bool)
Converts a Boolean to a Integer using the convention that zero is false.

null will be converted to null.

   BooleanUtils.toIntegerObject(Boolean.TRUE)  = new Integer(1)
   BooleanUtils.toIntegerObject(Boolean.FALSE) = new Integer(0)
 
Parameters:
bool - the Boolean to convert
Returns:
one if Boolean.TRUE, zero if Boolean.FALSE, null if null

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, new Integer(1), new Integer(0), new Integer(2))  = new Integer(1)
   BooleanUtils.toIntegerObject(Boolean.FALSE, new Integer(1), new Integer(0), new Integer(2)) = new Integer(0)
   BooleanUtils.toIntegerObject(null, new Integer(1), new Integer(0), new Integer(2))          = new Integer(2)
 
Parameters:
bool - the Boolean to convert
trueValue - 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
Returns:
the appropriate value

toString

public static String toString(boolean bool,
                              String trueString,
                              String falseString)
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 be null
falseString - the String to return if false, may be null
Returns:
one of the two input Strings

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 check
trueString - 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
Returns:
one of the three input Strings

toStringOnOff

public static String toStringOnOff(boolean bool)
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', or null

toStringOnOff

public static String toStringOnOff(Boolean bool)
Converts a Boolean to a String returning 'on', 'off', or null.
   BooleanUtils.toStringOnOff(Boolean.TRUE)  = "on"
   BooleanUtils.toStringOnOff(Boolean.FALSE) = "off"
   BooleanUtils.toStringOnOff(null)          = null;
 
Parameters:
bool - the Boolean to check
Returns:
'on', 'off', or null

toStringTrueFalse

public static String toStringTrueFalse(boolean bool)
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', or null
Usages and Demos :

View More Examples of toStringTrueFalse(boolean bool)
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: 
   4:         ...
   5:         PersistenceManagerFactoryImpl retval = new PersistenceManagerFactoryImpl();
   6:         retval.setOptimistic(Boolean.getBoolean(props.getProperty(JDOConstants.OPTIMISTIC, BooleanUtils.toStringTrueFalse(retval.getOptimistic()))));
   7:         ...
   8:         retval.setRetainValues(Boolean.getBoolean(props.getProperty(JDOConstants.RETAIN_VALUES, BooleanUtils.toStringTrueFalse(retval.getRetainValues()))));
   9:         ...
  10:         retval.setRestoreValues(Boolean.getBoolean(props.getProperty(JDOConstants.RESTORE_VALUES, BooleanUtils.toStringTrueFalse(retval.getRestoreValues()))));

View Full Code Here

toStringTrueFalse

public static String toStringTrueFalse(Boolean bool)
Converts a Boolean to a String returning 'true', 'false', or null.
   BooleanUtils.toStringTrueFalse(Boolean.TRUE)  = "true"
   BooleanUtils.toStringTrueFalse(Boolean.FALSE) = "false"
   BooleanUtils.toStringTrueFalse(null)          = null;
 
Parameters:
bool - the Boolean to check
Returns:
'true', 'false', or null
Usages and Demos :

View More Examples of toStringTrueFalse(Boolean bool)
   1: 
   2: import org.apache.commons.lang.BooleanUtils;
   3: 
   4:         ...
   5:         PersistenceManagerFactoryImpl retval = new PersistenceManagerFactoryImpl();
   6:         retval.setOptimistic(Boolean.getBoolean(props.getProperty(JDOConstants.OPTIMISTIC, BooleanUtils.toStringTrueFalse(retval.getOptimistic()))));
   7:         ...
   8:         retval.setRetainValues(Boolean.getBoolean(props.getProperty(JDOConstants.RETAIN_VALUES, BooleanUtils.toStringTrueFalse(retval.getRetainValues()))));
   9:         ...
  10:         retval.setRestoreValues(Boolean.getBoolean(props.getProperty(JDOConstants.RESTORE_VALUES, BooleanUtils.toStringTrueFalse(retval.getRestoreValues()))));

View Full Code Here

toStringYesNo

public static String toStringYesNo(boolean bool)
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', or null

toStringYesNo

public static String toStringYesNo(Boolean bool)
Converts a Boolean to a String returning 'yes', 'no', or null.
   BooleanUtils.toStringYesNo(Boolean.TRUE)  = "yes"
   BooleanUtils.toStringYesNo(Boolean.FALSE) = "no"
   BooleanUtils.toStringYesNo(null)          = null;
 
Parameters:
bool - the Boolean to check
Returns:
'yes', 'no', or null

xor

public static boolean xor(boolean[] array)
Performs an xor on a set of booleans.
   BooleanUtils.xor(new boolean[] { true, true })   = false
   BooleanUtils.xor(new boolean[] { false, false }) = false
   BooleanUtils.xor(new boolean[] { true, false })  = true
 
Parameters:
array - an array of booleans
Returns:
true if the xor is successful.
Throws:
IllegalArgumentException - if array is null
IllegalArgumentException - if array is empty.

xor

public static Boolean xor(Boolean[] array)
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 of Booleans
Returns:
true if the xor is successful.
Throws:
IllegalArgumentException - if array is null
IllegalArgumentException - if array is empty.
IllegalArgumentException - if array contains a null