|
@@ -3,8 +3,8 @@ package com.hcloud.microserver.commoncore.util;
|
|
|
import com.hcloud.microserver.commoncore.util.string.StrUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* @author JYJ
|
|
@@ -12,6 +12,57 @@ import java.util.List;
|
|
|
@Slf4j
|
|
|
public class TracedCodeUtils {
|
|
|
|
|
|
+ public static void main(String[] args) throws InterruptedException {
|
|
|
+ Map<String, Long> map = new HashMap<>();
|
|
|
+ long starttime = new Date().getTime();
|
|
|
+ System.err.println();
|
|
|
+ for (int i = 0; i < 10000000; i++) {
|
|
|
+ String commonRandomCode = generateShortUuid();
|
|
|
+ Long count = map.get(commonRandomCode);
|
|
|
+ if (null != count) {
|
|
|
+ count = count + 1L;
|
|
|
+ map.put(commonRandomCode, count);
|
|
|
+ } else {
|
|
|
+ map.put(commonRandomCode, 1L);
|
|
|
+ }
|
|
|
+ System.err.println(commonRandomCode);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String s : map.keySet()) {
|
|
|
+ Long count = map.get(s);
|
|
|
+ if (count > 1) {
|
|
|
+ System.err.println(s + "---" + count);
|
|
|
+ }else {
|
|
|
+ //System.err.println(s + "---" + count);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ long endtime = new Date().getTime();
|
|
|
+ long diff = endtime - starttime;
|
|
|
+ long time = diff / 1000;
|
|
|
+ System.err.println(time+":秒");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String[] chars = new String[]{"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"};
|
|
|
+
|
|
|
+
|
|
|
+ public static String generateShortUuid() {
|
|
|
+ StringBuffer shortBuffer = new StringBuffer();
|
|
|
+ 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);
|
|
|
+ shortBuffer.append(chars[x % 0x3E]);
|
|
|
+ }
|
|
|
+ return shortBuffer.toString();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private static final Integer[] ASCII_NUM = {65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
|
|
|
78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90};
|
|
|
private static final String[] ASCII_WORD = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
|
|
@@ -58,49 +109,27 @@ public class TracedCodeUtils {
|
|
|
|
|
|
/**
|
|
|
* 生成不重复的用户账号
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
- public static String getCommonRandomCode(){
|
|
|
+ public static String getCommonRandomCode() {
|
|
|
long nowDate = System.currentTimeMillis();
|
|
|
StringBuffer ssb = new StringBuffer();
|
|
|
- String sid = Integer.toHexString((int)nowDate);
|
|
|
+ String sid = Integer.toHexString((int) nowDate);
|
|
|
List<String> arrayList = Arrays.asList(sid.split(""));
|
|
|
- for(int i = 0; i < arrayList.size(); i++){
|
|
|
+ for (int i = 0; i < arrayList.size(); i++) {
|
|
|
String tmp = arrayList.get(i);
|
|
|
- if(!StrUtil.isNumeric(tmp)){
|
|
|
- for (int j = 0; j <ASCII_WORD.length ; j++) {
|
|
|
+ if (!StrUtil.isNumeric(tmp)) {
|
|
|
+ for (int j = 0; j < ASCII_WORD.length; j++) {
|
|
|
String inner = ASCII_WORD[j];
|
|
|
- if(tmp.equalsIgnoreCase(inner)){
|
|
|
- ssb.append(ASCII_NUM[j]/10);
|
|
|
+ if (tmp.equalsIgnoreCase(inner)) {
|
|
|
+ ssb.append(ASCII_NUM[j] / 10);
|
|
|
}
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
ssb.append(tmp);
|
|
|
}
|
|
|
}
|
|
|
return ssb.toString();
|
|
|
}
|
|
|
-
|
|
|
-// public static void main(String[] args) {
|
|
|
-// long nowDate = System.currentTimeMillis();
|
|
|
-// StringBuffer ssb = new StringBuffer();
|
|
|
-// String sid = Integer.toHexString((int)nowDate);
|
|
|
-// List<String> arrayList = Arrays.asList(sid.split(""));
|
|
|
-// for(int i = 0; i < arrayList.size(); i++){
|
|
|
-// String tmp = arrayList.get(i);
|
|
|
-// if(!StrUtil.isNumeric(tmp)){
|
|
|
-// for (int j = 0; j <ASCII_WORD.length ; j++) {
|
|
|
-// String inner = ASCII_WORD[j];
|
|
|
-// if(tmp.equalsIgnoreCase(inner)){
|
|
|
-// ssb.append(ASCII_NUM[j]/10);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }else{
|
|
|
-// ssb.append(tmp);
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
-// System.out.println(ssb.toString());
|
|
|
-//
|
|
|
-// }
|
|
|
}
|