1 package org
.argeo
.api
.uuid
;
3 import java
.nio
.charset
.Charset
;
4 import java
.nio
.charset
.StandardCharsets
;
7 /** A name UUID whose values used for its construction are known. */
8 public class NameUuid
extends BasicNameUuid
{
9 private static final long serialVersionUID
= APM
.SERIAL
;
11 protected final TypedUuid namespace
;
12 protected final String name
;
13 protected final Charset encoding
;
16 * Default static builder which creates a v5 (SHA1) name based {@link UUID},
17 * using UTF-8 encoding. Use
18 * {@link #NameUuid(TypedUuid, String, Charset, boolean)} for more options.
20 public NameUuid(TypedUuid namespace
, String name
) {
21 this(namespace
, name
, StandardCharsets
.UTF_8
, true);
24 /** Static builder (an {@link TypedUuidFactory} may be more efficient). */
25 public NameUuid(TypedUuid namespace
, String name
, Charset encoding
, boolean sha1
) {
26 this(sha1 ? AbstractUuidFactory
.createNameUUIDv5Static(namespace
.uuid
, name
.getBytes(encoding
))
27 : AbstractUuidFactory
.createNameUUIDv5Static(namespace
.uuid
, name
.getBytes(encoding
)), namespace
, name
,
32 * Since no check is performed, the constructor is protected so that the object
33 * can only be built by the default methods of {@link TypedUuidFactory} (in this
34 * package) or by extending the class.
36 protected NameUuid(UUID uuid
, TypedUuid namespace
, String name
, Charset encoding
) {
38 assert namespace
!= null;
40 assert encoding
!= null;
41 this.namespace
= namespace
;
43 this.encoding
= encoding
;
46 /** The namespace used to build this UUID. */
47 public final TypedUuid
getNamespace() {
51 /** The name of this UUID. */
52 public final String
getName() {
56 /** The encoding used to create this UUID. */
57 public final Charset
getEncoding() {
61 /** Always returns <code>false</code> since construction values are known. */
63 public final boolean isOpaque() {