Package org.jgroups.util
Class UUID
- java.lang.Object
-
- org.jgroups.util.UUID
-
- All Implemented Interfaces:
java.lang.Comparable<Address>
,Address
,Constructable<UUID>
,SizeStreamable
,Streamable
- Direct Known Subclasses:
FlagsUUID
public class UUID extends java.lang.Object implements Address, Constructable<UUID>
Logical address which is unique over space and time.
Copied from java.util.UUID, but unneeded fields from the latter have been removed. UUIDs needs to have a small memory footprint.- Author:
- Bela Ban
-
-
Field Summary
Fields Modifier and Type Field Description protected long
leastSigBits
protected long
mostSigBits
protected static int
SIZE
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(Address other)
Compares this UUID with the specified UUID.UUID
copy()
java.util.function.Supplier<? extends UUID>
create()
Creates an instance of the class implementing this interfaceprotected static java.lang.String
digits(long val, int digits)
Returns val represented by the specified number of hex digits.boolean
equals(java.lang.Object obj)
Compares this object to the specified object.static UUID
fromString(java.lang.String name)
Creates aUUID
from the string standard representation as described in thetoString()
method.static byte[]
generateRandomBytes()
Generate random bytes and adjusts them for a type-4 UUIDlong
getLeastSignificantBits()
long
getMostSignificantBits()
Returns the most significant 64 bits of this UUID's 128 bit value.int
hashCode()
Returns a hash code for thisUUID
.static java.lang.String
printName(UUID uuid)
static UUID
randomUUID()
Static factory to retrieve a type 4 (pseudo randomly generated) UUID.void
readFrom(java.io.DataInput in)
Read the state of the current object (including superclasses) from instream Note that the input stream must not be closedint
serializedSize()
Returns the size (in bytes) of the marshalled objectjava.lang.String
toString()
java.lang.String
toStringLong()
Returns aString
object representing thisUUID
.void
writeTo(java.io.DataOutput out)
Write the entire state of the current object (including superclasses) to outstream.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jgroups.Address
isMulticast, isSiteAddress, isSiteMaster
-
-
-
-
Field Detail
-
mostSigBits
protected long mostSigBits
-
leastSigBits
protected long leastSigBits
-
SIZE
protected static final int SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
create
public java.util.function.Supplier<? extends UUID> create()
Description copied from interface:Constructable
Creates an instance of the class implementing this interface- Specified by:
create
in interfaceConstructable<UUID>
-
randomUUID
public static UUID randomUUID()
Static factory to retrieve a type 4 (pseudo randomly generated) UUID. TheUUID
is generated using aThreadLocalRandom
.- Returns:
- A randomly generated
UUID
-
getLeastSignificantBits
public long getLeastSignificantBits()
-
getMostSignificantBits
public long getMostSignificantBits()
Returns the most significant 64 bits of this UUID's 128 bit value.- Returns:
- The most significant 64 bits of this UUID's 128 bit value
-
printName
public static java.lang.String printName(UUID uuid)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toStringLong
public java.lang.String toStringLong()
Returns aString
object representing thisUUID
.The UUID string representation is as described by this 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:
- A string representation of this
UUID
-
fromString
public static UUID fromString(java.lang.String name)
Creates aUUID
from the string standard representation as described in thetoString()
method.- Parameters:
name
- A string that specifies aUUID
- Returns:
- A
UUID
with the specified value - Throws:
java.lang.IllegalArgumentException
- If name does not conform to the string representation as described intoString()
-
digits
protected static java.lang.String digits(long val, int digits)
Returns val represented by the specified number of hex digits.
-
hashCode
public int hashCode()
Returns a hash code for thisUUID
.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- A hash code value for this
UUID
-
equals
public boolean equals(java.lang.Object obj)
Compares this object to the specified object. The result istrue
if and only if the argument is notnull
, is aUUID
object, has the same variant, and contains the same value, bit for bit, as thisUUID
.- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- The object to be compared- Returns:
true
if the objects are the same;false
otherwise
-
compareTo
public int compareTo(Address other)
Compares this UUID with the specified UUID.The first of two UUIDs is greater than the second if the most significant field in which the UUIDs differ is greater for the first UUID.
- Specified by:
compareTo
in interfacejava.lang.Comparable<Address>
- Parameters:
other
-UUID
to which thisUUID
is to be compared- Returns:
- -1, 0 or 1 as this
UUID
is less than, equal to, or greater thanval
-
writeTo
public void writeTo(java.io.DataOutput out) throws java.io.IOException
Description copied from interface:Streamable
Write the entire state of the current object (including superclasses) to outstream. Note that the output stream must not be closed- Specified by:
writeTo
in interfaceStreamable
- Throws:
java.io.IOException
-
readFrom
public void readFrom(java.io.DataInput in) throws java.io.IOException
Description copied from interface:Streamable
Read the state of the current object (including superclasses) from instream Note that the input stream must not be closed- Specified by:
readFrom
in interfaceStreamable
- Throws:
java.io.IOException
-
serializedSize
public int serializedSize()
Description copied from interface:SizeStreamable
Returns the size (in bytes) of the marshalled object- Specified by:
serializedSize
in interfaceSizeStreamable
-
copy
public UUID copy()
-
generateRandomBytes
public static byte[] generateRandomBytes()
Generate random bytes and adjusts them for a type-4 UUID
-
-