/** * Given a boolean in string format, it checks if it's 'true' or 'false' (case insensitive) * * @param booleanStr the string to check * @return true if booleanStr is 'true' or 'false' otherwise false */ public static boolean isValid(@Nullable final String booleanStr) { if (StringUtils.isBlank(booleanStr)) { return false; } final String lowerCaseBoolean = getLowerCaseString(booleanStr); return lowerCaseBoolean.equals(BooleanValues.TRUE) || lowerCaseBoolean.equals(BooleanValues.FALSE); }
/** * Given a boolean in string format, it checks if it's 'true' or 'false' (case insensitive) * * @param booleanStr the string to check * @return true if booleanStr is 'true' or 'false' otherwise false */ public static boolean isValid(@Nullable final String booleanStr) { if (StringUtils.isBlank(booleanStr)) { return false; } final String lowerCaseBoolean = getLowerCaseString(booleanStr); return lowerCaseBoolean.equals(BooleanValues.TRUE) || lowerCaseBoolean.equals(BooleanValues.FALSE); }
/** * If the booleanStr is a valid boolean (see isValid) it returns the boolean value, otherwise it throws an exception * * @param booleanStr the string to convert to boolean * @return true if the booleanStr is 'true', false if it's 'false' * @throws IllegalArgumentException if the booleanStr is not a valid boolean */ public static boolean toBoolean(@Nullable final String booleanStr) { if (!isValid(booleanStr)) { throw new IllegalArgumentException(booleanStr + ExceptionValues.EXCEPTION_DELIMITER + ExceptionValues.INVALID_BOOLEAN_VALUE); } return BooleanUtils.toBoolean(getLowerCaseString(booleanStr)); }
/** * If the booleanStr is a valid boolean (see isValid) it returns the boolean value, otherwise it throws an exception * * @param booleanStr the string to convert to boolean * @return true if the booleanStr is 'true', false if it's 'false' * @throws IllegalArgumentException if the booleanStr is not a valid boolean */ public static boolean toBoolean(@Nullable final String booleanStr) { if (!isValid(booleanStr)) { throw new IllegalArgumentException(booleanStr + ExceptionValues.EXCEPTION_DELIMITER + ExceptionValues.INVALID_BOOLEAN_VALUE); } return BooleanUtils.toBoolean(getLowerCaseString(booleanStr)); }