class ToDouble
        implements Function {
    final Double defaultValue;

    public ToDouble(Double defaultValue) {
        this.defaultValue = defaultValue;
    }

    @Override
    public Object apply(Object o) {<FILL_FUNCTION_BODY>}
}

        if (o == null) {
            return defaultValue;
        }

        if (o instanceof Boolean) {
            return (Boolean) o ? 1D : 0D;
        }

        if (o instanceof Number) {
            return ((Number) o).doubleValue();
        }

        if (o instanceof String) {
            String str = (String) o;
            if (str.isEmpty()) {
                return defaultValue;
            }

            return Double.parseDouble(str);
        }

        if (o instanceof List) {
            List list = (List) o;
            JSONArray array = new JSONArray(list.size());
            for (int i = 0; i < list.size(); i++) {
                Object item = list.get(i);
                array.add(apply(item));
            }
            return array;
        }

        throw new JSONException("can not cast to Double " + o.getClass());
    
<no_super_class>