class TypeConverter {

    public static Double convertToDouble(final Object value) throws TypeConversionException {
        if (value instanceof Number) {
            return ((Number) value).doubleValue();
        }
        if (value instanceof String) {
            if (((String) value).isEmpty()) {
                return 0.0;
            }
            try {
                return Double.valueOf((String) value);
            } catch (NumberFormatException ex) {
                return Double.NaN;
            }
        }
        if (value instanceof Boolean) {
            return (Boolean) value ? 1.0 : 0.0;
        }
        if (value == null) {
            return Double.NaN;
        }
        // Java Object hasn't default method like a JavaScript
        // so the arbitrary object can't to be cast to Double type.
        throw new TypeConversionException("Failed converted to number: unrecognized type of the given value!");
    }

}