<commit_before>package com.wizzardo.tools.json;

import java.util.Map;

/**
 * @author: wizzardo
 * Date: 3/14/14
 */
public class JavaMapBinder extends JavaObjectBinder {
    private Map that;
    private Generic[] type;
    private boolean valueIsMap;
    private JsonFieldSetter valueSetter;
    private StringConverter keyConverter;

    public JavaMapBinder(Generic generic) {
        super(generic);
        that = (Map) object;
        type = getTypes(generic);
        valueIsMap = Map.class.isAssignableFrom(type[1].clazz);
        keyConverter = StringConverter.getConverter(type[0].clazz);
        valueSetter = getValueSetter(type[1].clazz);
    }

    protected JsonFieldSetter getValueSetter(Class classValue) {
        final StringConverter valueConverter = StringConverter.getConverter(classValue);
        if (valueConverter == null || keyConverter == null)
            return null;

        return new JsonFieldSetter.ObjectSetter() {
            @Override
            public void setString(Object object, String value) {
                put(keyConverter, valueConverter, value);
            }

            @Override
            public void setObject(Object object, Object value) {
                put(keyConverter, value);
            }

            @Override
            public Type getType() {
                return valueConverter.type;
            }
        };
    }

    protected void put(StringConverter keyConverter, StringConverter valueConverter, String value) {
        put(keyConverter, valueConverter.convert(value));
    }

    protected void put(StringConverter keyConverter, Object value) {
        that.put(keyConverter.convert(tempKey), value);
    }

    @Override
    protected Map createInstance(Class clazz) {
        return Binder.createMap(clazz);
    }

    private Generic[] getTypes(Generic generic) {
        if (generic == null)
            return new Generic[]{new Generic(Object.class), new Generic(Object.class)};

        if (generic.typeParameters.length != 2)
            return getTypes(generic.parent);
        return generic.typeParameters;
    }

    @Override
    public void add(Object value) {
        put(keyConverter, value);
    }

    @Override
    public void add(JsonItem value) {
        if (Binder.setValue(object, tempKey, value))
            return;

        that.put(JsonItem.getAs(tempKey, type[0].clazz), value.getAs(type[1].clazz));
    }

    @Override
    public JsonBinder getObjectBinder() {
        JsonBinder binder = super.getObjectBinder();
        if (binder != null)
            return binder;

        if (valueIsMap)
            return new JavaMapBinder(type[1]);
        else
            return new JavaObjectBinder(type[1]);
    }

    @Override
    public JsonBinder getArrayBinder() {
        JsonBinder binder = super.getArrayBinder();
        if (binder != null)
            return binder;

        return new JavaArrayBinder(type[1]);
    }

    @Override
    public JsonFieldSetter getFieldSetter() {
        return valueSetter;
    }
}<commit_msg>remove support of custom map implementations<commit_after>package com.wizzardo.tools.json;

import java.util.Map;

/**
 * @author: wizzardo
 * Date: 3/14/14
 */
public class JavaMapBinder extends JavaObjectBinder {
    private Map that;
    private Generic[] type;
    private boolean valueIsMap;
    private JsonFieldSetter valueSetter;
    private StringConverter keyConverter;

    public JavaMapBinder(Generic generic) {
        super(generic);
        that = (Map) object;
        type = getTypes(generic);
        valueIsMap = Map.class.isAssignableFrom(type[1].clazz);
        keyConverter = StringConverter.getConverter(type[0].clazz);
        valueSetter = getValueSetter(type[1].clazz);
    }

    protected JsonFieldSetter getValueSetter(Class classValue) {
        final StringConverter valueConverter = StringConverter.getConverter(classValue);
        if (valueConverter == null || keyConverter == null)
            return null;

        return new JsonFieldSetter.ObjectSetter() {
            @Override
            public void setString(Object object, String value) {
                put(keyConverter, valueConverter, value);
            }

            @Override
            public void setObject(Object object, Object value) {
                put(keyConverter, value);
            }

            @Override
            public Type getType() {
                return valueConverter.type;
            }
        };
    }

    protected void put(StringConverter keyConverter, StringConverter valueConverter, String value) {
        put(keyConverter, valueConverter.convert(value));
    }

    protected void put(StringConverter keyConverter, Object value) {
        that.put(keyConverter.convert(tempKey), value);
    }

    @Override
    protected Map createInstance(Class clazz) {
        return Binder.createMap(clazz);
    }

    private Generic[] getTypes(Generic generic) {
        if (generic == null)
            return new Generic[]{new Generic(Object.class), new Generic(Object.class)};

        if (generic.typeParameters.length != 2)
            return getTypes(generic.parent);
        return generic.typeParameters;
    }

    @Override
    public void add(Object value) {
        put(keyConverter, value);
    }

    @Override
    public void add(JsonItem value) {
        if (Binder.setValue(object, tempKey, value))
            return;

        that.put(JsonItem.getAs(tempKey, type[0].clazz), value.getAs(type[1].clazz));
    }

    @Override
    public JsonBinder getObjectBinder() {
        if (valueIsMap)
            return new JavaMapBinder(type[1]);
        else
            return new JavaObjectBinder(type[1]);
    }

    @Override
    public JsonBinder getArrayBinder() {
        return new JavaArrayBinder(type[1]);
    }

    @Override
    public JsonFieldSetter getFieldSetter() {
        return valueSetter;
    }
}
{'fraction_non_alphanumeric': 0.0928813559322034, 'fraction_numerical': 0.0047457627118644066, 'mean_word_length': 2.410982658959538, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5327785', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1542, 'n_words': 375}