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 longleastSigBitsprotected longmostSigBitsprotected static intSIZE
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Address other)Compares this UUID with the specified UUID.intcompareTo(UUID val)UUIDcopy()java.util.function.Supplier<? extends UUID>create()Creates an instance of the class implementing this interfaceprotected static java.lang.Stringdigits(long val, int digits)Returns val represented by the specified number of hex digits.booleanequals(java.lang.Object obj)Compares this object to the specified object.static UUIDfromString(java.lang.String name)Creates aUUIDfrom the string standard representation as described in thetoString()method.static byte[]generateRandomBytes()Generate random bytes and adjusts them for a type-4 UUIDlonggetLeastSignificantBits()longgetMostSignificantBits()Returns the most significant 64 bits of this UUID's 128 bit value.inthashCode()Returns a hash code for thisUUID.static java.lang.StringprintName(UUID uuid)static UUIDrandomUUID()Static factory to retrieve a type 4 (pseudo randomly generated) UUID.voidreadFrom(java.io.DataInput in)Read the state of the current object (including superclasses) from instream Note that the input stream must not be closedintserializedSize()Returns the size (in bytes) of the marshalled objectjava.lang.StringtoString()java.lang.StringtoStringLong()Returns aStringobject representing thisUUID.voidwriteTo(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
-
-
Constructor Detail
-
UUID
public UUID()
-
UUID
public UUID(long mostSigBits, long leastSigBits)
-
UUID
public UUID(UUID uuid)
-
UUID
protected UUID(byte[] data)
Private constructor which uses a byte array to construct the new UUID
-
-
Method Detail
-
create
public java.util.function.Supplier<? extends UUID> create()
Description copied from interface:ConstructableCreates an instance of the class implementing this interface- Specified by:
createin interfaceConstructable<UUID>
-
randomUUID
public static UUID randomUUID()
Static factory to retrieve a type 4 (pseudo randomly generated) UUID. TheUUIDis 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:
toStringin classjava.lang.Object
-
toStringLong
public java.lang.String toStringLong()
Returns aStringobject 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 aUUIDfrom the string standard representation as described in thetoString()method.- Parameters:
name- A string that specifies aUUID- Returns:
- A
UUIDwith 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:
hashCodein 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 istrueif and only if the argument is notnull, is aUUIDobject, and contains the same most- and least significant bits.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- The object to be compared- Returns:
trueif the objects are the same;falseotherwise
-
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:
compareToin interfacejava.lang.Comparable<Address>- Parameters:
other-UUIDto which thisUUIDis to be compared- Returns:
- -1, 0 or 1 as this
UUIDis less than, equal to, or greater thanval
-
compareTo
public int compareTo(UUID val)
-
writeTo
public void writeTo(java.io.DataOutput out) throws java.io.IOExceptionDescription copied from interface:StreamableWrite the entire state of the current object (including superclasses) to outstream. Note that the output stream must not be closed- Specified by:
writeToin interfaceStreamable- Throws:
java.io.IOException
-
readFrom
public void readFrom(java.io.DataInput in) throws java.io.IOExceptionDescription copied from interface:StreamableRead the state of the current object (including superclasses) from instream Note that the input stream must not be closed- Specified by:
readFromin interfaceStreamable- Throws:
java.io.IOException
-
serializedSize
public int serializedSize()
Description copied from interface:SizeStreamableReturns the size (in bytes) of the marshalled object- Specified by:
serializedSizein interfaceSizeStreamable
-
copy
public UUID copy()
-
generateRandomBytes
public static byte[] generateRandomBytes()
Generate random bytes and adjusts them for a type-4 UUID
-
-