Java Code Examples for org.apache.commons.lang3.BooleanUtils#toBooleanObject()

The following examples show how to use org.apache.commons.lang3.BooleanUtils#toBooleanObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QuerydslUtils.java    From gvnix with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Return an expression for {@code entityPath.fieldName} (for Booleans) with
 * the {@code operator} or "equal" by default.
 * <p/>
 * Expr: {@code entityPath.fieldName eq searchObj}
 * 
 * @param entityPath
 * @param fieldName
 * @param searchObj
 * @param operator
 * @return
 */
public static <T> BooleanExpression createBooleanExpression(
        PathBuilder<T> entityPath, String fieldName, Object searchObj,
        String operator) {
    Boolean value = BooleanUtils.toBooleanObject((String) searchObj);
    if (value != null) {
        if (StringUtils.equalsIgnoreCase(operator, OPERATOR_GOE)) {
            return entityPath.getBoolean(fieldName).goe(value);
        }
        else if (StringUtils.equalsIgnoreCase(operator, "gt")) {
            return entityPath.getBoolean(fieldName).gt(value);
        }
        else if (StringUtils.equalsIgnoreCase(operator, OPERATOR_LOE)) {
            return entityPath.getBoolean(fieldName).loe(value);
        }
        else if (StringUtils.equalsIgnoreCase(operator, "lt")) {
            return entityPath.getBoolean(fieldName).lt(value);
        }
    }
    return entityPath.get(fieldName).eq(searchObj);
}
 
Example 2
Source File: OutputPanel.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static ExportChoices getChoice(String value)
{
	Boolean choice = BooleanUtils.toBooleanObject(value);
	if (choice == null)
	{
		return ExportChoices.ASK;
	}
	else if (choice)
	{
		return ExportChoices.ALWAYS_OPEN;
	}
	else
	{
		return ExportChoices.NEVER_OPEN;
	}
}
 
Example 3
Source File: MapTools.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public static Boolean getBoolean(Map<?, ?> map, Object key, Boolean defaultValue) {
	Boolean value = defaultValue;
	if (null != map) {
		Object o = map.get(key);
		if (!Objects.isNull(o)) {
			if (o instanceof Boolean) {
				value = (Boolean) o;
			} else if (o instanceof String) {
				String t = (String) o;
				value = BooleanUtils.toBooleanObject(t);
				if (null == value) {
					value = defaultValue;
				}
			}
		}
	}
	return value;
}
 
Example 4
Source File: PropertyConverter.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the specified object into a Boolean. Internally the
 * {@code org.apache.commons.lang.BooleanUtils} class from the
 * <a href="https://commons.apache.org/lang/">Commons Lang</a>
 * project is used to perform this conversion. This class accepts some more
 * tokens for the boolean value of <b>true</b>, e.g. {@code yes} and
 * {@code on}. Please refer to the documentation of this class for more
 * details.
 *
 * @param value the value to convert
 * @return the converted value
 * @throws ConversionException thrown if the value cannot be converted to a boolean
 */
public static Boolean toBoolean(final Object value) throws ConversionException
{
    if (value instanceof Boolean)
    {
        return (Boolean) value;
    }
    else if (value instanceof String)
    {
        final Boolean b = BooleanUtils.toBooleanObject((String) value);
        if (b == null)
        {
            throw new ConversionException("The value " + value + " can't be converted to a Boolean object");
        }
        return b;
    }
    else
    {
        throw new ConversionException("The value " + value + " can't be converted to a Boolean object");
    }
}
 
Example 5
Source File: AbstractOAuth2Base.java    From apiman with Apache License 2.0 6 votes vote down vote up
protected static void createOrDescend(JsonObject root, Deque<String> keyPath, String value) {
    // If there are still key-path elements remaining to traverse.
    if (keyPath.size() > 1) {
        // If there's no object already at this key-path create a new JsonObject.
        if (root.getJsonObject(keyPath.peek()) == null) {
            JsonObject newJson = new JsonObject();
            String val = keyPath.pop();
            root.put(val, newJson);
            createOrDescend(newJson, keyPath, value);
        } else { // If there's already an existing object on key-path, grab it and traverse.
            createOrDescend(root.getJsonObject(keyPath.pop()), keyPath, value);
        }
    } else { // Set the value.
        Boolean boolObj = BooleanUtils.toBooleanObject(value);
        if (boolObj != null) {
            root.put(keyPath.pop(), boolObj);
        } else if (StringUtils.isNumeric(value)) {
            root.put(keyPath.pop(), Long.parseLong(value));
        } else {
            root.put(keyPath.pop(), value);
        }
    }
}
 
