PropertiesUtil


package top.ibase4j.core.util;

import java.util.HashMap;
import java.util.Map;
import java.util.MissingResourceException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import top.ibase4j.core.util.DataUtil;

public final class PropertiesUtil extends PropertyPlaceholderConfigurer {
    private static Map, String> ctxPropertiesMap = new HashMap();

    public PropertiesUtil() {
    }

    public static Map, String> getProperties() {
        return ctxPropertiesMap;
    }

    public static String getString(String key) {
        try {
            return (String)ctxPropertiesMap.get(key);
        } catch (MissingResourceException var2) {
            return null;
        }
    }

    public static String getString(String key, String defaultValue) {
        try {
            String e = (String)ctxPropertiesMap.get(key);
            return DataUtil.isEmpty(e)?defaultValue:e;
        } catch (MissingResourceException var3) {
            return defaultValue;
        }
    }

    public static Integer getInt(String key) {
        String value = (String)ctxPropertiesMap.get(key);
        return value != null && !"".equals(value.trim())?Integer.valueOf(Integer.parseInt(value)):null;
    }

    public static int getInt(String key, int defaultValue) {
        String value = (String)ctxPropertiesMap.get(key);
        return StringUtils.isBlank(value)?defaultValue:Integer.parseInt(value);
    }

    public static long getLong(String keyName, long defaultValue) {
        String value = getString(keyName);
        if(value != null && value.length() > 0) {
            try {
                long e = Long.parseLong(value.trim());
                return e;
            } catch (Exception var6) {
                return defaultValue;
            }
        } else {
            return defaultValue;
        }
    }

    public static boolean getBoolean(String key, boolean defaultValue) {
        String value = (String)ctxPropertiesMap.get(key);
        return StringUtils.isBlank(value)?defaultValue:(new Boolean(value.trim())).booleanValue();
    }
}

你可能感兴趣的:(工具类)