Package com.fizzed.crux.util
Class TimeUUID
- java.lang.Object
-
- com.fizzed.crux.util.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 Summary
Constructors Constructor Description TimeUUID(byte[] timeBytes)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(TimeUUID val)Compares this TimeUUID with the specified TimeUUID.booleanequals(java.lang.Object obj)static TimeUUIDfromString(java.lang.String uuid)static TimeUUIDfromUUID(java.util.UUID uuid)byte[]getBytes()longgetEpochMillis()inthashCode()java.lang.StringtoString()java.util.UUIDtoUUID()
-
-
-
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:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.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:
compareToin interfacejava.lang.Comparable<TimeUUID>- Parameters:
val-TimeUUIDto which thisTimeUUIDis to be compared- Returns:
- -1, 0 or 1 as this
TimeUUIDis less than, equal to, or greater thanval
-
-