1 package com.buralotech.oss.identifier.uuid;
2
3 import java.time.Instant;
4
5 /**
6 * Implementations encapsulate logic that is specific to the UUID format.
7 */
8 public interface UUIDVersionDelegate {
9
10 /**
11 * Generate an identifier using an underlying UUID generator.
12 *
13 * @return The generated identifier as a byte array.
14 */
15 byte[] generate();
16
17 /**
18 * Check that the binary representation is valid. The service has already checked that it is non-null and a valid length.
19 *
20 * @param binary The binary representation.
21 * @return {@code true} if the binary representation is valid. Otherwise, {@code false}.
22 */
23 boolean isValidBinary(byte[] binary);
24
25 /**
26 * Check that the text representation is valid. The service has already checked that it is non-null and a valid length.
27 *
28 * @param text The binary representation.
29 * @return {@code true} if the text representation is valid. Otherwise, {@code false}.
30 */
31 boolean isValidText(String text);
32
33 /**
34 * Extract the timestamp from the UUID.
35 *
36 * @param binary The binary representation of the UUID.
37 * @return The timestamp as an Instant.
38 */
39 Instant toInstant(byte[] binary);
40
41 /**
42 * Create a UUID as a byte array from a timestamp.
43 *
44 * @param ticks The timestamp in 100 nanoseconds.
45 * @param suffix The second portion of the UUID.
46 * @return The UUID as a byte array.
47 */
48 byte[] fromTicks(long ticks, long suffix);
49 }