org.apache.commons.beanutils.converters.BooleanConverter Java Examples

The following examples show how to use org.apache.commons.beanutils.converters.BooleanConverter. 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: FieldHolder.java    From bluetooth-gatt-parser with Apache License 2.0 5 votes vote down vote up
private AbstractConverter getConverter() {
    FieldFormat fieldFormat = field.getFormat();
    int size = fieldFormat.getSize();
    switch (fieldFormat.getType()) {
        case BOOLEAN: return new BooleanConverter();
        case UINT:
            if (size < 32) {
                return new IntegerConverter();
            } else if (size < 64) {
                return new LongConverter();
            } else {
                return new BigIntegerConverter();
            }
        case SINT:
            if (size <= 32) {
                return new IntegerConverter();
            } else if (size <= 64) {
                return new LongConverter();
            } else {
                return new BigIntegerConverter();
            }
        case FLOAT_IEE754:
        case FLOAT_IEE11073: return size <= 32 ? new FloatConverter() : new DoubleConverter();
        case UTF8S:
        case UTF16S: return new StringConverter();
        default:
            throw new IllegalStateException("Unsupported field format: " + fieldFormat.getType());
    }
}
 
Example #2
Source File: ConvertUtil.java    From feilong-core with Apache License 2.0 5 votes vote down vote up
/**
 * Register standard default null.
 * 
 * @see ConvertUtilsBean#registerPrimitives(boolean) registerPrimitives(boolean throwException)
 * @see ConvertUtilsBean#registerStandard(boolean,boolean) registerStandard(boolean throwException, boolean defaultNull)
 * @see ConvertUtilsBean#registerOther(boolean) registerOther(boolean throwException)
 * @see ConvertUtilsBean#registerArrays(boolean,int) registerArrays(boolean throwException, int defaultArraySize)
 * @see ConvertUtilsBean#deregister(Class) ConvertUtilsBean.deregister(Class)
 * @since 1.11.2
 */
public static void registerStandardDefaultNull(){
    ConvertUtils.register(new BigDecimalConverter(null), BigDecimal.class);
    ConvertUtils.register(new BigIntegerConverter(null), BigInteger.class);
    ConvertUtils.register(new BooleanConverter(null), Boolean.class);
    ConvertUtils.register(new ByteConverter(null), Byte.class);
    ConvertUtils.register(new CharacterConverter(null), Character.class);
    ConvertUtils.register(new DoubleConverter(null), Double.class);
    ConvertUtils.register(new FloatConverter(null), Float.class);
    ConvertUtils.register(new IntegerConverter(null), Integer.class);
    ConvertUtils.register(new LongConverter(null), Long.class);
    ConvertUtils.register(new ShortConverter(null), Short.class);
    ConvertUtils.register(new StringConverter(null), String.class);
}
 
Example #3
Source File: KualiActionServlet.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
    * <p>Initialize other global characteristics of the controller servlet.</p>
    * Overridden to remove the ConvertUtils.deregister() command that caused problems
    * with the concurrent data dictionary load.  (KULRNE-4405)
    *
    * @exception ServletException if we cannot initialize these resources
    */
   @Override
protected void initOther() throws ServletException {

       String value = null;
       value = getServletConfig().getInitParameter("config");
       if (value != null) {
           config = value;
       }

       // Backwards compatibility for form beans of Java wrapper classes
       // Set to true for strict Struts 1.0 compatibility
       value = getServletConfig().getInitParameter("convertNull");
       if ("true".equalsIgnoreCase(value)
           || "yes".equalsIgnoreCase(value)
           || "on".equalsIgnoreCase(value)
           || "y".equalsIgnoreCase(value)
           || "1".equalsIgnoreCase(value)) {

           convertNull = true;
       }

       if (convertNull) {
           ConvertUtils.register(new BigDecimalConverter(null), BigDecimal.class);
           ConvertUtils.register(new BigIntegerConverter(null), BigInteger.class);
           ConvertUtils.register(new BooleanConverter(null), Boolean.class);
           ConvertUtils.register(new ByteConverter(null), Byte.class);
           ConvertUtils.register(new CharacterConverter(null), Character.class);
           ConvertUtils.register(new DoubleConverter(null), Double.class);
           ConvertUtils.register(new FloatConverter(null), Float.class);
           ConvertUtils.register(new IntegerConverter(null), Integer.class);
           ConvertUtils.register(new LongConverter(null), Long.class);
           ConvertUtils.register(new ShortConverter(null), Short.class);
       }

       // KULRICE-8176: KFS Notes/Attachments Tab Functionality for Note Text Error - Visible/Special characters, spaces, or tabs
       parameterEncoding = getServletConfig().getInitParameter("PARAMETER_ENCODING");
   }
 
Example #4
Source File: FieldHolder.java    From bluetooth-gatt-parser with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a Boolean representation of the field or a default value in case if the field cannot
 * be converted to a Boolean.
 * @param def the default value to be returned if an error occurs converting the field
 * @return a Boolean representation of the field
 */
public Boolean getBoolean(Boolean def) {
    return new BooleanConverter(def).convert(Boolean.class, prepareValue());
}
 
Example #5
Source File: ConvertUtil.java    From feilong-core with Apache License 2.0 2 votes vote down vote up
/**
 * 将 <code>toBeConvertedValue</code> 转换成 {@link Boolean}类型.
 * 
 * <h3>示例:</h3>
 * 
 * <blockquote>
 * 
 * <pre class="code">
 * 
 * ConvertUtil.toBoolean(null)      =   null
 * 
 * ConvertUtil.toBoolean(1L)        =   true
 * ConvertUtil.toBoolean("1")       =   true
 * ConvertUtil.toBoolean("9")       =   null
 * ConvertUtil.toBoolean("1,2,3")   =   null
 * </pre>
 * 
 * </blockquote>
 * 
 * <h3>逻辑及规则:</h3>
 * 
 * <blockquote>
 * 
 * <ul>
 * <li>如果 "true", "yes", "y", "on", "1" <span style="color:green">(忽视大小写)</span>, 返回 true</li>
 * <li>如果 "false", "no", "n", "off", "0" <span style="color:green">(忽视大小写)</span>, 返回 false</li>
 * <li>其他抛出 conversionException, 但是在
 * {@link org.apache.commons.beanutils.converters.AbstractConverter#handleError(Class, Object, Throwable) handleError(Class, Object,
 * Throwable)} 方法里面返回默认值 是 null
 * </ul>
 * 
 * <p>
 * 你也可以调用 {@link org.apache.commons.beanutils.converters.BooleanConverter#BooleanConverter(String[], String[], Object)
 * BooleanConverter(String[], String[], Object)} 设置 trueStrings 和 falseStrings
 * </p>
 * </blockquote>
 * 
 * <h3>和 {@link Boolean#parseBoolean(String)}的区别:</h3>
 * 
 * <blockquote>
 * <p>
 * {@link Boolean#parseBoolean(String)},仅当 <code>(String != null) 并且 String.equalsIgnoreCase("true")</code> 返回 true
 * </p>
 * </blockquote>
 * 
 * @param toBeConvertedValue
 *            object
 * @return 如果 <code>toBeConvertedValue</code> 是null,返回null<br>
 * @see #convert(Object, Class)
 * @see org.apache.commons.beanutils.converters.BooleanConverter
 * @see org.apache.commons.lang3.BooleanUtils
 * @see java.lang.Boolean#parseBoolean(String)
 */
public static Boolean toBoolean(Object toBeConvertedValue){
    return new BooleanConverter(null).convert(Boolean.class, toBeConvertedValue);
}