Module buralotech.identifier.core
Class UUIDVersion7Delegate
java.lang.Object
com.buralotech.oss.identifier.uuid.UUIDVersion7Delegate
- All Implemented Interfaces:
UUIDVersionDelegate
Encapsulates the logic that is specific to the standard type 7 UUID format.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]fromTicks(long ticks, long suffix) Create a UUID as a byte array from a timestamp.byte[]generate()Generate an identifier using an underlying UUID generator.booleanisValidBinary(byte[] binary) Check that the binary representation is valid.booleanisValidText(String text) Check that the text representation is valid.toInstant(byte[] binary) Extract the timestamp from the UUID.
-
Field Details
-
PATTERN
The regular expression pattern used to validate identifiers. -
generator
private final com.fasterxml.uuid.NoArgGenerator generatorUsed to generate time based UUIDs.
-
-
Constructor Details
-
UUIDVersion7Delegate
public UUIDVersion7Delegate()
-
-
Method Details
-
generate
public byte[] generate()Generate an identifier using an underlying UUID generator.- Specified by:
generatein interfaceUUIDVersionDelegate- Returns:
- The generated identifier as a byte array.
-
isValidBinary
public boolean isValidBinary(byte[] binary) Check that the binary representation is valid. The service has already checked that it is non-null and a valid length.- Specified by:
isValidBinaryin interfaceUUIDVersionDelegate- Parameters:
binary- The binary representation.- Returns:
trueif the binary representation is valid. Otherwise,false.
-
isValidText
Check that the text representation is valid. The service has already checked that it is non-null and a valid length.- Specified by:
isValidTextin interfaceUUIDVersionDelegate- Parameters:
text- The binary representation.- Returns:
trueif the text representation is valid. Otherwise,false.
-
toInstant
Extract the timestamp from the UUID.- Specified by:
toInstantin interfaceUUIDVersionDelegate- Parameters:
binary- The binary representation of the UUID.- Returns:
- The timestamp as an Instant.
-
fromTicks
public byte[] fromTicks(long ticks, long suffix) Create a UUID as a byte array from a timestamp.- Specified by:
fromTicksin interfaceUUIDVersionDelegate- Parameters:
ticks- The timestamp in 100 nanoseconds.suffix- The second portion of the UUID.- Returns:
- The UUID as a byte array.
-