Class UuidUtil


  • public final class UuidUtil
    extends Object
    Utility that provides methods for checking UUID version, for extracting information from UUIDs, and etc.
    • Method Detail

      • applyVersion

        public static UUID applyVersion​(UUID uuid,
                                        int version)
        Applies UUID version bits into the UUID
        Parameters:
        uuid - a UUID
        version - a version
        Returns:
        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
      • 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
      • 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
      • extractNodeIdentifier

        public static long extractNodeIdentifier​(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:
        IllegalUuidException - if the input is not a time-based, time-ordered or DCE Security UUID.
      • extractClockSequence

        public static int extractClockSequence​(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:
        IllegalUuidException - if the input is not a time-based, time-ordered or DCE Security UUID.
      • extractInstant

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

        public static long extractUnixMilliseconds​(UUID uuid)
        Get the Unix epoch milliseconds from a time-based, time-ordered or DCE Security UUID. The value returned by this method is the number of milliseconds since 1970-01-01 (Unix epoch).
        Parameters:
        uuid - a UUID
        Returns:
        Unix milliseconds
        Throws:
        IllegalUuidException - if the input is not a time-based, time-ordered or DCE Security UUID.
      • extractTimestamp

        public static long extractTimestamp​(UUID uuid)
        Get the timestamp 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:
        IllegalUuidException - if the input is not a time-based, time-ordered or DCE Security UUID.
      • extractLocalDomain

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

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

        protected static char[] removeHyphens​(char[] input)