<commit_before>package org.qfox.jestful.commons.conversion;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Map转换器
 *
 * @author 杨昌沛 <EMAIL>
 * @date 2018-06-04 11:21
 **/
public class MapConverter implements Converter<Map<?, ?>> {

    @Override
    public boolean supports(Class<?> type) {
        return Map.class.isAssignableFrom(type);
    }

    @Override
    public Map<String, String[]> convert(String name, Map<?, ?> value, ConversionProvider provider) throws Exception {
        Map<String, String[]> map = new LinkedHashMap<String, String[]>();
        for (Map.Entry<?, ?> entry : value.entrySet()) {
            Map<String, String[]> m = provider.convert(name + "['" + entry.getValue() + "']", entry.getValue());
            map.putAll(m);
        }
        return map;
    }

    @Override
    public boolean supports(Conversion conversion) {
        return conversion.type instanceof ParameterizedType
                && ((ParameterizedType) conversion.type).getRawType() == Map.class;
    }

    @Override
    public Map<?, ?> convert(Conversion conversion, ConversionProvider provider) throws Exception {
        if (!supports(conversion)) return (Map<?, ?>) conversion.value;
        ParameterizedType mapType = (ParameterizedType) conversion.type;
        Type keyType = mapType.getActualTypeArguments()[0];
        Type valueType = mapType.getActualTypeArguments()[1];
        if (conversion.name.isEmpty()) {
            Map map = conversion.value != null ? (Map<?, ?>) conversion.value : new LinkedHashMap();
            Conversion kcvs = new Conversion(KEY, null, keyType, conversion.decoded, conversion.charset, KEY, new String[]{conversion.expression});
            Object key = provider.convert(kcvs);
            Object value = map.get(key);
            Conversion vcvs = new Conversion(KEY, value, valueType, conversion.decoded, conversion.charset, KEY, conversion.values);
            value = provider.convert(vcvs);
            map.put(key, value);
            return map;
        } else if (conversion.expression.startsWith(conversion.name + ".")) {
            String expression = conversion.expression.substring(conversion.name.length() + 1);<commit_msg>1. 客户端处理 @Matrix 注解的参数<commit_after>package org.qfox.jestful.commons.conversion;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Map转换器
 *
 * @author 杨昌沛 <EMAIL>
 * @date 2018-06-04 11:21
 **/
public class MapConverter implements Converter<Map<?, ?>> {

    @Override
    public boolean supports(Class<?> type) {
        return Map.class.isAssignableFrom(type);
    }

    @Override
    public Map<String, String[]> convert(String name, Map<?, ?> value, ConversionProvider provider) throws Exception {
        Map<String, String[]> map = new LinkedHashMap<String, String[]>();
        for (Map.Entry<?, ?> entry : value.entrySet()) {
            Map<String, String[]> m = provider.convert(name + "['" + entry.getKey() + "']", entry.getValue());
            map.putAll(m);
        }
        return map;
    }

    @Override
    public boolean supports(Conversion conversion) {
        return conversion.type instanceof ParameterizedType
                && ((ParameterizedType) conversion.type).getRawType() == Map.class;
    }

    @Override
    public Map<?, ?> convert(Conversion conversion, ConversionProvider provider) throws Exception {
        if (!supports(conversion)) return (Map<?, ?>) conversion.value;
        ParameterizedType mapType = (ParameterizedType) conversion.type;
        Type keyType = mapType.getActualTypeArguments()[0];
        Type valueType = mapType.getActualTypeArguments()[1];
        if (conversion.name.isEmpty()) {
            Map map = conversion.value != null ? (Map<?, ?>) conversion.value : new LinkedHashMap();
            Conversion kcvs = new Conversion(KEY, null, keyType, conversion.decoded, conversion.charset, KEY, new String[]{conversion.expression});
            Object key = provider.convert(kcvs);
            Object value = map.get(key);
            Conversion vcvs = new Conversion(KEY, value, valueType, conversion.decoded, conversion.charset, KEY, conversion.values);
            value = provider.convert(vcvs);
            map.put(key, value);
            return map;
        } else if (conversion.expression.startsWith(conversion.name + ".")) {
            String expression = conversion.expression.substring(conversion.name.length() + 1);
{'fraction_non_alphanumeric': 0.13198859899144924, 'fraction_numerical': 0.006796755097566323, 'mean_word_length': 3.121047877145438, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '2408613', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1261, 'n_words': 294}