public final class UuidComparator extends Object implements Comparator<UUID>
The default static method compares two time-based UUIDs by comparing the time stamps first and then comparing the least significant bits as unsigned 64-bit integers. If both UUIDs are not time-based then it compares them as unsigned 128-bit integers.
The opaque static method compares two UUIDs as unsigned 128-bit integers. It's the same as lexicographic sorting of UUID canonical strings.
| 构造器和说明 |
|---|
UuidComparator()
Creates a default implementation of
UuidComparator. |
| 限定符和类型 | 方法和说明 |
|---|---|
int |
compare(UUID uuid1,
UUID uuid2)
Compares two UUIDs.
|
static int |
defaultCompare(UUID uuid1,
UUID uuid2)
Compares two UUIDs.
|
static UuidComparator |
getDefaultInstance()
Returns a default implementation of
UuidComparator. |
static UuidComparator |
getOpaqueInstance()
Returns an opaque implementation of
UuidComparator. |
static int |
opaqueCompare(UUID uuid1,
UUID uuid2)
Compares two UUIDs.
|
public UuidComparator()
UuidComparator.public static UuidComparator getDefaultInstance()
UuidComparator.UuidComparatordefaultCompare(UUID, UUID)public static UuidComparator getOpaqueInstance()
UuidComparator.UuidComparatoropaqueCompare(UUID, UUID)public static int defaultCompare(UUID uuid1, UUID uuid2)
The default static method compares two time-based UUIDs by comparing the time stamps first and then comparing the least significant bits as unsigned 64-bit integers. If both UUIDs are not time-based then it compares them as unsigned 128-bit integers.
The first of two UUIDs is greater than the second if the time stamp is greater for the first UUID. If the time stamps are equal, the first of two UUIDs is greater than the second if the most significant byte in which they differ is greater for the first UUID.
It can be useful for these reasons:
UUID.compareTo(UUID) doesn't work well for time-based UUIDs;
UUID.compareTo(UUID) can lead to unexpected behavior due to
signed long comparison;
UUID.compareTo(UUID) throws NullPointerException if a
null UUID is given.
uuid1 - a UUIDuuid2 - another UUIDu1 is less than, equal to, or greater than
u2public static int opaqueCompare(UUID uuid1, UUID uuid2)
The opaque static method compares two UUIDs as unsigned 128-bit integers. It's the same as lexicographic sorting of UUID canonical strings.
The first of two UUIDs is greater than the second if the most significant byte in which they differ is greater for the first UUID.
The opaque method is faster than the default method as it does not check the UUID version.
It's referred to as "opaque" just because it works like a "blind byte-to-byte comparison".
It can be useful for these reasons:
UUID.compareTo(UUID) can lead to unexpected behavior due to
signed long comparison;
UUID.compareTo(UUID) throws NullPointerException if a
null UUID is given.
uuid1 - a UUIDuuid2 - another UUIDu1 is less than, equal to, or greater than
u2public int compare(UUID uuid1, UUID uuid2)
compare 在接口中 Comparator<UUID>uuid1 - a UUIDuuid2 - another UUIDu1 is less than, equal to, or greater than
u2defaultCompare(UUID, UUID)Copyright © 2024. All rights reserved.