@@ -17,26 +17,50 @@ public class UUIDs {
17
17
private static final RandomBasedUUIDGenerator RANDOM_UUID_GENERATOR = new RandomBasedUUIDGenerator ();
18
18
private static final UUIDGenerator TIME_UUID_GENERATOR = new TimeBasedUUIDGenerator ();
19
19
20
- /** Generates a time-based UUID (similar to Flake IDs), which is preferred when generating an ID to be indexed into a Lucene index as
21
- * primary key. The id is opaque and the implementation is free to change at any time! */
20
+ /**
21
+ * The length of a UUID string generated by {@link #base64UUID}.
22
+ */
23
+ // A 15-byte time-based UUID is base64-encoded as 5 3-byte chunks (each becoming 4 chars after encoding).
24
+ public static final int TIME_BASED_UUID_STRING_LENGTH = 20 ;
25
+
26
+ /**
27
+ * Generates a time-based UUID (similar to Flake IDs), which is preferred when generating an ID to be indexed into a Lucene index as
28
+ * primary key. The id is opaque and the implementation is free to change at any time!
29
+ * The resulting string has length {@link #TIME_BASED_UUID_STRING_LENGTH}.
30
+ */
22
31
public static String base64UUID () {
23
32
return TIME_UUID_GENERATOR .getBase64UUID ();
24
33
}
25
34
26
- /** Returns a Base64 encoded version of a Version 4.0 compatible UUID as defined here: http://www.ietf.org/rfc/rfc4122.txt, using the
27
- * provided {@code Random} instance */
35
+ /**
36
+ * The length of a UUID string generated by {@link #randomBase64UUID} and {@link #randomBase64UUIDSecureString}.
37
+ */
38
+ // A 16-byte v4 UUID is base64-encoded as 5 3-byte chunks (each becoming 4 chars after encoding) plus another byte (becomes 2 chars).
39
+ public static final int RANDOM_BASED_UUID_STRING_LENGTH = 22 ;
40
+
41
+ /**
42
+ * Returns a Base64 encoded string representing a <a href="http://www.ietf.org/rfc/rfc4122.txt">RFC4122 version 4 UUID</a>, using the
43
+ * provided {@code Random} instance.
44
+ * The resulting string has length {@link #RANDOM_BASED_UUID_STRING_LENGTH}.
45
+ */
28
46
public static String randomBase64UUID (Random random ) {
29
47
return RandomBasedUUIDGenerator .getBase64UUID (random );
30
48
}
31
49
32
- /** Returns a Base64 encoded version of a Version 4.0 compatible UUID as defined here: http://www.ietf.org/rfc/rfc4122.txt, using a
33
- * private {@code SecureRandom} instance */
50
+ /**
51
+ * Returns a Base64 encoded string representing a <a href="http://www.ietf.org/rfc/rfc4122.txt">RFC4122 version 4 UUID</a>, using a
52
+ * private {@code SecureRandom} instance.
53
+ * The resulting string has length {@link #RANDOM_BASED_UUID_STRING_LENGTH}.
54
+ */
34
55
public static String randomBase64UUID () {
35
56
return RANDOM_UUID_GENERATOR .getBase64UUID ();
36
57
}
37
58
38
- /** Returns a Base64 encoded {@link SecureString} of a Version 4.0 compatible UUID as defined here: http://www.ietf.org/rfc/rfc4122.txt,
39
- * using a private {@code SecureRandom} instance */
59
+ /**
60
+ * Returns a Base64 encoded {@link SecureString} representing a <a href="http://www.ietf.org/rfc/rfc4122.txt">RFC4122 version 4
61
+ * UUID</a>, using a private {@code SecureRandom} instance.
62
+ * The resulting string has length {@link #RANDOM_BASED_UUID_STRING_LENGTH}.
63
+ */
40
64
public static SecureString randomBase64UUIDSecureString () {
41
65
return RandomBasedUUIDGenerator .getBase64UUIDSecureString ();
42
66
}
0 commit comments