@Immutable public final class UUID extends Object implements Serializable, Comparable<UUID>
This class implements version 4 (pseudo-randomly generated) of the RFC 4122 variant of the UUID namespace.
Some debugging use cases benefit from being able to identify the machine from which a UUID has been generated. To allow for this, a system property ("rvpf.uuid.mac") allows the use of the MAC address of a specified or default interface to be used as the node value in each generated UUID, like it would be for a version 1 (time-based) UUID.
UUID values are frequently used as primary keys in databases. A special bit manipulation allows the key value to be identified as deleted: the variant field is modified to make the UUID use the NCS compatibility value which is not accepted as valid for original keys where deleted entries may be present.
| Modifier and Type | Field and Description |
|---|---|
static int |
BYTES_LENGTH
Length of a byte array containing a UUID.
|
static String |
MAC_ADDRESS_PROPERTY
Include MAC address property (may specify interface).
|
static int |
NAME_LENGTH
Name length.
|
static UUID |
NULL
Null UUID.
|
static int |
RAW_STRING_LENGTH
Length of a String containing a raw UUID.
|
static int |
STRING_LENGTH
Length of a String containing a decorated UUID.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(UUID other)
Implements Comparable.
|
UUID |
deleted()
Returns this or a clone of this with the 'deleted' indicator set.
|
boolean |
equals(Object other) |
static UUID |
fromBytes(byte[] bytes)
Returns a new UUID from a byte array.
|
static Optional<UUID> |
fromDataInput(DataInput source)
Reads in an external representation of a UUID.
|
static UUID |
fromLongs(long high,
long low)
Returns a new UUID from two longs.
|
static UUID |
fromName(String name)
Returns a new UUID from a name generated by
toName(). |
static Optional<UUID> |
fromString(String string)
Returns a new UUID from a string.
|
static UUID |
generate()
Generates a UUID.
|
static UUID |
generate(Optional<byte[]> seed)
Generates a version 4 UUID (IETF RFC 4122).
|
static UUID |
generate(String seed)
Generates a UUID.
|
long |
getHigh()
Gets back the high value from a synthesized UUID.
|
long |
getLeastSignificantBits()
Gets the least significant bits.
|
long |
getLow()
Gets back the low value from a synthesized UUID.
|
int |
getMidHigh()
Gets back the mid high value from a synthesized UUID.
|
int |
getMidLow()
Gets back the mid low value from a synthesized UUID.
|
long |
getMostSignificantBits()
Gets the most significant bits.
|
static Optional<byte[]> |
getNode()
Gets the node part.
|
int |
hashCode() |
boolean |
isDeleted()
Asks if this represents a deleted entry.
|
boolean |
isRandomNode()
Asks if this contains a random node.
|
static boolean |
isUUID(String key)
Asks if a key string can represent a UUID.
|
static Optional<UUID> |
readExternal(ObjectInput source)
Reads in an external representation of a UUID.
|
static UUID |
synthesize(long high,
int midHigh,
int midLow,
long low)
Synthesizes a UUID from four numbers.
|
byte[] |
toBytes()
Returns a binary representation of itself.
|
void |
toDataOutput(DataOutput destination)
Sends to a data output.
|
String |
toName()
Returns a name representation of itself.
|
String |
toRawString()
Returns an undecorated string representation of itself.
|
String |
toString()
Returns a decorated string representation of itself.
|
String |
toURN()
Returns a URN reference to this.
|
UUID |
undeleted()
Returns this or a clone of this with the 'deleted' indicator cleared.
|
static void |
writeExternal(Optional<UUID> uuid,
ObjectOutput destination)
Writes out an external representation of a UUID.
|
public static final int BYTES_LENGTH
public static final String MAC_ADDRESS_PROPERTY
public static final int NAME_LENGTH
public static final UUID NULL
public static final int RAW_STRING_LENGTH
public static final int STRING_LENGTH
@Nonnull @CheckReturnValue public static UUID fromBytes(@Nonnull byte[] bytes)
bytes - Binary value for the UUID in 16 bytes.@Nonnull @CheckReturnValue public static Optional<UUID> fromDataInput(@Nonnull DataInput source) throws IOException
source - The source.IOException - When an I/O error occurs.@Nonnull @CheckReturnValue public static UUID fromLongs(long high, long low)
This convenience method is used to convert from a
UUID.
high - The most significant bits.low - The least significant bits.@Nonnull @CheckReturnValue public static UUID fromName(@Nonnull String name)
toName().name - The previously generated name.@Nonnull @CheckReturnValue public static Optional<UUID> fromString(@Nonnull String string)
string - A string of 32 hexadecimal digits for the UUID. It may
include '-' decorators. When empty, an empty value is
returned.@Nonnull @CheckReturnValue public static UUID generate()
@Nonnull @CheckReturnValue public static UUID generate(@Nonnull Optional<byte[]> seed)
seed - A value prefix (may be null).@Nonnull @CheckReturnValue public static UUID generate(@Nonnull String seed)
seed - A value prefix (may be empty).@Nonnull @CheckReturnValue public static Optional<byte[]> getNode()
@CheckReturnValue
public static boolean isUUID(@Nonnull
String key)
key - The candidate key string.@Nonnull @CheckReturnValue public static Optional<UUID> readExternal(@Nonnull ObjectInput source) throws IOException
This is a helper method for
Externalizable objects containing a
UUID.
source - The source.IOException - When an I/O error occurs.@Nonnull @CheckReturnValue public static UUID synthesize(long high, int midHigh, int midLow, long low)
high - A 48 bits number.midHigh - A 8 bits number.midLow - A 8 bits number.low - A 40 bits number.public static void writeExternal(@Nonnull
Optional<UUID> uuid,
@Nonnull
ObjectOutput destination)
throws IOException
This is a helper method for
Externalizable objects containing a
UUID.
uuid - The UUID (may be empty).destination - The destination.IOException - When an I/O error occurs.public int compareTo(UUID other)
compareTo in interface Comparable<UUID>other - An other PointEntity.@Nonnull @CheckReturnValue public UUID deleted()
If the 'deleted' indicator is already set, returns this.
public boolean equals(Object other)
equals in class Object@CheckReturnValue public long getHigh()
@CheckReturnValue public long getLeastSignificantBits()
This convenience method is used to help convert to
UUID.
@CheckReturnValue public long getLow()
@CheckReturnValue public int getMidHigh()
@CheckReturnValue public int getMidLow()
@CheckReturnValue public long getMostSignificantBits()
This convenience method is used to help convert to
UUID.
public int hashCode()
hashCode in class Object@CheckReturnValue public boolean isDeleted()
@CheckReturnValue public boolean isRandomNode()
Note: some UUID generators do not interpret correctly the position of the multicast bit in RFC 4122.
@Nonnull @CheckReturnValue public byte[] toBytes()
public void toDataOutput(@Nonnull
DataOutput destination)
throws IOException
destination - The destination.IOException - On I/O exception.@Nonnull @CheckReturnValue public String toName()
@Nonnull @CheckReturnValue public String toRawString()
public String toString()
toString in class Object@Nonnull @CheckReturnValue public String toURN()
@Nonnull @CheckReturnValue public UUID undeleted()
If the 'deleted' indicator is already clear, returns this.
Copyright © 2003-2019 Serge Brisson. All Rights Reserved.