zoukankan      html  css  js  c++  java
  • 在维护项目中的UUID工具类

    import java.util.UUID;
    
    
    /**
     * <p>
     * Title:uuID生成器
     * </p>
     * <p>
     * Description:UUID 标示符生成策略
     * </p>
     *
     * @author YangJiwei
     */
    public final class UUIDGenerator {
        private static String[] chars = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
    
        private UUIDGenerator() {
    
        }
    
        /**
         * 得到一个没有'-'字符的UUID。 标准UUID:b8154343-9b22-4a05-a7c1-01ac9e6eaf3e 本方法返回值
         * :b81543439b224a05a7c101ac9e6eaf3e
         *
         * @return String
         */
        public static String getUUID() {
            String s = UUID.randomUUID().toString();
    
            return s.substring(0, 8) + s.substring(9, 13) + s.substring(14, 18) + s.substring(19, 23) + s.substring(24);
        }
    
        /**
         * 得到number个uuid组成的数组
         *
         * @param number number
         * @return String[]
         */
        public static String[] getUUID(int number) {
            if (number < 1) {
                return null;
            }
            String[] ss = new String[number];
            for (int i = 0; i < number; i++) {
                ss[i] = getUUID();
            }
            return ss;
        }
    
        /**
         * 构造8位uuid
         *
         * @return
         * @since 1.0
         */
        public static String gen8UUID() {
            StringBuilder builder = new StringBuilder();
            String uuid = UUID.randomUUID().toString().replace("-", "");
            for (int i = 0; i < 8; i++) {
                String str = uuid.substring(i * 4, i * 4 + 4);
                int x = Integer.parseInt(str, 16);
                builder.append(chars[(x % 62)]);
            }
            return builder.toString();
        }
    }
  • 相关阅读:
    [测试题]钦点
    香港记者
    【模板】三维偏序
    C. Journey
    B. Game of the Rows
    A. Arya and Bran
    D. Statistics of Recompressing Videos
    人们对Python在企业级开发中的10大误解
    各种开源协议介绍 BSD、Apache Licence、GPL V2 、GPL V3 、LGPL、MIT
    WPF.UIShell UIFramework之自定义窗口的深度技术
  • 原文地址:https://www.cnblogs.com/wjup/p/11041285.html
Copyright © 2011-2022 走看看