package org.scy.common.utils;

import org.apache.commons.lang3.StringUtils;

/**
 * note: 定义一些公共方法，提供静态调用。
 * Created by hykj on 2017/8/15.
 */
public abstract class CommonUtilsEx {

    /**
     * 检查一个IP地址的格式是否正确
     * @param strIp 一个IP地址字符串
     * @return
     */
    public static boolean checkIP(String strIp) {
        if (StringUtils.isEmpty(strIp)) // 如果是空串，返回false
            return false;
        if (!"localhost".equals(strIp.toLowerCase())) { // 一般localhost也是允许的
            String[] strs = StringUtils.split(strIp, ".");
            if (strs.length != 4)
                return false; // IP长度为4
            for (int i = 0; i < 4; i++) {
                try {
                    int K = Integer.parseInt(strs[i]);
                    if (K < 0 || K > 255)
                        return false; // 必须是0到255之间的数字
                }
                catch(Exception e){
                    return false;
                }
            }
        }
        return true;
    }

    /**
     * 打印系统环境变量
     */
    public static void showSystemProperty() {
        System.out.println("java.version:" + System.getProperty("java.version"));
        System.out.println("java.vendor:" + System.getProperty("java.vendor"));
        System.out.println("java.vendor.url:" + System.getProperty("java.vendor.url"));
        System.out.println("java.home:" + System.getProperty("java.home"));
        System.out.println("java.vm.specification.version:" + System.getProperty("java.vm.specification.version"));
        System.out.println("java.vm.specification.vendor:" + System.getProperty("java.vm.specification.vendor"));
        System.out.println("java.vm.specification.name:" + System.getProperty("java.vm.specification.name"));
        System.out.println("java.vm.version:" + System.getProperty("java.vm.version"));
        System.out.println("java.vm.vendor:" + System.getProperty("java.vm.vendor"));
        System.out.println("java.vm.name:" + System.getProperty("java.vm.name"));
        System.out.println("java.specification.version:" + System.getProperty("java.specification.version"));
        System.out.println("java.specification.vendor:" + System.getProperty("java.specification.vendor"));
        System.out.println("java.specification.name:" + System.getProperty("java.specification.name"));
        System.out.println("java.class.version:" + System.getProperty("java.class.version"));
        System.out.println("java.class.path:" + System.getProperty("java.class.path"));
        System.out.println("java.library.path:" + System.getProperty("java.library.path"));
        System.out.println("java.io.tmpdir:" + System.getProperty("java.io.tmpdir"));
        System.out.println("java.compiler:" + System.getProperty("java.compiler"));
        System.out.println("java.ext.dirs:" + System.getProperty("java.ext.dirs"));
        System.out.println("os.name:" + System.getProperty("os.name"));
        System.out.println("os.arch:" + System.getProperty("os.arch"));
        System.out.println("os.version:" + System.getProperty("os.version"));
        System.out.println("file.separator:" + System.getProperty("file.separator"));
        System.out.println("path.separator:" + System.getProperty("path.separator"));
        System.out.println("line.separator:" + System.getProperty("line.separator"));
        System.out.println("user.name:" + System.getProperty("user.name"));
        System.out.println("user.home:" + System.getProperty("user.home"));
        System.out.println("user.dir:" + System.getProperty("user.dir"));
    }

}

@@ -70,16 +70,81 @@
 Utils;%0A%0A
+import java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0A
 /**%0A * n
@@ -202,16 +202,44 @@
 15.%0A */%0A
+@SuppressWarnings(%22unused%22)%0A
 public a
@@ -334,23 +334,8 @@
 %E5%AD%97%E7%AC%A6%E4%B8%B2%0A
-     * @return%0A
     
@@ -1018,32 +1018,32 @@
     %7D%0A        %7D%0A
-
         return t
@@ -1054,16 +1054,836 @@
 %0A    %7D%0A%0A
+    /**%0A     * %E6%A3%80%E6%9F%A5%E6%89%8B%E6%9C%BA%E5%8F%B7%E7%A0%81%E6%A0%BC%E5%BC%8F%E6%98%AF%E5%90%A6%E6%AD%A3%E7%A1%AE%0A     */%0A    public static boolean checkMobile(String mobile) %7B%0A        if (StringUtils.isNotBlank(mobile)) %7B%0A            String regExp = %22%5E1((3%5B0-9%5D)%7C(4%5B57%5D)%7C(5%5B0-35-9%5D)%7C(7%5B0135678%5D)%7C(8%5B0-9%5D))%5C%5Cd%7B8%7D$%22;%0A            Pattern pattern = Pattern.compile(regExp);%0A            Matcher matcher = pattern.matcher(mobile);%0A            return matcher.matches();%0A        %7D%0A        return false;%0A    %7D%0A%0A    /**%0A     * %E6%A3%80%E6%9F%A5%E9%82%AE%E7%AE%B1%E5%9C%B0%E5%9D%80%E6%A0%BC%E5%BC%8F%E6%98%AF%E5%90%A6%E6%AD%A3%E7%A1%AE%0A     */%0A    public static boolean checkEmail(String email) %7B%0A        if (StringUtils.isNotBlank(email)) %7B%0A            String regExp = %22%5E%5Ba-zA-Z0-9_-%5D+@%5Ba-zA-Z0-9_-%5D+(%5C%5C.%5Ba-zA-Z0-9_-%5D+)+$%22;%0A            Pattern pattern = Pattern.compile(regExp);%0A            Matcher matcher = pattern.matcher(email);%0A            return matcher.matches();%0A        %7D%0A        return false;%0A    %7D%0A%0A
     /**%0A

添加 CommonUtilsEx.isMobile() 和 CommonUtilsEx.isEmail() 方法