Class StringUtil


  • public class StringUtil
    extends Object
    StringUtil
    Author:
    zhangjianshe@gmail.com
    • Constructor Detail

      • StringUtil

        public StringUtil()
    • Method Detail

      • trim

        public static String trim​(CharSequence cs)
        去掉字符串前后空白字符。空白字符的定义由Character.isWhitespace来判断
        Parameters:
        cs - 字符串
        Returns:
        去掉了前后空白字符的新字符串
      • isBlank

        public static boolean isBlank​(String cs)
      • isNotBlank

        public static boolean isNotBlank​(String cs)
      • formatFileSize

        public static String formatFileSize​(Long size)
      • brief

        public static String brief​(String str,
                                   int len)
        字符串简化版本
        Parameters:
        str -
        Returns:
      • formatDate

        public static String formatDate​(Date date)
      • formatDateS

        public static String formatDateS​(Date date)
      • formIsoDate

        public static String formIsoDate​(String time)
        2021-12-07T11:19:55.628922Z
        Parameters:
        time -
        Returns:
      • formatNumber

        public static String formatNumber​(Integer num,
                                          int length)
      • formatDouble

        public static String formatDouble​(Double num,
                                          int precision)
      • formatFloat

        public static String formatFloat​(Float num,
                                         int precision)
      • formatMillseconds

        public static String formatMillseconds​(long numberOfMilliseconds)
        格式化毫秒时间间隔
        Parameters:
        numberOfMilliseconds -
        Returns:
      • formatTimeSpan

        public static String formatTimeSpan​(Long estTime)
      • isLeapYear

        public static boolean isLeapYear​(int year)
      • formatTimeSpan

        public static String formatTimeSpan​(Long estTime,
                                            String suffix)
        格式化时间区间 < 60 分钟内 刚刚 < 60*60 小时内 n分钟前 < 24*60*60 天内 n小时前 < 7*24*60*60 周内 n天前 < 4*7*24*60*60 月内 n周前 < 365*24*60*60 年内 n月前 < 好几年 n年m月
        Parameters:
        estTime - 时间单位为秒 second
        Returns:
      • randomColor

        public static String randomColor()
      • randomString

        public static String randomString​(int length)
      • calMod

        public static int calMod​(int total,
                                 int mod)
        计算 total 除以 mod 后的 有效行数
        Parameters:
        total -
        mod -
        Returns:
      • departCssValue

        public static String[] departCssValue​(String s)
      • parseCssValue

        public static float parseCssValue​(String s)
      • isNumber

        public static boolean isNumber​(String value,
                                       String message,
                                       IShowMessage showMessage)
        检查是否是数字
        Parameters:
        value -
        message -
        showMessage -
        Returns:
      • last

        public static String last​(String name,
                                  String c)
        去最后一段 /abc/def/j98 返回 j98
        Parameters:
        name -
        c -
        Returns:
      • parseInteger

        public static Integer parseInteger​(String text,
                                           int defaultValue)
        不会产生异常的parseInt
        Parameters:
        text -
        defaultValue -
        Returns:
      • attachTo

        public static int attachTo​(int value,
                                   int step)
        将整型值 吸附到 按照step的网格上
        Parameters:
        value -
        step -
        Returns:
      • extractName

        public static String extractName​(String name)
        解析名字 将 名字前面的前缀 都去掉 比如 /ABC/DEF 返回 DEF
        Parameters:
        name -
        Returns:
      • extractBaseName

        public static String extractBaseName​(String location)
        解析名字 将 名字前面的前缀 都去掉 比如 /ABC/DEF.git 返回 DEF
        Parameters:
        location -
        Returns:
      • suffix

        public static String suffix​(String location)
        获取 文件的后缀名称 会转换为小写
        Parameters:
        location -
        Returns:
      • formatProgress

        public static String formatProgress​(Integer progress)
        格式化进度值 [0,100]->n% 其他的值 返回 -- 或者 空字符串
        Parameters:
        progress -
        Returns:
      • extractLocation

        public static String extractLocation​(String location)
      • obj2String

        public static String obj2String​(Object obj)
        Obj对象转为字符串
        Parameters:
        obj -
        Returns:
      • random

        public static double random​(double start,
                                    double end)
      • parseDouble

        public static Double parseDouble​(String value,
                                         double defaultValue)
      • extractSuffix

        public static String extractSuffix​(String name)
      • removeNumberPrefix

        public static String removeNumberPrefix​(String str)
      • parseNumberPrefix

        public static int parseNumberPrefix​(String str,
                                            int defaultValue)
      • isTrue

        public static boolean isTrue​(Boolean b)
        判断一个Boolean值是否为true
        Parameters:
        b -
        Returns:
      • numberToPath

        public static String numberToPath​(Long number)
        Converts a Long number to a path-like string by formatting it with '/' every three characters.
        Parameters:
        number - the Long number to convert
        Returns:
        the formatted path string
        Throws:
        IllegalArgumentException - if the number is null
      • stringToPath

        public static String stringToPath​(String str)
        Formats a string by inserting '/' every three characters.
        Parameters:
        str - the string to format
        Returns:
        the formatted path string
      • uuidToPath

        public static String uuidToPath​(String uuid)
      • concatPath

        public static String concatPath​(String... paths)
        连接路径
        Parameters:
        paths -
        Returns: