Class UuidUtil


  • public final class UuidUtil
    extends Object
    Utility for checking UUID version, extracting UUID details, etc.
    • Method Detail

      • copy

        public static UUID copy​(UUID uuid)
        Get a copy of a UUID.

        It is just a convenience method for cloning UUIDs.

        Parameters:
        uuid - a UUID
        Returns:
        a copy of a UUID
      • isNil

        public static boolean isNil​(UUID uuid)
        Checks whether the UUID is equal to the Nil UUID.

        The Nil UUID is special UUID that has all 128 bits set to zero.

        Parameters:
        uuid - a UUID
        Returns:
        boolean true if it is an RFC4122 variant
        Throws:
        NullPointerException - if null
      • isMax

        public static boolean isMax​(UUID uuid)
        Checks whether the UUID is equal to the Max UUID.

        The Max UUID is special UUID that has all 128 bits set to one.

        Parameters:
        uuid - a UUID
        Returns:
        boolean true if it is an RFC4122 variant
        Throws:
        NullPointerException - if null
      • setVersion

        public static UUID setVersion​(UUID uuid,
                                      int version)
        Applies UUID version bits into the UUID
        Parameters:
        uuid - a UUID
        version - a version
        Returns:
        a UUID
      • isRfc4122

        public static boolean isRfc4122​(UUID uuid)
        Checks whether the UUID variant is the one defined by the RFC-4122.
        Parameters:
        uuid - a UUID
        Returns:
        boolean true if it is an RFC4122 variant
      • isReservedNcs

        public static boolean isReservedNcs​(UUID uuid)
        Checks whether the UUID variant is reserved NCS.
        Parameters:
        uuid - a UUID
        Returns:
        boolean true if it is an reserved NCS variant
      • isReservedMicrosoft

        public static boolean isReservedMicrosoft​(UUID uuid)
        Checks whether the UUID variant is reserved Microsoft.
        Parameters:
        uuid - a UUID
        Returns:
        boolean true if it is an reserved Microsoft variant
      • isReservedFuture

        public static boolean isReservedFuture​(UUID uuid)
        Checks whether the UUID variant is reserved future.
        Parameters:
        uuid - a UUID
        Returns:
        boolean true if it is an reserved future variant
      • isRandomBased

        public static boolean isRandomBased​(UUID uuid)
        Checks whether the UUID version 4.
        Parameters:
        uuid - a UUID
        Returns:
        boolean true if it is a random UUID
      • isNameBasedMd5

        public static boolean isNameBasedMd5​(UUID uuid)
        Checks whether the UUID version 3.
        Parameters:
        uuid - a UUID
        Returns:
        boolean true if it is a name-based UUID
      • isNameBasedSha1

        public static boolean isNameBasedSha1​(UUID uuid)
        Checks whether the UUID version 5.
        Parameters:
        uuid - a UUID
        Returns:
        boolean true if it is a name-based UUID
      • isTimeBased

        public static boolean isTimeBased​(UUID uuid)
        Checks whether the UUID version 1.
        Parameters:
        uuid - a UUID
        Returns:
        boolean true if it is a time-based UUID
      • isTimeOrdered

        public static boolean isTimeOrdered​(UUID uuid)
        Checks whether the UUID version 6.
        Parameters:
        uuid - a UUID
        Returns:
        boolean true if it is a time-ordered UUID
      • isTimeOrderedEpoch

        public static boolean isTimeOrderedEpoch​(UUID uuid)
        Checks whether the UUID version 7.
        Parameters:
        uuid - a UUID
        Returns:
        boolean true if it is a time-ordered with Unix Epoch UUID
      • isDceSecurity

        public static boolean isDceSecurity​(UUID uuid)
        Checks whether the UUID version 2.
        Parameters:
        uuid - a UUID
        Returns:
        boolean true if it is a DCE Security UUID
      • isCustom

        public static boolean isCustom​(UUID uuid)
        Checks whether the UUID version 8.
        Parameters:
        uuid - a UUID
        Returns:
        boolean true if it is a custom UUID
      • getInstant

        public static Instant getInstant​(UUID uuid)
        Returns the instant from a time-based, time-ordered or DCE Security UUID.
        Parameters:
        uuid - a UUID
        Returns:
        Instant
        Throws:
        IllegalArgumentException - if the input is not a time-based, time-ordered or DCE Security UUID.
      • getTimestamp

        public static long getTimestamp​(UUID uuid)
        Returns the time stamp from a time-based, time-ordered or DCE Security UUID.

        The value returned by this method is the number of 100-nanos since 1582-10-15 (Gregorian epoch).

        Parameters:
        uuid - a UUID
        Returns:
        long the timestamp
        Throws:
        IllegalArgumentException - if the input is not a time-based, time-ordered or DCE Security UUID.
      • getNodeIdentifier

        public static long getNodeIdentifier​(UUID uuid)
        Get the node identifier from a time-based, time-ordered or DCE Security UUID.
        Parameters:
        uuid - a UUID
        Returns:
        long the node identifier
        Throws:
        IllegalArgumentException - if the input is not a time-based, time-ordered or DCE Security UUID.
      • getClockSequence

        public static int getClockSequence​(UUID uuid)
        Get the clock sequence from a time-based, time-ordered or DCE Security UUID.
        Parameters:
        uuid - a UUID
        Returns:
        int the clock sequence
        Throws:
        IllegalArgumentException - if the input is not a time-based, time-ordered or DCE Security UUID.
      • getLocalDomain

        public static byte getLocalDomain​(UUID uuid)
        Get the local domain number from a DCE Security UUID.
        Parameters:
        uuid - a UUID
        Returns:
        the local domain
        Throws:
        IllegalArgumentException - if the input is not a DCE Security UUID.
      • getLocalIdentifier

        public static int getLocalIdentifier​(UUID uuid)
        Get the local identifier number from a DCE Security UUID.
        Parameters:
        uuid - a UUID
        Returns:
        the local identifier
        Throws:
        IllegalArgumentException - if the input is not a DCE Security UUID.