]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.api.uuid/src/org/argeo/api/uuid/NameUuid.java
Improve build and local deployment
[lgpl/argeo-commons.git] / org.argeo.api.uuid / src / org / argeo / api / uuid / NameUuid.java
1 package org.argeo.api.uuid;
2
3 import java.nio.charset.Charset;
4 import java.nio.charset.StandardCharsets;
5 import java.util.UUID;
6
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;
10
11 protected final TypedUuid namespace;
12 protected final String name;
13 protected final Charset encoding;
14
15 /**
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.
19 */
20 public NameUuid(TypedUuid namespace, String name) {
21 this(namespace, name, StandardCharsets.UTF_8, true);
22 }
23
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,
28 encoding);
29 }
30
31 /**
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.
35 */
36 protected NameUuid(UUID uuid, TypedUuid namespace, String name, Charset encoding) {
37 super(uuid);
38 assert namespace != null;
39 assert name != null;
40 assert encoding != null;
41 this.namespace = namespace;
42 this.name = name;
43 this.encoding = encoding;
44 }
45
46 /** The namespace used to build this UUID. */
47 public final TypedUuid getNamespace() {
48 return namespace;
49 }
50
51 /** The name of this UUID. */
52 public final String getName() {
53 return name;
54 }
55
56 /** The encoding used to create this UUID. */
57 public final Charset getEncoding() {
58 return encoding;
59 }
60
61 /** Always returns <code>false</code> since construction values are known. */
62 @Override
63 public final boolean isOpaque() {
64 return false;
65 }
66
67 }