package com.jarvis.base.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
/**
* A class that represents an immutable universally unique identifier (UUID).
* A UUID represents a 128-bit value.
* <p/>
* <p>There exist different variants of these global identifiers. The methods
* of this class are for manipulating the Leach-Salz variant, although the
* constructors allow the creation of any variant of UUID (described below).
* <p/>
* <p>The layout of a variant 2 (Leach-Salz) UUID is as follows:
* <p/>
* The most significant long consists of the following unsigned fields:
* <pre>
* 0xFFFFFFFF00000000 time_low
* 0x00000000FFFF0000 time_mid
* 0x000000000000F000 version
* 0x0000000000000FFF time_hi
* </pre>
* The least significant long consists of the following unsigned fields:
* <pre>
* 0xC000000000000000 variant
* 0x3FFF000000000000 clock_seq
* 0x0000FFFFFFFFFFFF node
* </pre>
* <p/>
* <p>The variant field contains a value which identifies the layout of
* the <tt>UUID</tt>. The bit layout described above is valid only for
* a <tt>UUID</tt> with a variant value of 2, which indicates the
* Leach-Salz variant.
* <p/>
* <p>The version field holds a value that describes the type of this
* <tt>UUID</tt>. There are four different basic types of UUIDs: time-based,
* DCE security, name-based, and randomly generated UUIDs. These types
* have a version value of 1, 2, 3 and 4, respectively.
* <p/>
* <p>For more information including algorithms used to create <tt>UUID</tt>s,
* see the Internet-Draft <a href="http://www.ietf.org/internet-drafts/draft-mealling-uuid-urn-03.txt">UUIDs and GUIDs</a>
* or the standards body definition at
* <a href="http://www.iso.ch/cate/d2229.html">ISO/IEC 11578:1996</a>.
*
* @version 1.14, 07/12/04
* @since 1.5
*/
@Deprecated
public final class UUID implements java.io.Serializable
{
/**
* Explicit serialVersionUID for interoperability.
*/
private static final long serialVersionUID = -4856846361193249489L;
/*
* The most significant 64 bits of this UUID.
*
* @serial
*/
private final long mostSigBits;
/**
* The least significant 64 bits of this UUID.
*
* @serial
*/
private final long leastSigBits;
/*
* The version number associated with this UUID. Computed on demand.
*/
private transient int version = -1;
/*
* The variant number associated with this UUID. Computed on demand.
*/
private transient int variant = -1;
/*
* The timestamp associated with this UUID. Computed on demand.
*/
private transient volatile long timestamp = -1;
/*
* The clock sequence associated with this UUID. Computed on demand.
*/
private transient int sequence = -1;
/*
* The node number associated with this UUID. Computed on demand.
*/
private transient long node = -1;
/*
* The hashcode of this UUID. Computed on demand.
*/
private transient int hashCode = -1;
/*
* The random number generator used by this class to create random
* based UUIDs.
*/
private static volatile SecureRandom numberGenerator = null;
// Constructors and Factories
/*
* Private constructor which uses a byte array to construct the new UUID.
*/
private UUID(byte[] data)
{
long msb = 0;
long lsb = 0;
for (int i = 0; i < 8; i++)
msb = (msb << 8) | (data[i] & 0xff);
for (int i = 8; i < 16; i++)
lsb = (lsb << 8) | (data[i] & 0xff);
this.mostSigBits = msb;
this.leastSigBits = lsb;
}
/**
* Constructs a new <tt>UUID</tt> using the specified data.
* <tt>mostSigBits</tt> is used for the most significant 64 bits
* of the <tt>UUID</tt> and <tt>leastSigBits</tt> becomes the
* least significant 64 bits of the <tt>UUID</tt>.
*
* @param mostSigBits
* @param leastSigBits
*/
public UUID(long mostSigBits, long leastSigBits)
{
this
Java常用工具类---UUID工具类、Map工具类
最新推荐文章于 2025-06-16 10:48:39 发布