
package com.xiang.xservice.application.generator.util;

import java.util.Map;

public class MapUtil {
    public static String getString(Map map, String key) {
        if (map != null && map.containsKey(key)) {
            try {
                return map.get(key).toString();
            } catch (Exception e) {
                e.printStackTrace();
                return "";
            }
        } else {
            return "";
        }
    }

    public static Integer getInteger(Map map, String key) {
        if (map != null && map.containsKey(key)) {
            try {
                return Integer.valueOf(map.get(key).toString());
            } catch (Exception e) {
                e.printStackTrace();
                return 0;
            }
        } else {
            return 0;
        }
    }

    public static Boolean getBoolean(Map map, String key) {
        if (map != null && map.containsKey(key)) {
            try {
                return Boolean.parseBoolean(map.get(key).toString()) || "true".equals(map.get(key).toString());
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
        } else {
            return false;
        }
    }
}
