Class TimeUUID

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<TimeUUID>

    public class TimeUUID
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Comparable<TimeUUID>
    A time-based UUID that is internally stored in a sortable/lexicographical byte ordering. It's outside appearance (e.g. toString()) is identical as java.util.UUID, but you can access its underlying byte array, and its natural ordering will be time ascending. Very useful for storing in databases as binary and then have it ordered as time ascending if in an indexed column.
    Author:
    jjlauer
    See Also:
    Serialized Form
    • Constructor Detail

      • TimeUUID

        public TimeUUID​(byte[] timeBytes)
    • Method Detail

      • getBytes

        public byte[] getBytes()
      • getEpochMillis

        public long getEpochMillis()
      • toUUID

        public java.util.UUID toUUID()
      • fromUUID

        public static TimeUUID fromUUID​(java.util.UUID uuid)
      • fromString

        public static TimeUUID fromString​(java.lang.String uuid)
      • toString

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

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

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

        public int compareTo​(TimeUUID val)
        Compares this TimeUUID with the specified TimeUUID. Since a TimeUUID is already arranged in a sortable byte-order, this method simply compares timeBytes left to right.
        Specified by:
        compareTo in interface java.lang.Comparable<TimeUUID>
        Parameters:
        val - TimeUUID to which this TimeUUID is to be compared
        Returns:
        -1, 0 or 1 as this TimeUUID is less than, equal to, or greater than val