本文整理汇总了Java中org.apache.commons.lang.BooleanUtils.toBooleanObject方法的典型用法代码示例。如果您正苦于以下问题:Java BooleanUtils.toBooleanObject方法的具体用法?Java BooleanUtils.toBooleanObject怎么用?Java BooleanUtils.toBooleanObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang.BooleanUtils
的用法示例。
在下文中一共展示了BooleanUtils.toBooleanObject方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toBoolean
import org.apache.commons.lang.BooleanUtils; //导入方法依赖的package包/类
/**
* Convert the specified object into a Boolean. Internally the
* {@code org.apache.commons.lang.BooleanUtils} class from the <a
* href="http://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(Object value) throws ConversionException {
if (value instanceof Boolean) {
return (Boolean) value;
} else if (value instanceof String) {
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");
}
}
示例2: setValue
import org.apache.commons.lang.BooleanUtils; //导入方法依赖的package包/类
@Override
public void setValue(String value)
{
this.value = BooleanUtils.toBooleanObject(value);
this.value = this.value == null ? def : this.value;
config.set(path, this.value);
}
示例3: validateParameters
import org.apache.commons.lang.BooleanUtils; //导入方法依赖的package包/类
/**
* Validates the URI parameters for a given {@link DockerOperation}
*
* @param dockerOperation
* @param parameters
*/
public static void validateParameters(DockerOperation dockerOperation, Map<String, Object> parameters) {
Map<String, Class<?>> validParamMap = new HashMap<String, Class<?>>();
validParamMap.putAll(DockerConstants.DOCKER_DEFAULT_PARAMETERS);
validParamMap.putAll(dockerOperation.getParameters());
for (String key : parameters.keySet()) {
String transformedKey = DockerHelper.transformToHeaderName(key);
// Validate URI parameter name
if (!validParamMap.containsKey(transformedKey)) {
throw new DockerClientException(key + " is not a valid URI parameter");
}
try {
Class<?> parameterClass = validParamMap.get(transformedKey);
Object parameterValue = parameters.get(key);
if (parameterClass == null || parameterValue == null) {
throw new DockerClientException("Failed to validate parameter type for property " + key);
}
if (Integer.class == parameterClass) {
Integer.parseInt((String) parameterValue);
} else if (Boolean.class == parameterClass) {
BooleanUtils.toBooleanObject((String) parameterValue, "true", "false", "null");
}
} catch (Exception e) {
throw new DockerClientException("Failed to validate parameter type for property " + key);
}
}
}
示例4: getProperty
import org.apache.commons.lang.BooleanUtils; //导入方法依赖的package包/类
/**
* Attempts to locate a given property name within a URI parameter or the message header.
* A found value in a message header takes precedence over a URI parameter. Returns a
* default value if given
*
* @param name
* @param configuration
* @param message
* @param clazz
* @param defaultValue
* @return
*/
@SuppressWarnings("unchecked")
public static <T> T getProperty(String name, DockerConfiguration configuration, Message message, Class<T> clazz, T defaultValue) {
// First attempt to locate property from Message Header, then fallback to Endpoint property
if (message != null) {
T headerProperty = message.getHeader(name, clazz);
if (headerProperty != null) {
return headerProperty;
}
}
Object prop = configuration.getParameters().get(transformFromHeaderName(name));
if (prop != null) {
if (prop.getClass().isAssignableFrom(clazz)) {
return (T) prop;
} else if (Integer.class == clazz) {
return (T) Integer.valueOf((String) prop);
} else if (Boolean.class == clazz) {
return (T) BooleanUtils.toBooleanObject((String) prop, "true", "false", "null");
}
} else if (defaultValue != null) {
return defaultValue;
}
return null;
}
示例5: loadFontPreferences
import org.apache.commons.lang.BooleanUtils; //导入方法依赖的package包/类
protected void loadFontPreferences(Element element) {
// load font preferences
String fontFamily = element.attributeValue("fontFamily");
String fontSize = element.attributeValue("fontSize");
String fontStyle = element.attributeValue("fontStyle");
String fontUnderline = element.attributeValue("fontUnderline");
if (!StringUtils.isBlank(fontFamily) &&
!StringUtils.isBlank(fontSize) &&
!StringUtils.isBlank(fontUnderline) &&
!StringUtils.isBlank(fontStyle)) {
try {
int size = Integer.parseInt(fontSize);
int style = Integer.parseInt(fontStyle);
String[] availableFonts = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getAvailableFontFamilyNames();
int fontIndex = Arrays.asList(availableFonts).indexOf(fontFamily);
if (fontIndex < 0) {
log.debug("Unsupported font family, font settings not loaded");
return;
}
Configuration configuration = AppBeans.get(Configuration.NAME);
DesktopConfig desktopConfig = configuration.getConfig(DesktopConfig.class);
int sizeIndex = desktopConfig.getAvailableFontSizes().indexOf(size);
if (sizeIndex < 0) {
log.debug("Unsupported font size, font settings not loaded");
return;
}
Boolean underline = BooleanUtils.toBooleanObject(fontUnderline);
@SuppressWarnings("MagicConstant")
Font font = new Font(fontFamily, style, size);
if (underline != null && Boolean.TRUE.equals(underline)) {
Map<TextAttribute, Integer> attributes = new HashMap<>();
attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
font = font.deriveFont(attributes);
}
table.setFont(font);
} catch (NumberFormatException ex) {
log.debug("Broken font definition in user setting");
}
}
}
示例6: getProperty
import org.apache.commons.lang.BooleanUtils; //导入方法依赖的package包/类
/**
* Returns the property for the key as boolean. 'true', 'on' or 'yes' (case insensitive) will
* return true. 'false', 'off' or 'no' (case insensitive) will return false. If none of these
* values is set the fallback will be returned.
*
* @param key
* the key
* @param fallback
* the fallback to return if there is no property for the key or the property cannot
* be converted to boolean.
* @return the property value or the fallback if there is no property for the key or it cannot
* be converted into a boolean
*/
public boolean getProperty(T key, boolean fallback) {
Boolean result = BooleanUtils.toBooleanObject(getProperty(key));
if (result == null) {
result = fallback;
}
return result;
}
示例7: getProperty
import org.apache.commons.lang.BooleanUtils; //导入方法依赖的package包/类
/**
* Returns the property for the key as boolean. 'true', 'on' or 'yes' (case insensitive) will
* return true. 'false', 'off' or 'no' (case insensitive) will return false. If none of these
* values is set the fallback will be returned.
*
* @param key
* the key
* @param fallback
* the fallback to return if there is no property for the key
* @return the property value or the fallback if there is no property for the key or it cannot
* be converted into a boolean
*/
public boolean getProperty(String key, boolean fallback) {
Boolean result = BooleanUtils.toBooleanObject(getProperty(key));
if (result == null) {
result = fallback;
}
return result;
}
示例8: getValue
import org.apache.commons.lang.BooleanUtils; //导入方法依赖的package包/类
/**
* Gets the value as a Boolean instance.
*
* @return the value as a Boolean, never null
*/
public Object getValue() {
return BooleanUtils.toBooleanObject(this.value);
}
示例9: toBoolean
import org.apache.commons.lang.BooleanUtils; //导入方法依赖的package包/类
/**
* Gets this mutable as an instance of Boolean.
*
* @return a Boolean instance containing the value from this mutable, never null
* @since 2.5
*/
public Boolean toBoolean() {
return BooleanUtils.toBooleanObject(this.value);
}