/** * Get or create a UUID for the given high and low order values. * * @param high the most significant bits * @param low the least significant bits * @return the UUID */ public static ValueUuid get(long high, long low) { return (ValueUuid) cache(new ValueUuid(high, low)); }
/** * Create a new UUID using the pseudo random number generator. * * @return the new UUID */ public static ValueUuid getNewRandom() { long high = MathUtils.secureRandomLong(); long low = MathUtils.secureRandomLong(); // version 4 (random) high = (high & (~0xf000L)) | 0x4000L; // variant (Leach-Salz) low = (low & 0x3fffffffffffffffL) | 0x8000000000000000L; return new ValueUuid(high, low); }
/** * Get or create a UUID for the given text representation. * * @param s the text representation of the UUID * @return the UUID */ public static ValueUuid get(String s) { long low = 0, high = 0; for (int i = 0, j = 0, length = s.length(); i < length; i++) { char c = s.charAt(i); if (c >= '0' && c <= '9') { low = (low << 4) | (c - '0'); } else if (c >= 'a' && c <= 'f') { low = (low << 4) | (c - 'a' + 0xa); } else if (c == '-') { continue; } else if (c >= 'A' && c <= 'F') { low = (low << 4) | (c - 'A' + 0xa); } else if (c <= ' ') { continue; } else { throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, s); } if (j++ == 15) { high = low; low = 0; } } return (ValueUuid) cache(new ValueUuid(high, low)); }
/** * Get or create a UUID for the given 16 bytes. * * @param binary the byte array (must be at least 16 bytes long) * @return the UUID */ public static ValueUuid get(byte[] binary) { if (binary.length < 16) { return get(StringUtils.convertBytesToHex(binary)); } long high = Utils.readLong(binary, 0); long low = Utils.readLong(binary, 8); return (ValueUuid) cache(new ValueUuid(high, low)); }