| | |
| | | public class Func { |
| | | |
| | | /** |
| | | * 通常用于将主键oid转换成8位唯一hash码值 |
| | | * @return |
| | | */ |
| | | public static String oidEnHash(String oid){ |
| | | UUID originalUUID = UUID.fromString(oid); |
| | | // 使用Base64编码将原始UUID转换为较短的字符串 |
| | | String base64String = Base64.getUrlEncoder().withoutPadding().encodeToString(new byte[] { |
| | | (byte)(originalUUID.getMostSignificantBits()>>>56), |
| | | (byte)(originalUUID.getMostSignificantBits()>>>48), |
| | | (byte)(originalUUID.getMostSignificantBits()>>>40), |
| | | (byte)(originalUUID.getMostSignificantBits()>>>32), |
| | | (byte)(originalUUID.getMostSignificantBits()>>>24), |
| | | (byte)(originalUUID.getMostSignificantBits()>>>16), |
| | | (byte)(originalUUID.getMostSignificantBits()>>>8), |
| | | (byte)(originalUUID.getMostSignificantBits()), |
| | | (byte)(originalUUID.getLeastSignificantBits()>>>56), |
| | | (byte)(originalUUID.getLeastSignificantBits()>>>48), |
| | | (byte)(originalUUID.getLeastSignificantBits()>>>40), |
| | | (byte)(originalUUID.getLeastSignificantBits()>>>32), |
| | | (byte)(originalUUID.getLeastSignificantBits()>>>24), |
| | | (byte)(originalUUID.getLeastSignificantBits()>>>16), |
| | | (byte)(originalUUID.getLeastSignificantBits()>>>8), |
| | | (byte)(originalUUID.getLeastSignificantBits())}); |
| | | return base64String; |
| | | } |
| | | |
| | | /** |
| | | * 通常用于将主键oid转换成的8位唯一hash码,反转为oid |
| | | * @param base64String |
| | | * @return |
| | | */ |
| | | public static String oidDeHash(String base64String){ |
| | | // 反推回原始的UUID字符串 |
| | | byte[] bytes = Base64.getUrlDecoder().decode(base64String); |
| | | UUID reconstructedUUID = new UUID(((long)(bytes[0] & 0xff) << 56) |
| | | | ((long)(bytes[1] & 0xff) << 48) |
| | | | ((long)(bytes[2] & 0xff) << 40) |
| | | | ((long)(bytes[3] & 0xff) << 32) |
| | | | ((long)(bytes[4] & 0xff) << 24) |
| | | | ((long)(bytes[5] & 0xff) << 16) |
| | | | ((long)(bytes[6] & 0xff) << 8) |
| | | | (bytes[7] & 0xff), |
| | | ((long)(bytes[8] & 0xff) << 56) |
| | | | ((long)(bytes[9] & 0xff) << 48) |
| | | | ((long)(bytes[10] & 0xff) << 40) |
| | | | ((long)(bytes[11] & 0xff) << 32) |
| | | | ((long)(bytes[12] & 0xff) << 24) |
| | | | ((long)(bytes[13] & 0xff) << 16) |
| | | | ((long)(bytes[14] & 0xff) << 8) |
| | | | (bytes[15] & 0xff)); |
| | | return reconstructedUUID.toString().toUpperCase(Locale.ROOT); |
| | | } |
| | | |
| | | /** |
| | | * 断言,必须不能为 null |
| | | * <blockquote><pre> |
| | | * public Foo(Bar bar) { |