public final class UUID
extends Object implements Serializable, Comparable<UUID>
| java.lang.Object | |
| java.util.UUID | |
表示不可变的通用唯一标识符(UUID)的类。 一个UUID表示一个128位的值。
这些全局标识符存在不同的变体。 该类的方法用于操纵Leach-Salz变体,尽管构造函数允许创建UUID的任何变体(如下所述)。
变体2(Leach-Salz)UUID的布局如下:最重要的长包括以下无符号字段:
0xFFFFFFFF00000000 time_low 0x00000000FFFF0000 time_mid 0x000000000000F000 version 0x0000000000000FFF time_hiThe least significant long consists of the following unsigned fields:
0xC000000000000000 variant 0x3FFF000000000000 clock_seq 0x0000FFFFFFFFFFFF node
variant字段包含一个标识UUID布局的UUID 。 上述位布局仅适用于变量值为2的UUID ,这表示Leach-Salz变体。
版本字段包含一个描述此UUID类型的UUID 。 UUID有四种不同的基本类型:基于时间的,DCE安全性,基于名称的和随机生成的UUID。 这些类型的版本值分别为1,2,3和4。
有关包括用于创建 UUID的算法的更多信息,请参见 RFC 4122: A Universally Unique IDentifier (UUID) URN Namespace的第4.2节“用于创建基于时间的UUID的算法”。
Public constructors |
|
|---|---|
UUID(long mostSigBits, long leastSigBits) 使用指定的数据构造一个新的 |
|
公共方法(Public methods) |
|
|---|---|
int |
clockSequence() 与此UUID关联的时钟序列值。 |
int |
compareTo(UUID val) 将此UUID与指定的UUID进行比较。 |
boolean |
equals(Object obj) 将此对象与指定的对象进行比较。 |
static UUID |
fromString(String name) 创建 |
long |
getLeastSignificantBits() 返回此UUID的128位值的最低有效64位。 |
long |
getMostSignificantBits() 返回此UUID的128位值的最重要的64位。 |
int |
hashCode() 返回此 |
static UUID |
nameUUIDFromBytes(byte[] name) 静态工厂根据指定的字节数组检索类型3(基于名称) |
long |
node() 与此UUID关联的节点值。 |
static UUID |
randomUUID() 静态工厂检索类型4(伪随机生成的)UUID。 |
long |
timestamp() 与此UUID关联的时间戳记值。 |
String |
toString() 返回代表此 |
int |
variant() 与此 |
int |
version() 与此 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
java.lang.Comparable
|
|
UUID (long mostSigBits,
long leastSigBits)
使用指定的数据构造一个新的UUID 。 mostSigBits用于最显著64位UUID和leastSigBits成为的至少显著64位UUID 。
| 参数(Parameters) | |
|---|---|
mostSigBits |
long: The most significant bits of the UUID |
leastSigBits |
long: The least significant bits of the UUID |
int clockSequence ()
与此UUID关联的时钟序列值。
14位时钟序列值由该UUID的时钟序列字段构成。 时钟序列字段用于保证基于时间的UUID中的时间唯一性。
clockSequence值仅在基于时间的UUID中有意义,该UUID具有版本类型1.如果此UUID不是基于时间的UUID,则此方法会抛出UnsupportedOperationException。
| 返回(Returns) | |
|---|---|
int |
The clock sequence of this UUID |
| 抛出异常(Throws) | |
|---|---|
UnsupportedOperationException |
If this UUID is not a version 1 UUID |
int compareTo (UUID val)
将此UUID与指定的UUID进行比较。
如果第一个UUID中UUID不同的最重要字段更大,则两个UUID中的第一个大于第二个UUID。
| 参数(Parameters) | |
|---|---|
val |
UUID: UUID to which this UUID is to be compared |
| 返回(Returns) | |
|---|---|
int |
-1, 0 or 1 as this UUID is less than, equal to, or greater than val |
boolean equals (Object obj)
将此对象与指定的对象进行比较。 结果是true当且仅当参数不是null ,是一个UUID对象,具有相同的变量,并且包含相同的值,比特位,如此UUID 。
| 参数(Parameters) | |
|---|---|
obj |
Object: The object to be compared |
| 返回(Returns) | |
|---|---|
boolean |
true if the objects are the same; false otherwise |
UUID fromString (String name)
创建 UUID如在所描述的字符串标准表示 toString()方法。
| 参数(Parameters) | |
|---|---|
name |
String: A string that specifies a UUID |
| 返回(Returns) | |
|---|---|
UUID |
A UUID with the specified value |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
If name does not conform to the string representation as described in toString() |
long getLeastSignificantBits ()
返回此UUID的128位值的最低有效64位。
| 返回(Returns) | |
|---|---|
long |
The least significant 64 bits of this UUID's 128 bit value |
long getMostSignificantBits ()
返回此UUID的128位值的最重要的64位。
| 返回(Returns) | |
|---|---|
long |
The most significant 64 bits of this UUID's 128 bit value |
int hashCode ()
返回此 UUID的哈希码。
| 返回(Returns) | |
|---|---|
int |
A hash code value for this UUID |
UUID nameUUIDFromBytes (byte[] name)
静态工厂根据指定的字节数组检索类型3(基于名称) UUID 。
| 参数(Parameters) | |
|---|---|
name |
byte: A byte array to be used to construct a UUID |
| 返回(Returns) | |
|---|---|
UUID |
A UUID generated from the specified array |
long node ()
与此UUID关联的节点值。
48位节点值由该UUID的节点字段构成。 该字段旨在保存生成此UUID的机器的IEEE 802地址,以保证空间唯一性。
该节点值仅在基于时间的UUID中有意义,该UUID具有版本类型1.如果此UUID不是基于时间的UUID,则此方法将引发UnsupportedOperationException。
| 返回(Returns) | |
|---|---|
long |
The node value of this UUID |
| 抛出异常(Throws) | |
|---|---|
UnsupportedOperationException |
If this UUID is not a version 1 UUID |
UUID randomUUID ()
静态工厂检索类型4(伪随机生成的)UUID。 UUID是使用密码强的伪随机数发生器生成的。
| 返回(Returns) | |
|---|---|
UUID |
A randomly generated UUID |
long timestamp ()
与此UUID关联的时间戳记值。
60位时间戳值由此UUID的time_low,time_mid和time_hi字段UUID 。 由此产生的时间戳以UTC时间1582年10月15日午夜之后的100纳秒为单位进行测量。
timestamp值仅在基于时间的UUID中有意义,该UUID具有版本类型1.如果此 UUID不是基于时间的UUID,则此方法将引发UnsupportedOperationException。
| 返回(Returns) | |
|---|---|
long |
|
| 抛出异常(Throws) | |
|---|---|
UnsupportedOperationException |
If this UUID is not a version 1 UUID |
String toString ()
返回代表此 UUID的 String对象。
UUID字符串表示与此BNF所描述的一样:
UUID = <time_low> "-" <time_mid> "-" <time_high_and_version> "-" <variant_and_sequence> "-" <node> time_low = 4*<hexOctet> time_mid = 2*<hexOctet> time_high_and_version = 2*<hexOctet> variant_and_sequence = 2*<hexOctet> node = 6*<hexOctet> hexOctet = <hexDigit><hexDigit> hexDigit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "a" | "b" | "c" | "d" | "e" | "f" | "A" | "B" | "C" | "D" | "E" | "F"
| 返回(Returns) | |
|---|---|
String |
A string representation of this UUID |
int variant ()
与此UUID相关联的变体编号。 变体编号描述了UUID的布局。 变体号具有以下含义:
| 返回(Returns) | |
|---|---|
int |
The variant number of this UUID |
int version ()
与此UUID关联的版本号。 版本号描述了如何生成这个UUID 。 版本号具有以下含义:
| 返回(Returns) | |
|---|---|
int |
The version number of this UUID |