Package org.openl.util
Class BooleanUtils
java.lang.Object
org.openl.util.BooleanUtils
An utility for manipulating with booleans: - converting an object to a boolean value - logic operation with a boolean
array (and, or, xor)
- Author:
- Yury Molchan
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanConverts an Object to a boolean.static booleanConverts an Object to a boolean.static BooleantoBooleanObject(Object value) Converts an Object to a Boolean.static BooleantoBooleanObject(Object value, Boolean defaultValue) Converts an Object to a Boolean.static BooleantoBooleanObject(String str) Converts a String to a Boolean.
-
Method Details
-
toBoolean
Converts an Object to a boolean. For String value 'true', 'on', 'yes', 'y' or 't' (case insensitive) will return true. Otherwise, false is returned. For Integer value 0 will return false. Otherwise, true is returned.- Parameters:
value- Object value- Returns:
- boolean value
-
toBoolean
Converts an Object to a boolean. For String value 'true', 'on', 'yes', 'y' or 't' (case insensitive) will return true. Otherwise, false is returned. For Integer value 0 will return false. Otherwise, true is returned. Returns boolean value or default value if the input value is null or not a Boolean.- Parameters:
value- Object valuedefaultValue- The default boolean value to return if the value is null or not a Boolean- Returns:
- boolean value
-
toBooleanObject
Converts an Object to a Boolean. For String value 'true', 'on', 'yes', 'y' or 't' (case insensitive) will return true. 'false', 'off', 'no', 'n' or 'f' (case insensitive) will return false. Otherwise, null is returned. For Integer value 0 will return false, null will return null. Otherwise, true is returned.- Parameters:
value- Object value- Returns:
- Boolean value
-
toBooleanObject
Converts a String to a Boolean.
'true','on','y','t'or'yes'(case insensitive) will returntrue.'false','off','n','f'or'no'(case insensitive) will returnfalse. Otherwise,nullis returned.NOTE: This returns null and will throw a NullPointerException if autoboxed 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("blue") = null BooleanUtils.toBooleanObject("true ") = null // trailing space (too long) BooleanUtils.toBooleanObject("ono") = null // does not match on or no- Parameters:
str- the String to check; upper and lower case are treated as the same- Returns:
- the Boolean value of the string,
nullif no match ornullinput
-
toBooleanObject
Converts an Object to a Boolean. For String value 'true', 'on', 'yes', 'y' or 't' (case insensitive) will return true. 'false', 'off', 'no', 'n' or 'f' (case insensitive) will return false. Otherwise, null is returned. For Integer value 0 will return false, null will return null. Otherwise, true is returned. Returns Boolean value or default value if the input value is null or not a Boolean.- Parameters:
value- Object valuedefaultValue- The default Boolean value to return if the value is null or not a Boolean- Returns:
- Boolean value
-