类 CommonUtil


  • public class CommonUtil
    extends Object
    通用工具
    作者:
    frankcl
    • 构造器详细资料

      • CommonUtil

        public CommonUtil()
    • 方法详细资料

      • stringToTime

        public static Long stringToTime​(String string,
                                        String format)
        字符串转换时间戳
        参数:
        string - 时间字符串
        format - 时间格式,如果为空使用默认格式
        返回:
        成功返回毫秒时间戳,否则返回null
      • timeToString

        public static String timeToString​(long timestamp,
                                          String format)
        时间戳转换字符串
        参数:
        timestamp - 毫秒时间戳
        format - 时间格式
        返回:
        成功返回字符串表示,否则返回null
      • getHost

        public static String getHost​(String str)
        获取URL中host
        参数:
        str - URL字符串
        返回:
        如果url合法返回host,否则返回空字符串
      • isLetter

        public static boolean isLetter​(char c)
        判断字符是否为字母
        参数:
        c - 字符
        返回:
        如果是字母返回true,否则返回false
      • isDigit

        public static boolean isDigit​(char c)
        判断字符是否为数字
        参数:
        c - 字符
        返回:
        如果是数字返回true,否则返回false
      • isSpace

        public static boolean isSpace​(char c)
        判断字符是否为空白字符
        参数:
        c - 字符
        返回:
        如果是空白字符返回true,否则返回false
      • isIP

        public static boolean isIP​(String str)
        判断是否为IP
        参数:
        str - 字符串
        返回:
        符合IP规范返回true,否则返回false
      • round

        public static double round​(double v,
                                   int n)
        取小数点后n位数字
        参数:
        v - 浮点数
        n - 小数点后保留位数
        返回:
        浮点数
      • isPrime

        public static boolean isPrime​(int n)
        判断一个整数是否为质数
        参数:
        n - 整数
        返回:
        质数返回true,否则返回false
      • findNextPrime

        public static int findNextPrime​(int n)
        找到比n大的第一个质数
        参数:
        n -
        返回:
        比n大的第一个质数
      • isPrimitiveType

        public static boolean isPrimitiveType​(Object object)
        判断对象是否为Java原型
        参数:
        object - 对象
        返回:
        是原型返回true,否则返回false