Class Uuid
- All Implemented Interfaces:
Serializable
Uuids are equal if
they have the same 128-bit value. Uuid instances can be created using the static
methods of the UuidFactory class.
The design of this class is intended to support the use of universally unique identifiers that
- have a high likelihood of uniqueness over space and time and
- are computationally difficult to guess.
Uuid as a
capability. Note that not all defined Uuid values imply a generation algorithm that
supports this goal.
The most significant 64 bits of the value can be decomposed into unsigned integer fields according to the following bit masks:
0xFFFFFFFF00000000 time_low 0x00000000FFFF0000 time_mid 0x000000000000F000 version 0x0000000000000FFF time_hi
The least significant 64 bits of the value can be decomposed into unsigned integer fields according to the following bit masks:
0xC000000000000000 variant 0x3FFF000000000000 clock_seq 0x0000FFFFFFFFFFFF node
This specification defines the meaning (and implies aspects of the generation algorithm) of
Uuid values if the variant field is 0x2 and the version
field is either 0x1 or 0x4.
If the version field is 0x1, then
- the
time_low,time_mid, andtime_hifields are the least, middle, and most significant bits (respectively) of a 60-bit timestamp of 100-nanosecond intervals since midnight, October 15, 1582 UTC, - the
clock_seqfield is a 14-bit number chosen to help avoid duplicateUuidvalues in the event of a changed node address or a backward system clock adjustment (such as a random number when in doubt, or the previously used number incremented by one if just a backward clock adjustment is detected), and - the
nodefield is an IEEE 802 address (a 48-bit value).As an alternative to an IEEE 802 address (such as if one is not available to the generation algorithm), the
nodefield may also be a 48-bit number for which the most significant bit is set to1and the remaining bits were produced from a cryptographically strong random sequence.
If the version field is 0x4, then the time_low,
time_mid, time_hi, clock_seq, and node fields
are values that were produced from a cryptographically strong random sequence.
Only Uuid values with a version field of 0x4 are
considered computationally difficult to guess. A Uuid value with a
version field of 0x1 should not be treated as a capability.
A subclass of Uuid must not implement Externalizable; this restriction is
enforced by this class's constructor and readObject methods.
- Since:
- 2.0
- Author:
- Sun Microsystems, Inc.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionUuid(long bits0, long bits1) Creates a newUuidwith the specified 128-bit value. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanCompares the specified object with thisUuidfor equality.protected final voidfinalize()Delegates to the superclass'sfinalizemethod.final longReturns the least significant 64 bits of thisUuid's 128-bit value.final longReturns the most significant 64 bits of thisUuid's 128-bit value.final inthashCode()Returns the hash code value for thisUuid.protected final ObjectReturns this object.final StringtoString()Returns a string representation of thisUuid.final voidwrite(OutputStream out) Marshals a binary representation of thisUuidto anOutputStream.protected final ObjectReturns this object.
-
Constructor Details
-
Uuid
public Uuid(long bits0, long bits1) Creates a newUuidwith the specified 128-bit value.- Parameters:
bits0- the most significant 64 bits of the 128-bit valuebits1- the least significant 64 bits of the 128-bit value- Throws:
SecurityException- if the class of this object implementsExternalizable
-
-
Method Details
-
getMostSignificantBits
public final long getMostSignificantBits()Returns the most significant 64 bits of thisUuid's 128-bit value.- Returns:
- the most significant 64 bits of the 128-bit value
-
getLeastSignificantBits
public final long getLeastSignificantBits()Returns the least significant 64 bits of thisUuid's 128-bit value.- Returns:
- the least significant 64 bits of the 128-bit value
-
hashCode
public final int hashCode()Returns the hash code value for thisUuid. -
equals
Compares the specified object with thisUuidfor equality. This method returnstrueif and only if the specified object is aUuidinstance with the same 128-bit value as this one. -
toString
Returns a string representation of thisUuid.The string representation is 36 characters long, with five fields of zero-filled, lowercase hexadecimal numbers separated by hyphens. The fields of the string representation are derived from the components of the 128-bit value in the following order:
time_low(8 hexadecimal digits)time_mid(4 hexadecimal digits)versionandtime_hitreated as a single field (4 hexadecimal digits)variantandclock_seqtreated as a single field (4 hexadecimal digits)node(12 hexadecimal digits)
As an example, a
Uuidwith the 128-bit value0x0123456789ABCDEF0123456789ABCDEF
would have the following string representation:01234567-89ab-cdef-0123-456789abcdef
-
write
Marshals a binary representation of thisUuidto anOutputStream.Specifically, this method writes the 128-bit value to the stream as 16 bytes in network (big-endian) byte order.
- Parameters:
out- theOutputStreamto write thisUuidto- Throws:
IOException- if an I/O exception occurs while performing this operationNullPointerException- ifoutisnull
-
finalize
Delegates to the superclass'sfinalizemethod. This method prevents a subclass from declaring an overridingfinalizemethod. -
writeReplace
Returns this object. This method prevents a subclass from declaring awriteReplacemethod with an alternate implementation.- Returns:
- this object
-
readResolve
Returns this object. This method prevents a subclass from declaring areadResolvemethod with an alternate implementation.- Returns:
- this object
-