Package memeid

Class UUID

  • All Implemented Interfaces:
    java.lang.Comparable<UUID>
    Direct Known Subclasses:
    UUID.UnknownVersion, UUID.V1, UUID.V2, UUID.V3, UUID.V4, UUID.V5

    public class UUID
    extends java.lang.Object
    implements java.lang.Comparable<UUID>
    A class that represents an immutable universally unique identifier (UUID). A UUID represents a 128-bit value.
    See Also:
    RFC-4122
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  UUID.UnknownVersion
      Not standard-version UUIDs.
      static class  UUID.V1
      Version 1 UUIDs are those generated using a timestamp and the MAC address of the computer on which it was generated.
      static class  UUID.V2
      DCE Security version, with embedded POSIX UIDs.
      static class  UUID.V3
      Version 3 UUIDs are those generated by hashing a namespace identifier and name using MD5 as the hashing algorithm.
      static class  UUID.V4
      Version 4 UUIDs are those generated using random numbers.
      static class  UUID.V5
      Version 5 UUIDs are those generated by hashing a namespace identifier and name using SHA-1 as the hashing algorithm.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static byte[] nibbles  
      static UUID NIL
      The nil UUID is special form of UUID that is specified to have all 128 bits set to zero.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.UUID asJava()
      Returns this UUID as a UUID.
      java.util.Optional<UUID.V1> asV1()
      Returns this UUID as a UUID.V1 if versions match; otherwise, returns Optional.empty().
      java.util.Optional<UUID.V2> asV2()
      Returns this UUID as a UUID.V2 if versions match; otherwise, returns Optional.empty().
      java.util.Optional<UUID.V3> asV3()
      Returns this UUID as a UUID.V3 if versions match; otherwise, returns Optional.empty().
      java.util.Optional<UUID.V4> asV4()
      Returns this UUID as a UUID.V4 if versions match; otherwise, returns Optional.empty().
      java.util.Optional<UUID.V5> asV5()
      Returns this UUID as a UUID.V5 if versions match; otherwise, returns Optional.empty().
      int compareTo​(UUID o)  
      boolean equals​(java.lang.Object obj)  
      static UUID from​(long msb, long lsb)
      Creates a valid UUID from two long values representing the most/least significant bits.
      static UUID fromString​(java.lang.String name)
      Creates a UUID from the string standard representation as described in the toString() method.
      static UUID fromUUID​(java.util.UUID juuid)
      Creates a valid UUID from a UUID.
      long getLeastSignificantBits()
      Returns the most significant 64 bits of this UUID's 128 bit value.
      long getMostSignificantBits()
      Returns the most significant 64 bits of this UUID's 128 bit value.
      int hashCode()  
      boolean isNil()
      Returns true if this UUID is a NIL UUID; otherwise, returns false.
      boolean isV1()
      Returns true if this UUID is a UUID.V1; otherwise, returns false.
      boolean isV2()
      Returns true if this UUID is a UUID.V2; otherwise, returns false.
      boolean isV3()
      Returns true if this UUID is a UUID.V3; otherwise, returns false.
      boolean isV4()
      Returns true if this UUID is a UUID.V4; otherwise, returns false.
      boolean isV5()
      Returns true if this UUID is a UUID.V5; otherwise, returns false.
      java.lang.String toString()
      Returns a String object representing this UUID.
      int variant()
      The variant field determines the layout of the UUID.
      int version()
      The version number associated with this UUID.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • nibbles

        public static final byte[] nibbles
      • NIL

        public static final UUID NIL
        The nil UUID is special form of UUID that is specified to have all 128 bits set to zero.
        See Also:
        RFC-4122
    • Method Detail

      • from

        public static UUID from​(long msb,
                                long lsb)
        Creates a valid UUID from two long values representing the most/least significant bits.
        Parameters:
        msb - Most significant bit in long representation
        lsb - Least significant bit in long representation
        Returns:
        a new UUID constructed from msb and lsb
      • fromUUID

        public static UUID fromUUID​(java.util.UUID juuid)
        Creates a valid UUID from a UUID.
        Parameters:
        juuid - the UUID
        Returns:
        a valid UUID created from a UUID
      • fromString

        public static UUID fromString​(java.lang.String name)
        Creates a UUID from the string standard representation as described in the toString() method.
        Parameters:
        name - A string that specifies a UUID
        Returns:
        A UUID with the specified value
        Throws:
        java.lang.IllegalArgumentException - If name does not conform to the string representation as described in toString()
      • 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
      • getLeastSignificantBits

        public long getLeastSignificantBits()
        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
      • variant

        public int variant()
        The variant field determines the layout of the UUID.

        The variant field consists of a variable number of the most significant bits of octet 8 of the UUID.

        The variant number has the following meaning:

        • '''0''': Reserved for NCS backward compatibility
        • '''2''': RFC-4122
        • '''6''': Reserved, Microsoft Corporation backward compatibility
        • '''7''': Reserved for future definition

        Interoperability, in any form, with variants other than the one defined here is not guaranteed, and is not likely to be an issue in practice.

        Returns:
        The variant of this UUID
        See Also:
        RFC-4122
      • version

        public int version()
        The version number associated with this UUID. The version number describes how this UUID was generated.

        The version number has the following meaning:

        • '''1''': Time-based UUID
        • '''2''': DCE security UUID
        • '''3''': Name-based UUID
        • '''4''': Randomly generated UUID
        • '''5''': The name-based version that uses SHA-1 hashing
        Returns:
        The version number of this UUID
        See Also:
        RFC-4122
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • compareTo

        public int compareTo​(UUID o)
        Specified by:
        compareTo in interface java.lang.Comparable<UUID>
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Returns a String object representing this UUID.

        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"
         
         
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of this UUID
      • asJava

        public java.util.UUID asJava()
        Returns this UUID as a UUID.
        Returns:
        this UUID as a UUID
      • asV1

        public java.util.Optional<UUID.V1> asV1()
        Returns this UUID as a UUID.V1 if versions match; otherwise, returns Optional.empty().
        Returns:
        this UUID as a UUID.V1 if versions match; otherwise, returns Optional.empty().
      • asV2

        public java.util.Optional<UUID.V2> asV2()
        Returns this UUID as a UUID.V2 if versions match; otherwise, returns Optional.empty().
        Returns:
        this UUID as a UUID.V2 if versions match; otherwise, returns Optional.empty().
      • asV3

        public java.util.Optional<UUID.V3> asV3()
        Returns this UUID as a UUID.V3 if versions match; otherwise, returns Optional.empty().
        Returns:
        this UUID as a UUID.V3 if versions match; otherwise, returns Optional.empty().
      • asV4

        public java.util.Optional<UUID.V4> asV4()
        Returns this UUID as a UUID.V4 if versions match; otherwise, returns Optional.empty().
        Returns:
        this UUID as a UUID.V4 if versions match; otherwise, returns Optional.empty().
      • asV5

        public java.util.Optional<UUID.V5> asV5()
        Returns this UUID as a UUID.V5 if versions match; otherwise, returns Optional.empty().
        Returns:
        this UUID as a UUID.V5 if versions match; otherwise, returns Optional.empty().
      • isNil

        public boolean isNil()
        Returns true if this UUID is a NIL UUID; otherwise, returns false.
        Returns:
        true if this UUID is a NIL UUID; false otherwise
      • isV1

        public boolean isV1()
        Returns true if this UUID is a UUID.V1; otherwise, returns false.
        Returns:
        true if this UUID is a UUID.V1; false otherwise
      • isV2

        public boolean isV2()
        Returns true if this UUID is a UUID.V2; otherwise, returns false.
        Returns:
        true if this UUID is a UUID.V2; false otherwise
      • isV3

        public boolean isV3()
        Returns true if this UUID is a UUID.V3; otherwise, returns false.
        Returns:
        true if this UUID is a UUID.V3; false otherwise
      • isV4

        public boolean isV4()
        Returns true if this UUID is a UUID.V4; otherwise, returns false.
        Returns:
        true if this UUID is a UUID.V4; false otherwise
      • isV5

        public boolean isV5()
        Returns true if this UUID is a UUID.V5; otherwise, returns false.
        Returns:
        true if this UUID is a UUID.V5; false otherwise