package com.lanyuanxiaoyao.service.common.utils;

import java.util.Map;

/**
 * Map工具类
 *
 * @author ZhangJiacheng
 * @date 2023-03-20
 */
public class MapHelper {
    // 如果大小写同时存在，那么这个忽略大小写的方案就会首先返回大写键的值
    public static Object getWithoutCase(Map<String, ?> map, String key) {
        String upperKey = key.toUpperCase(), lowerKey = key.toLowerCase();
        return map.containsKey(upperKey) ? map.get(upperKey) : map.containsKey(lowerKey) ? map.get(lowerKey) : map.get(key);
    }

    public static String getStringWithoutCase(Map<String, ?> map, String key) {
        return (String) getWithoutCase(map, key);
    }

    public static Integer getIntWithoutCase(Map<String, ?> map, String key) {
        return (Integer) getWithoutCase(map, key);
    }

    public static Long getLongWithoutCase(Map<String, ?> map, String key) {
        return (Long) getWithoutCase(map, key);
    }

    public static Double getDoubleWithoutCase(Map<String, ?> map, String key) {
        return (Double) getWithoutCase(map, key);
    }

    public static Float getFloatWithoutCase(Map<String, ?> map, String key) {
        return (Float) getWithoutCase(map, key);
    }
}
