nutz中有没有生成19位长度的uuid,比如这样的:loRLmcrgR4xUw6YtOQA
16 回复
package com.my.util;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
public class ShortUUID
{
static final char[] jdField_a_of_type_ArrayOfChar = { '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', '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' };
static final Map<Character, Integer> jdField_a_of_type_JavaUtilMap = new HashMap();
private static final int jdField_a_of_type_Int = jdField_a_of_type_ArrayOfChar.length;
public static void main(String[] paramArrayOfString)
{
long l = 0L;
HashSet localHashSet = new HashSet();
for (;;)
{
l += 1L;
System.out.println(l);
String str = generate();
if (localHashSet.contains(str))
{
System.out.println(": " + str);
break;
}
localHashSet.add(str);
}
}
private static String a(long paramLong, int paramInt)
{
if ((paramInt < 2) || (paramInt > jdField_a_of_type_Int)) {
paramInt = 10;
}
if (paramInt == 10) {
return Long.toString(paramLong);
}
int i = 64;
char[] arrayOfChar = new char[65];
int j = paramLong < 0L ? 1 : 0;
if (j == 0) {}
for (paramLong = -paramLong; paramLong <= -paramInt; paramLong /= paramInt) {
arrayOfChar[(i--)] = jdField_a_of_type_ArrayOfChar[((int)-(paramLong % paramInt))];
}
arrayOfChar[i] = jdField_a_of_type_ArrayOfChar[((int)-paramLong)];
if (j != 0) {
arrayOfChar[(--i)] = '-';
}
return new String(arrayOfChar, i, 65 - i);
}
private static String b(long paramLong, int paramInt)
{
long l = 1L << paramInt * 4;
return a(l | paramLong & l - 1L, jdField_a_of_type_Int).substring(1);
}
public static String generate()
{
UUID localUUID = UUID.randomUUID();
StringBuilder localStringBuilder = new StringBuilder();
localStringBuilder.append(b(localUUID.getMostSignificantBits() >> 32, 8));
localStringBuilder.append(b(localUUID.getMostSignificantBits() >> 16, 4));
localStringBuilder.append(b(localUUID.getMostSignificantBits(), 4));
localStringBuilder.append(b(localUUID.getLeastSignificantBits() >> 48, 4));
localStringBuilder.append(b(localUUID.getLeastSignificantBits(), 12));
return localStringBuilder.toString();
}
static
{
for (int i = 0; i < jdField_a_of_type_ArrayOfChar.length; i++) {
jdField_a_of_type_JavaUtilMap.put(Character.valueOf(jdField_a_of_type_ArrayOfChar[i]), Integer.valueOf(i));
}
}
}
@wendal 怎么在后台直接获得32位的UUID
@suyungit 你指的32位是长度还是进制。。。
@wendal 32位长度,感谢
添加回复
请先登陆