All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.enonic.xp.convert.BooleanConverter Maven / Gradle / Ivy

The newest version!
package com.enonic.xp.convert;

final class BooleanConverter
    implements Converter
{
    private static final String TRUE_FLAGS = "true|yes|on|1";

    @Override
    public Class getType()
    {
        return Boolean.class;
    }

    @Override
    public Boolean convert( final Object value )
    {
        if ( value instanceof Boolean )
        {
            return (Boolean) value;
        }

        if ( value instanceof Number )
        {
            return ( (Number) value ).intValue() != 0;
        }

        return TRUE_FLAGS.contains( value.toString() );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy