Java工具类

public class FormatUtils {
    private static final int DIGITNUM = 10;

    public FormatUtils() {
    }

    public static List<Integer> str2IntArray(String str) {
        return str2IntArray(str, ";");
    }

    public static List<Integer> str2IntArray(String str, String seperator) {
        List<Integer> ret = Lists.newArrayList();
        if (StringUtils.isEmpty(str)) {
            return ret;
        } else {
            String[] nums = str.split(seperator);
            String[] var4 = nums;
            int var5 = nums.length;

            for(int var6 = 0; var6 < var5; ++var6) {
                String num = var4[var6];
                ret.add(Integer.valueOf(num));
            }

            return ret;
        }
    }

    public static String intArray2Str(List<Integer> nums) {
        return intArray2Str(nums, ";");
    }

    public static String intArray2Str(List<Integer> nums, String seperator) {
        String str = null;
        if (nums == null) {
            return null;
        } else if (nums.isEmpty()) {
            return "";
        } else {
            for(int i = 0; i < nums.size(); ++i) {
                Integer num = (Integer)nums.get(i);
                if (i == 0) {
                    str = String.valueOf(num);
                } else {
                    str = str + seperator + num;
                }
            }

            return str;
        }
    }

    public static List<Long> str2LongArray(String str) {
        return str2LongArray(str, ";");
    }

    public static List<Long> str2LongArray(String str, String seperator) {
        List<Long> ret = Lists.newArrayList();
        if (StringUtils.isEmpty(str)) {
            return ret;
        } else {
            String[] nums = str.split(seperator);
            String[] var4 = nums;
            int var5 = nums.length;

            for(int var6 = 0; var6 < var5; ++var6) {
                String num = var4[var6];
                ret.add(Long.valueOf(num));
            }

            return ret;
        }
    }

    public static String longArray2Str(List<Long> nums) {
        return longArray2Str(nums, ";");
    }

    public static String longArray2Str(List<Long> nums, String seperator) {
        String str = null;
        if (nums == null) {
            return null;
        } else if (nums.isEmpty()) {
            return "";
        } else {
            for(int i = 0; i < nums.size(); ++i) {
                Long num = (Long)nums.get(i);
                if (i == 0) {
                    str = String.valueOf(num);
                } else {
                    str = str + seperator + num;
                }
            }

            return str;
        }
    }

    public static List<String> str2StrArray(String str) {
        return str2StrArray(str, ";");
    }

    public static List<String> str2StrArray(String str, String seperator) {
        if (StringUtils.isEmpty(str)) {
            return Lists.newArrayList();
        } else {
            String[] strs = str.split(seperator);
            List<String> ret = new ArrayList();
            String[] var4 = strs;
            int var5 = strs.length;

            for(int var6 = 0; var6 < var5; ++var6) {
                String url = var4[var6];
                ret.add(url);
            }

            return ret;
        }
    }

    public static String strArray2Str(List<String> strs) {
        return strArray2Str(strs, ";");
    }

    public static String strArray2Str(List<String> strs, String seperator) {
        StringBuilder ret = new StringBuilder();
        if (strs == null) {
            return null;
        } else if (strs.isEmpty()) {
            return "";
        } else {
            for(int i = 0; i < strs.size(); ++i) {
                String str = (String)strs.get(i);
                ret.append(str);
                if (i != strs.size() - 1) {
                    ret.append(seperator);
                }
            }

            return ret.toString();
        }
    }

    public static Map<String, String> str2StrMap(String mapStr) {
        Map<String, String> map = Maps.newHashMap();
        if (StringUtils.isEmpty(mapStr)) {
            return map;
        } else {
            String[] strList = mapStr.split(";");
            String[] var3 = strList;
            int var4 = strList.length;

            for(int var5 = 0; var5 < var4; ++var5) {
                String str = var3[var5];
                String[] kv = str.split(":");
                if (kv != null && kv.length == 2) {
                    map.put(kv[0], kv[1]);
                }
            }

            return map;
        }
    }

    public static String strMap2Str(Map<String, String> mapStr) {
        StringBuilder ret = new StringBuilder();
        if (CollectionUtils.isEmpty(mapStr)) {
            return ret.toString();
        } else {
            Set<Entry<String, String>> entrys = mapStr.entrySet();
            int i = 0;
            Iterator var4 = entrys.iterator();

            while(var4.hasNext()) {
                Entry<String, String> entry = (Entry)var4.next();
                if (entry.getKey() != null && entry.getValue() != null) {
                    ret.append((String)entry.getKey()).append(":").append((String)entry.getValue());
                    if (i != entrys.size() - 1) {
                        ret.append(";");
                    }

                    ++i;
                }
            }

            return ret.toString();
        }
    }

    public static String printStr(long num) {
        return printStr(10, num);
    }

    public static String printStr(int digitNum, long num) {
        return String.format("%0" + digitNum + "d", num);
    }

    public static <T> T mapToDTO(Map<?, ?> map, Class<T> clz) {
        return JSON.parseObject(JSON.toJSONString(map), clz);
    }

    public static Map<String, Object> dtoToMap(Object object) {
        return JSON.parseObject(JSON.toJSONString(object));
    }

    public static String toJsonString(Map<?, ?> map) {
        if (map == null) {
            return null;
        } else {
            return map.isEmpty() ? "" : JSON.toJSONString(map);
        }
    }

    public static Double formatDiscount(Integer discount) {
        return (double)discount / 10000.0D;
    }

    public static Integer formatDiscount(Double discount) {
        return Double.valueOf(discount * 10000.0D).intValue();
    }

    public static String mapToKeyValueStrSortByKey(Map<String, Object> map, String... ignoreParams) {
        if (CollectionUtils.isEmpty(map)) {
            return "";
        } else {
            List<String> ignoreList = ignoreParams != null ? Arrays.asList(ignoreParams) : null;
            String keyValueStr = (String)map.entrySet().stream().filter((entry) -> {
                return ignoreList == null || !ignoreList.contains(entry.getKey());
            }).sorted(Entry.comparingByKey()).map((entry) -> {
                return (String)entry.getKey() + entry.getValue();
            }).collect(Collectors.joining());
            return keyValueStr;
        }
    }

    public static String mapToValueStrSortByKey(Map<String, Object> map, String... ignoreParams) {
        if (CollectionUtils.isEmpty(map)) {
            return "";
        } else {
            List<String> ignoreList = ignoreParams != null ? Arrays.asList(ignoreParams) : null;
            String valueStr = (String)map.entrySet().stream().filter((entry) -> {
                return ignoreList == null || !ignoreList.contains(entry.getKey());
            }).sorted(Entry.comparingByKey()).map((entry) -> {
                return String.valueOf(entry.getValue());
            }).collect(Collectors.joining());
            return valueStr;
        }
    }

    public static String camelToSnake(String field) {
        String regex = "([a-z])([A-Z]+)";
        String replacement = "$1_$2";
        return field.replaceAll(regex, replacement).toLowerCase();
    }
}