Class TimeUuid

  • All Implemented Interfaces:
    Comparable<TimeUuid>

    public class TimeUuid
    extends Object
    implements Comparable<TimeUuid>
    A UUID implementation. It supports creating version 7 UUIDs, which are time-ordered. See also draft-ietf-uuidrev-rfc4122bis-00 Unlike java.util.UUID, the comparison is unsigned, so that the string comparison yields the same result.
    • Constructor Detail

      • TimeUuid

        public TimeUuid​(long msb,
                        long lsb)
    • Method Detail

      • toShortString

        public String toShortString()
      • toHumanReadableString

        public String toHumanReadableString()
      • getTimestampPart

        public long getTimestampPart()
        Get the timestamp part (48 bits).
        Returns:
        the timestamp part
      • getCounterPart

        public long getCounterPart()
        Get the counter part (12 bits).
        Returns:
        counter part
      • getRandomPart

        public long getRandomPart()
        Get the random part (62 bits). The first 2 bits are fixed.
        Returns:
        the random part
      • compareTo

        public int compareTo​(TimeUuid o)
        Unlike java.util.UUID, the comparison is unsigned, so that the string comparison yields the same result.
        Specified by:
        compareTo in interface Comparable<TimeUuid>
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getMillisAndCountIncreasing

        public static long getMillisAndCountIncreasing​(long now,
                                                       AtomicLong lastMillisAndCount)
        Get the next timestamp (in milliseconds) and counter. The lowest 12 bits of the returned value is the counter. The milliseconds are shifted by 12 bits.
        Parameters:
        now - the milliseconds
        lastMillisAndCount - the last returned value
        Returns:
        the new value
      • newUuid

        public static TimeUuid newUuid()
      • getMostSignificantBits

        public long getMostSignificantBits()
      • getLeastSignificantBits

        public long getLeastSignificantBits()