Example 6
Source File: ExportImportConfigParser.java    From apiman with Apache License 2.0 5 votes vote down vote up
public boolean isOverwrite() {
    Boolean booleanObject = BooleanUtils.toBooleanObject(System.getProperty(OVERWRITE));
    if (booleanObject == null) {
        booleanObject = Boolean.FALSE;
    }
    return booleanObject;
}
 
Example 7
Source File: GoEnvironment.java    From gocd-s3-artifacts with Apache License 2.0 5 votes vote down vote up
public boolean hasAWSUseIamRole() {
    if (!has(AWS_USE_IAM_ROLE)) {
        return false;
    }

    String useIamRoleValue = get(AWS_USE_IAM_ROLE);
    Boolean result = BooleanUtils.toBooleanObject(useIamRoleValue);
    if (result == null) {
        throw new IllegalArgumentException(getEnvInvalidFormatMessage(AWS_USE_IAM_ROLE,
                useIamRoleValue, validUseIamRoleValues.toString()));
    }
    else {
        return result.booleanValue();
    }
}
 
Example 8
Source File: FilterEntry.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public Boolean available() {
	if (StringUtils.isEmpty(path)) {
		return false;
	}
	if (StringUtils.isEmpty(logic)) {
		return false;
	}
	if (StringUtils.isEmpty(comparison)) {
		return false;
	}
	if (null == formatType) {
		return false;
	}
	switch (formatType) {
	case textValue:
		return true;
	case booleanValue:
		if (null == BooleanUtils.toBooleanObject(value)) {
			return false;
		} else {
			return true;
		}
	case dateTimeValue:
		if (DateTools.isDateTimeOrDateOrTime(value)) {
			return true;
		} else {
			return false;
		}
	case numberValue:
		if (NumberUtils.isNumber(value)) {
			return true;
		} else {
			return false;
		}
	}
	return false;
}
 
Example 9
Source File: QuerydslUtilsBeanImpl.java    From gvnix with GNU General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public <T> BooleanExpression createBooleanExpression(
        PathBuilder<T> entityPath, String fieldName, String searchStr) {
    if (StringUtils.isBlank(searchStr)) {
        return null;
    }

    Boolean value = null;

    // I18N: Spanish (normalize search value: trim start-end and lower case)
    if ("si".equals(StringUtils.trim(searchStr).toLowerCase())) {
        value = Boolean.TRUE;
    }
    else {
        value = BooleanUtils.toBooleanObject(searchStr);
    }

    // if cannot parse to boolean or null input
    if (value == null) {
        return null;
    }

    BooleanExpression expression = entityPath.getBoolean(fieldName).eq(
            value);
    return expression;
}
 
Example 10
Source File: InitializerServiceImpl.java    From openmrs-module-initializer with MIT License 5 votes vote down vote up
@Override
public Boolean getBooleanFromKey(String key, Boolean defaultInstance) {
	String val = getValueFromKey(key);
	if (StringUtils.isEmpty(val)) {
		return defaultInstance;
	}
	try {
		return BooleanUtils.toBoolean(val, "1", "0");
	}
	catch (IllegalArgumentException e) {
		return BooleanUtils.toBooleanObject(val);
	}
}
 
Example 11
Source File: BooleanValueParser.java    From synopsys-detect with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public Boolean parse(@NotNull final String value) throws ValueParseException {
    String trimmed = value.toLowerCase().trim();
    if (StringUtils.isBlank(trimmed)) {
        return true;
    } else {
        Boolean aBoolean = BooleanUtils.toBooleanObject(trimmed);
        if (aBoolean == null) {
            throw new ValueParseException(value, "boolean", "Unknown boolean format. Supported values include true and false.");
        } else {
            return aBoolean;
        }
    }
}
 
Example 12
Source File: SolrCLI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void ensureArgumentIsValidBooleanIfPresent(CommandLine cli, String argName) {
  if (cli.hasOption(argName)) {
    final String value = cli.getOptionValue(argName);
    final Boolean parsedBoolean = BooleanUtils.toBooleanObject(value);
    if (parsedBoolean == null) {
      echo("Argument [" + argName + "] must be either true or false, but was [" + value + "]");
      exit(1);
    }
  }
}
 
