package com.platform.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author abnerhou
 * @date 2020/9/9 17:58
 * @desciption
 */
@Service
@Slf4j
public class ControllerUtils {

    /**
     *  根据map的key进行字典升序排序
     * @param map
     * @return map
     */
    public Map<String, Object> sortMapByKey(Map<String, Object>map) {
        Map<String, Object> treemap = new TreeMap<String, Object>(map);
        List<Map.Entry<String, Object>> list = new ArrayList<Map.Entry<String, Object>>(treemap.entrySet());
        Collections.sort(list, new Comparator<Map.Entry<String, Object>>() {
            @Override
            public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) {
                return org.apache.commons.lang3.StringUtils.compare(o1.getKey() , o2.getKey());
            }
        });
        return treemap;
    }
}
