Class UUIDVersion7Delegate

java.lang.Object
com.buralotech.oss.identifier.uuid.UUIDVersion7Delegate
All Implemented Interfaces:
UUIDVersionDelegate

public class UUIDVersion7Delegate extends Object implements UUIDVersionDelegate
Encapsulates the logic that is specific to the standard type 7 UUID format.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final com.fasterxml.uuid.NoArgGenerator
    Used to generate time based UUIDs.
    private static final Pattern
    The regular expression pattern used to validate identifiers.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    fromTicks(long ticks, long suffix)
    Create a UUID as a byte array from a timestamp.
    byte[]
    Generate an identifier using an underlying UUID generator.
    boolean
    isValidBinary(byte[] binary)
    Check that the binary representation is valid.
    boolean
    Check that the text representation is valid.
    toInstant(byte[] binary)
    Extract the timestamp from the UUID.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PATTERN

      private static final Pattern PATTERN
      The regular expression pattern used to validate identifiers.
    • generator

      private final com.fasterxml.uuid.NoArgGenerator generator
      Used 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:
      generate in interface UUIDVersionDelegate
      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:
      isValidBinary in interface UUIDVersionDelegate
      Parameters:
      binary - The binary representation.
      Returns:
      true if the binary representation is valid. Otherwise, false.
    • isValidText

      public boolean isValidText(String text)
      Check that the text representation is valid. The service has already checked that it is non-null and a valid length.
      Specified by:
      isValidText in interface UUIDVersionDelegate
      Parameters:
      text - The binary representation.
      Returns:
      true if the text representation is valid. Otherwise, false.
    • toInstant

      public Instant toInstant(byte[] binary)
      Extract the timestamp from the UUID.
      Specified by:
      toInstant in interface UUIDVersionDelegate
      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:
      fromTicks in interface UUIDVersionDelegate
      Parameters:
      ticks - The timestamp in 100 nanoseconds.
      suffix - The second portion of the UUID.
      Returns:
      The UUID as a byte array.