Example 13
Source File: JpaStorage.java    From apiman with Apache License 2.0 5 votes vote down vote up
private Boolean parseBoolValue(Object object) {
    if (object instanceof Boolean) {
        return (Boolean) object;
    } else if (object instanceof Number) {
        Byte num = ((Number) object).byteValue();
        return num > 0;
    }
    return BooleanUtils.toBooleanObject(String.valueOf(object));
}
 
Example 14
Source File: ValueNormalizationUtil.java    From moneta with Apache License 2.0 5 votes vote down vote up
/**
 * Will convert a String into the specified property type.  Integer, Long, Boolean, and String supported.
 * @param targetType
 * @param value
 * @return convertedValue
 */
public static Object convertString(Class targetType, String value) {
	Validate.notNull(targetType, "Null targetType not allowed.");
	if (value == null) {
		return value;
	}
	if (ClassUtils.isAssignable(targetType, String.class)) {
		return value;
	}
	if (ClassUtils.isAssignable(targetType, Integer.class)) {
		return Integer.valueOf(value);
	}
	if (ClassUtils.isAssignable(targetType, int.class)) {
		return Integer.valueOf(value);
	}
	if (ClassUtils.isAssignable(targetType, Long.class)) {
		return Long.valueOf(value);
	}
	if (ClassUtils.isAssignable(targetType, long.class)) {
		return Long.valueOf(value);
	}
	Boolean bValue = BooleanUtils.toBooleanObject(value);
	if (bValue != null) {
		return bValue;
	}
	
	throw new MonetaException("Property type not supported")
		.addContextValue("targetType", targetType.getName());
}
 
Example 15
Source File: BooleanUtil.java    From j360-dubbo-app-all with Apache License 2.0 4 votes vote down vote up
/**
 * 支持true/false,on/off, y/n, yes/no的转换, str为空或无法分析时返回null
 */
public static Boolean parseGeneralString(String str) {
	return BooleanUtils.toBooleanObject(str);
}
 
Example 16
Source File: ScriptFactory.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public static Boolean asBoolean(Object o) throws Exception {
	return BooleanUtils.toBooleanObject(Objects.toString(o));
}
 
Example 17
Source File: Filter.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public Boolean available() {
	if (StringUtils.isEmpty(path)) {
		return false;
	}
	if (StringUtils.isEmpty(logic)) {
		return false;
	}
	if (StringUtils.isEmpty(comparison)) {
		return false;
	}
	if (null == formatType) {
		return false;
	}
	switch (StringUtils.trimToEmpty(formatType)) {
	case FORMAT_TEXTVALUE:
		return true;
	case FORMAT_BOOLEANVALUE:
		if (null == BooleanUtils.toBooleanObject(value)) {
			return false;
		} else {
			return true;
		}
	case FORMAT_DATETIMEVALUE:
		if (DateTools.isDateTimeOrDateOrTime(value)) {
			return true;
		} else {
			return false;
		}
	case FORMAT_DATEVALUE:
		if (DateTools.isDateTimeOrDateOrTime(value)) {
			return true;
		} else {
			return false;
		}
	case FORMAT_TIMEVALUE:
		if (DateTools.isDateTimeOrDateOrTime(value)) {
			return true;
		} else {
			return false;
		}
	case FORMAT_NUMBERVALUE:
		if (NumberUtils.isCreatable(value)) {
			return true;
		} else {
			return false;
		}
	}
	return false;
}
 
Example 18
Source File: BooleanUtil.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 支持true/false, on/off, y/n, yes/no的转换, str为空或无法分析时返回null
 */
public static Boolean parseGeneralString(String str) {
	return BooleanUtils.toBooleanObject(str);
}
 
Example 19
Source File: BooleanUtil.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 支持true/false, on/off, y/n, yes/no的转换, str为空或无法分析时返回null
 */
public static Boolean parseGeneralString(String str) {
	return BooleanUtils.toBooleanObject(str);
}
 
Example 20
Source File: BooleanWrapper.java    From uyuni with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets the boolean value to true if the aBool is 1, false if aBool is 0.
 * @param aBool the value to be used
 */
public void setBool(Integer aBool) {
    bool = BooleanUtils.toBooleanObject(aBool);
}